From 70b6cc5994d3b5a269e0b95ac4cb434dd874d45e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 6 Sep 2011 22:26:14 -0500 Subject: [PATCH] refactoring. --- application/composers.php | 2 +- laravel/arr.php | 10 ++----- laravel/asset.php | 46 ++++++++++++++++++++++------- laravel/config.php | 12 +------- laravel/config/container.php | 6 ++++ laravel/database/connection.php | 2 +- laravel/database/query/postgres.php | 5 ---- laravel/facades.php | 1 + laravel/lang.php | 5 +--- laravel/routing/route.php | 10 +++---- laravel/view.php | 2 +- 11 files changed, 56 insertions(+), 45 deletions(-) diff --git a/application/composers.php b/application/composers.php index 5e70068f..218536e0 100644 --- a/application/composers.php +++ b/application/composers.php @@ -39,7 +39,7 @@ | */ - 'global' => function($view, $laravel) + 'shared' => function($view, $laravel) { // }, diff --git a/laravel/arr.php b/laravel/arr.php index a31798af..ce92611c 100644 --- a/laravel/arr.php +++ b/laravel/arr.php @@ -7,7 +7,7 @@ class Arr { * * If the specified key is null, the entire array will be returned. The array may * also be accessed using JavaScript "dot" style notation. Retrieving items nested - * in multiple arrays is also supported. + * in multiple arrays is supported. * * @param array $array * @param string $key @@ -35,12 +35,8 @@ public static function get($array, $key, $default = null) * Set an array item to a given value. * * This method is primarly helpful for setting the value in an array with - * a variable depth, such as configuration arrays. - * - * If the specified item doesn't exist, it will be created. If the item's - * parents do no exist, they will also be created as arrays. - * - * Like the Arr::get method, JavaScript "dot" syntax is supported. + * a variable depth, such as configuration arrays. Like the Arr::get + * method, JavaScript "dot" syntax is supported. * * @param array $array * @param string $key diff --git a/laravel/asset.php b/laravel/asset.php index 7400a9b7..4abbb4b1 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -9,7 +9,25 @@ class Asset { * * @var array */ - public static $containers = array(); + public $containers = array(); + + /** + * The HTML writer instance. + * + * @var HTML + */ + protected $html; + + /** + * Create a new asset manager instance. + * + * @param HTML $html + * @return void + */ + public function __construct(HTML $html) + { + $this->html = $html; + } /** * Get an asset container instance. @@ -21,14 +39,14 @@ class Asset { * @param string $container * @return Asset_Container */ - public static function container($container = 'default') + public function container($container = 'default') { - if ( ! isset(static::$containers[$container])) + if ( ! isset($this->containers[$container])) { - static::$containers[$container] = new Asset_Container($container); + $this->containers[$container] = new Asset_Container($container, $this->html); } - return static::$containers[$container]; + return $this->containers[$container]; } /** @@ -37,9 +55,9 @@ public static function container($container = 'default') * This provides a convenient API, allowing the develop to skip the "container" * method when using the default container. */ - public static function __callStatic($method, $parameters) + public function __call($method, $parameters) { - return call_user_func_array(array(static::container(), $method), $parameters); + return call_user_func_array(array($this->container(), $method), $parameters); } } @@ -62,16 +80,24 @@ class Asset_Container { */ public $assets = array(); + /** + * The HTML writer instance. + * + * @var HTML + */ + protected $html; + /** * Create a new asset container instance. * * @param string $name - * @param File $file + * @param HTML $html * @return void */ - public function __construct($name) + public function __construct($name, HTML $html) { $this->name = $name; + $this->html = $html; } /** @@ -225,7 +251,7 @@ private function get_asset($group, $name) $asset = $this->assets[$group][$name]; - return HTML::$group($asset['source'], $asset['attributes']); + return $this->html->$group($asset['source'], $asset['attributes']); } /** diff --git a/laravel/config.php b/laravel/config.php index 2b151e70..d63c9901 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -43,10 +43,6 @@ public function has($key) /** * Get a configuration item. * - * Configuration items are retrieved using "dot" notation. So, asking for the - * "application.timezone" configuration item would return the "timezone" option - * from the "application" configuration file. - * * If the name of a configuration file is passed without specifying an item, the * entire configuration array will be returned. * @@ -71,9 +67,6 @@ public function get($key, $default = null) /** * Set a configuration item. * - * Like the get method, "dot" notation is used to set items, and setting items - * at any depth in the configuration array is supported. - * * If a specific configuration item is not specified, the entire configuration * array will be replaced with the given value. * @@ -124,10 +117,7 @@ protected function load($file) $config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config; } - if (count($config) > 0) - { - $this->items[$file] = $config; - } + if (count($config) > 0) $this->items[$file] = $config; return isset($this->items[$file]); } diff --git a/laravel/config/container.php b/laravel/config/container.php index 840a5680..a5f70d47 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -8,6 +8,12 @@ |-------------------------------------------------------------------------- */ + 'laravel.asset' => array('singleton' => true, 'resolver' => function($container) + { + return new Asset($container->resolve('laravel.html')); + }), + + 'laravel.auth' => array('resolver' => function($container) { return new Security\Authenticator($container->resolve('laravel.session'), $container->resolve('laravel.hasher')); diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 0ef33f67..b64fa020 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -87,7 +87,7 @@ public function scalar($sql, $bindings = array()) { $result = (array) $this->first($sql, $bindings); - return (strpos(strtolower($sql), 'select count') === 0) ? (int) reset($result) : (float) reset($result); + return (strpos(strtolower(trim($sql)), 'select count') === 0) ? (int) reset($result) : (float) reset($result); } /** diff --git a/laravel/database/query/postgres.php b/laravel/database/query/postgres.php index 565dfdee..83c9487f 100644 --- a/laravel/database/query/postgres.php +++ b/laravel/database/query/postgres.php @@ -7,11 +7,6 @@ class Postgres extends Query { /** * Insert an array of values into the database table and return the value of the ID column. * - * - * // Insert into the "users" table and get the auto-incrementing ID - * $id = DB::table('users')->insert_get_id(array('email' => 'example@gmail.com')); - * - * * @param array $values * @return int */ diff --git a/laravel/facades.php b/laravel/facades.php index 96155f53..55a92a59 100644 --- a/laravel/facades.php +++ b/laravel/facades.php @@ -20,6 +20,7 @@ public static function __callStatic($method, $parameters) } +class Asset extends Facade { public static $resolve = 'asset'; } class Auth extends Facade { public static $resolve = 'auth'; } class Cache extends Facade { public static $resolve = 'cache'; } class Config extends Facade { public static $resolve = 'config'; } diff --git a/laravel/lang.php b/laravel/lang.php index a85d70f1..78a408a2 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -183,10 +183,7 @@ private function load($file) } } - if (count($language) > 0) - { - static::$lines[$this->language.$file] = $language; - } + if (count($language) > 0) static::$lines[$this->language.$file] = $language; return isset(static::$lines[$this->language.$file]); } diff --git a/laravel/routing/route.php b/laravel/routing/route.php index 7332f8ac..e17935c8 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -46,7 +46,7 @@ public function __construct($key, $callback, $parameters = array()) $this->key = $key; $this->callback = $callback; $this->parameters = $parameters; - $this->uris = $this->parse($key); + $this->uris = $this->parse_uris($key); } /** @@ -120,13 +120,13 @@ public function handles($uri) * @param string $key * @return array */ - protected function parse($key) + protected function parse_uris($key) { - if (strpos($key, ', ') === false) return array($this->extract($key)); + if (strpos($key, ', ') === false) return array($this->extract_uri($key)); foreach (explode(', ', $key) as $segment) { - $uris[] = $this->extract($segment); + $uris[] = $this->extract_uri($segment); } return $uris; @@ -142,7 +142,7 @@ protected function parse($key) * @param string $segment * @return string */ - protected function extract($segment) + protected function extract_uri($segment) { $segment = substr($segment, strpos($segment, ' ') + 1); diff --git a/laravel/view.php b/laravel/view.php index 01caf1b7..c121f611 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -144,7 +144,7 @@ public function name($name) */ public function compose(View $view) { - if (isset($this->composers['global'])) call_user_func($this->composers['global'], $view, $this->container); + if (isset($this->composers['shared'])) call_user_func($this->composers['shared'], $view, $this->container); if (isset($this->composers[$view->view])) {