Commit 70b6cc59 by Taylor Otwell

refactoring.

parent 7eef380d
...@@ -39,7 +39,7 @@ return array( ...@@ -39,7 +39,7 @@ return array(
| |
*/ */
'global' => function($view, $laravel) 'shared' => function($view, $laravel)
{ {
// //
}, },
......
...@@ -7,7 +7,7 @@ class Arr { ...@@ -7,7 +7,7 @@ class Arr {
* *
* If the specified key is null, the entire array will be returned. The array may * 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 * 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 array $array
* @param string $key * @param string $key
...@@ -35,12 +35,8 @@ class Arr { ...@@ -35,12 +35,8 @@ class Arr {
* Set an array item to a given value. * Set an array item to a given value.
* *
* This method is primarly helpful for setting the value in an array with * This method is primarly helpful for setting the value in an array with
* a variable depth, such as configuration arrays. * a variable depth, such as configuration arrays. Like the Arr::get
* * method, JavaScript "dot" syntax is supported.
* 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.
* *
* @param array $array * @param array $array
* @param string $key * @param string $key
......
...@@ -9,7 +9,25 @@ class Asset { ...@@ -9,7 +9,25 @@ class Asset {
* *
* @var array * @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. * Get an asset container instance.
...@@ -21,14 +39,14 @@ class Asset { ...@@ -21,14 +39,14 @@ class Asset {
* @param string $container * @param string $container
* @return Asset_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 @@ class Asset { ...@@ -37,9 +55,9 @@ class Asset {
* This provides a convenient API, allowing the develop to skip the "container" * This provides a convenient API, allowing the develop to skip the "container"
* method when using the default 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);
} }
} }
...@@ -63,15 +81,23 @@ class Asset_Container { ...@@ -63,15 +81,23 @@ class Asset_Container {
public $assets = array(); public $assets = array();
/** /**
* The HTML writer instance.
*
* @var HTML
*/
protected $html;
/**
* Create a new asset container instance. * Create a new asset container instance.
* *
* @param string $name * @param string $name
* @param File $file * @param HTML $html
* @return void * @return void
*/ */
public function __construct($name) public function __construct($name, HTML $html)
{ {
$this->name = $name; $this->name = $name;
$this->html = $html;
} }
/** /**
...@@ -225,7 +251,7 @@ class Asset_Container { ...@@ -225,7 +251,7 @@ class Asset_Container {
$asset = $this->assets[$group][$name]; $asset = $this->assets[$group][$name];
return HTML::$group($asset['source'], $asset['attributes']); return $this->html->$group($asset['source'], $asset['attributes']);
} }
/** /**
......
...@@ -43,10 +43,6 @@ class Config { ...@@ -43,10 +43,6 @@ class Config {
/** /**
* Get a configuration item. * 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 * If the name of a configuration file is passed without specifying an item, the
* entire configuration array will be returned. * entire configuration array will be returned.
* *
...@@ -71,9 +67,6 @@ class Config { ...@@ -71,9 +67,6 @@ class Config {
/** /**
* Set a configuration item. * 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 * If a specific configuration item is not specified, the entire configuration
* array will be replaced with the given value. * array will be replaced with the given value.
* *
...@@ -124,10 +117,7 @@ class Config { ...@@ -124,10 +117,7 @@ class Config {
$config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config; $config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config;
} }
if (count($config) > 0) if (count($config) > 0) $this->items[$file] = $config;
{
$this->items[$file] = $config;
}
return isset($this->items[$file]); return isset($this->items[$file]);
} }
......
...@@ -8,6 +8,12 @@ return array( ...@@ -8,6 +8,12 @@ return array(
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
'laravel.asset' => array('singleton' => true, 'resolver' => function($container)
{
return new Asset($container->resolve('laravel.html'));
}),
'laravel.auth' => array('resolver' => function($container) 'laravel.auth' => array('resolver' => function($container)
{ {
return new Security\Authenticator($container->resolve('laravel.session'), $container->resolve('laravel.hasher')); return new Security\Authenticator($container->resolve('laravel.session'), $container->resolve('laravel.hasher'));
......
...@@ -87,7 +87,7 @@ class Connection { ...@@ -87,7 +87,7 @@ class Connection {
{ {
$result = (array) $this->first($sql, $bindings); $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);
} }
/** /**
......
...@@ -7,11 +7,6 @@ class Postgres extends Query { ...@@ -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 an array of values into the database table and return the value of the ID column.
* *
* <code>
* // Insert into the "users" table and get the auto-incrementing ID
* $id = DB::table('users')->insert_get_id(array('email' => 'example@gmail.com'));
* </code>
*
* @param array $values * @param array $values
* @return int * @return int
*/ */
......
...@@ -20,6 +20,7 @@ abstract class Facade { ...@@ -20,6 +20,7 @@ abstract class Facade {
} }
class Asset extends Facade { public static $resolve = 'asset'; }
class Auth extends Facade { public static $resolve = 'auth'; } class Auth extends Facade { public static $resolve = 'auth'; }
class Cache extends Facade { public static $resolve = 'cache'; } class Cache extends Facade { public static $resolve = 'cache'; }
class Config extends Facade { public static $resolve = 'config'; } class Config extends Facade { public static $resolve = 'config'; }
......
...@@ -183,10 +183,7 @@ class Lang { ...@@ -183,10 +183,7 @@ class Lang {
} }
} }
if (count($language) > 0) if (count($language) > 0) static::$lines[$this->language.$file] = $language;
{
static::$lines[$this->language.$file] = $language;
}
return isset(static::$lines[$this->language.$file]); return isset(static::$lines[$this->language.$file]);
} }
......
...@@ -46,7 +46,7 @@ class Route { ...@@ -46,7 +46,7 @@ class Route {
$this->key = $key; $this->key = $key;
$this->callback = $callback; $this->callback = $callback;
$this->parameters = $parameters; $this->parameters = $parameters;
$this->uris = $this->parse($key); $this->uris = $this->parse_uris($key);
} }
/** /**
...@@ -120,13 +120,13 @@ class Route { ...@@ -120,13 +120,13 @@ class Route {
* @param string $key * @param string $key
* @return array * @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) foreach (explode(', ', $key) as $segment)
{ {
$uris[] = $this->extract($segment); $uris[] = $this->extract_uri($segment);
} }
return $uris; return $uris;
...@@ -142,7 +142,7 @@ class Route { ...@@ -142,7 +142,7 @@ class Route {
* @param string $segment * @param string $segment
* @return string * @return string
*/ */
protected function extract($segment) protected function extract_uri($segment)
{ {
$segment = substr($segment, strpos($segment, ' ') + 1); $segment = substr($segment, strpos($segment, ' ') + 1);
......
...@@ -144,7 +144,7 @@ class View_Composer { ...@@ -144,7 +144,7 @@ class View_Composer {
*/ */
public function compose(View $view) 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])) if (isset($this->composers[$view->view]))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment