refactoring.
This commit is contained in:
parent
7eef380d8a
commit
70b6cc5994
|
@ -39,7 +39,7 @@
|
|||
|
|
||||
*/
|
||||
|
||||
'global' => function($view, $laravel)
|
||||
'shared' => function($view, $laravel)
|
||||
{
|
||||
//
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
*
|
||||
* <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
|
||||
* @return int
|
||||
*/
|
||||
|
|
|
@ -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'; }
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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]))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue