refactoring container for speed.
This commit is contained in:
parent
4263203dda
commit
71b0ab8b8d
|
@ -20,13 +20,13 @@
|
||||||
|
|
||||||
'Arr' => 'Laravel\\Arr',
|
'Arr' => 'Laravel\\Arr',
|
||||||
'Asset' => 'Laravel\\Asset',
|
'Asset' => 'Laravel\\Asset',
|
||||||
'Auth' => 'Laravel\\Facades\\Auth',
|
'Auth' => 'Laravel\\Auth',
|
||||||
'Benchmark' => 'Laravel\\Benchmark',
|
'Benchmark' => 'Laravel\\Benchmark',
|
||||||
'Cache' => 'Laravel\\Cache',
|
'Cache' => 'Laravel\\Cache',
|
||||||
'Config' => 'Laravel\\Config',
|
'Config' => 'Laravel\\Config',
|
||||||
'Controller' => 'Laravel\\Controller',
|
'Controller' => 'Laravel\\Controller',
|
||||||
'Cookie' => 'Laravel\\Facades\\Cookie',
|
'Cookie' => 'Laravel\\Cookie',
|
||||||
'Crypter' => 'Laravel\\Facades\\Crypter',
|
'Crypter' => 'Laravel\\Crypter',
|
||||||
'DB' => 'Laravel\\Database\\Manager',
|
'DB' => 'Laravel\\Database\\Manager',
|
||||||
'Eloquent' => 'Laravel\\Database\\Eloquent\\Model',
|
'Eloquent' => 'Laravel\\Database\\Eloquent\\Model',
|
||||||
'File' => 'Laravel\\File',
|
'File' => 'Laravel\\File',
|
||||||
|
@ -34,20 +34,20 @@
|
||||||
'Hasher' => 'Laravel\\Facades\\Hasher',
|
'Hasher' => 'Laravel\\Facades\\Hasher',
|
||||||
'HTML' => 'Laravel\\HTML',
|
'HTML' => 'Laravel\\HTML',
|
||||||
'Inflector' => 'Laravel\\Inflector',
|
'Inflector' => 'Laravel\\Inflector',
|
||||||
'Input' => 'Laravel\\Facades\\Input',
|
'Input' => 'Laravel\\Input',
|
||||||
'IoC' => 'Laravel\\IoC',
|
'IoC' => 'Laravel\\IoC',
|
||||||
'Lang' => 'Laravel\\Lang',
|
'Lang' => 'Laravel\\Lang',
|
||||||
'Loader' => 'Laravel\\Loader',
|
'Loader' => 'Laravel\\Loader',
|
||||||
'Messages' => 'Laravel\\Validation\\Messages',
|
'Messages' => 'Laravel\\Validation\\Messages',
|
||||||
'Package' => 'Laravel\\Facades\\Package',
|
'Package' => 'Laravel\\Facades\\Package',
|
||||||
'URI' => 'Laravel\\Facades\\URI',
|
'URI' => 'Laravel\\URI',
|
||||||
'URL' => 'Laravel\\URL',
|
'URL' => 'Laravel\\URL',
|
||||||
'Redirect' => 'Laravel\\Redirect',
|
'Redirect' => 'Laravel\\Redirect',
|
||||||
'Request' => 'Laravel\\Facades\\Request',
|
'Request' => 'Laravel\\Request',
|
||||||
'Response' => 'Laravel\\Response',
|
'Response' => 'Laravel\\Response',
|
||||||
'Session' => 'Laravel\\Facades\\Session',
|
'Session' => 'Laravel\\Facades\\Session',
|
||||||
'Str' => 'Laravel\\Str',
|
'Str' => 'Laravel\\Str',
|
||||||
'Validator' => 'Laravel\\Validation\\Validator',
|
'Validator' => 'Laravel\\Validation\\Validator',
|
||||||
'View' => 'Laravel\\Facades\\View',
|
'View' => 'Laravel\\View',
|
||||||
|
|
||||||
);
|
);
|
|
@ -63,6 +63,25 @@
|
||||||
|
|
||||||
'encoding' => 'UTF-8',
|
'encoding' => 'UTF-8',
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Auto-Loaded Packages
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The packages that should be auto-loaded each time Laravel handles a
|
||||||
|
| request. These should generally be packages that you use on almost every
|
||||||
|
| request to your application.
|
||||||
|
|
|
||||||
|
| Each package specified here will be bootstrapped and can be conveniently
|
||||||
|
| used by your application's routes, models, and libraries.
|
||||||
|
|
|
||||||
|
| Note: The package names in this array should correspond to a package
|
||||||
|
| directory in application/packages.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'packages' => array(),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Application Key
|
| Application Key
|
||||||
|
@ -93,23 +112,4 @@
|
||||||
|
|
||||||
'ssl' => true,
|
'ssl' => true,
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Auto-Loaded Packages
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
|
|
|
||||||
| The packages that should be auto-loaded each time Laravel handles a
|
|
||||||
| request. These should generally be packages that you use on almost every
|
|
||||||
| request to your application.
|
|
||||||
|
|
|
||||||
| Each package specified here will be bootstrapped and can be conveniently
|
|
||||||
| used by your application's routes, models, and libraries.
|
|
||||||
|
|
|
||||||
| Note: The package names in this array should correspond to a package
|
|
||||||
| directory in application/packages.
|
|
||||||
|
|
|
||||||
*/
|
|
||||||
|
|
||||||
'packages' => array(),
|
|
||||||
|
|
||||||
);
|
);
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'GET /' => function()
|
'GET /' => function($application)
|
||||||
{
|
{
|
||||||
return View::make('home.index');
|
return View::make('home.index');
|
||||||
},
|
},
|
||||||
|
|
|
@ -61,7 +61,9 @@
|
||||||
* for the lazy-loading of all of the Laravel core classes, as well as
|
* for the lazy-loading of all of the Laravel core classes, as well as
|
||||||
* the developer created libraries and models.
|
* the developer created libraries and models.
|
||||||
*/
|
*/
|
||||||
spl_autoload_register(array($container->resolve('laravel.loader'), 'load'));
|
spl_autoload_register(array('Laravel\\Loader', 'load'));
|
||||||
|
|
||||||
|
Loader::$aliases = Config::get('aliases');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define a few convenient global functions.
|
* Define a few convenient global functions.
|
||||||
|
|
|
@ -2,108 +2,34 @@
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
||||||
/*
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
| Core Laravel Components
|
|
||||||
|--------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
'laravel.auth' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new Security\Auth($c->resolve('laravel.session'));
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.cookie' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new Cookie($_COOKIE);
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.crypter' => array('resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', Config::get('application.key'));
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.hasher' => array('singleton' => true, 'resolver' => function($c)
|
'laravel.hasher' => array('singleton' => true, 'resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Security\Hashing\Bcrypt(8, false);
|
return new Security\Hashing\Bcrypt(8, false);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
'laravel.input' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
$input = array();
|
|
||||||
|
|
||||||
switch ($c->resolve('laravel.request')->method())
|
|
||||||
{
|
|
||||||
case 'GET':
|
|
||||||
$input = $_GET;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'POST':
|
|
||||||
$input = $_POST;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'PUT':
|
|
||||||
case 'DELETE':
|
|
||||||
if ($c->resolve('laravel.request')->spoofed())
|
|
||||||
{
|
|
||||||
$input = $_POST;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parse_str(file_get_contents('php://input'), $input);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($input[Request::spoofer]);
|
|
||||||
|
|
||||||
return new Input($input, $_FILES);
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.loader' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new Loader(array(BASE_PATH, MODEL_PATH, LIBRARY_PATH, BASE_PATH), Config::get('aliases'));
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.request' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new Request($c->resolve('laravel.uri'), $_SERVER, $_POST);
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.uri' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new URI($_SERVER);
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.view' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
require_once SYS_PATH.'view'.EXT;
|
|
||||||
|
|
||||||
return new View_Factory($c->resolve('laravel.composer'), VIEW_PATH, STORAGE_PATH.'views/');
|
|
||||||
}),
|
|
||||||
|
|
||||||
|
|
||||||
'laravel.composer' => array('singleton' => true, 'resolver' => function($c)
|
|
||||||
{
|
|
||||||
return new View_Composer(require APP_PATH.'composers'.EXT);
|
|
||||||
}),
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Laravel Routing Components
|
| Laravel Routing Components
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The following components are used by the Laravel routing system.
|
||||||
|
|
|
||||||
|
| The router is used to map a given method and URI to a route intance.
|
||||||
|
|
|
||||||
|
| The route loader is responsible for loading the appropriates routes file
|
||||||
|
| for a given request URI, as well as loading all routes when the framework
|
||||||
|
| needs to find a named route wtihin the application.
|
||||||
|
|
|
||||||
|
| The route caller is responsible for receiving a route and taking the
|
||||||
|
| appropriate action to execute that route. Some routes delegate execution
|
||||||
|
| to a controller, so this class will also resolve controllers out of the
|
||||||
|
| container and call the appropriate methods on those controllers.
|
||||||
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'laravel.routing.router' => array('singleton' => true, 'resolver' => function($c)
|
'laravel.routing.router' => array('singleton' => true, 'resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Routing\Router($c->resolve('laravel.routing.loader'), CONTROLLER_PATH);
|
return new Routing\Router($c->core('routing.loader'), CONTROLLER_PATH);
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,6 +48,13 @@
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Laravel Caching Components
|
| Laravel Caching Components
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The following components are used by the wonderfully, simple Laravel
|
||||||
|
| caching system. Each driver is resolved through the container.
|
||||||
|
|
|
||||||
|
| New cache drivers may be added to the framework by simply registering
|
||||||
|
| them into the container.
|
||||||
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'laravel.cache.apc' => array('resolver' => function($c)
|
'laravel.cache.apc' => array('resolver' => function($c)
|
||||||
|
@ -138,7 +71,7 @@
|
||||||
|
|
||||||
'laravel.cache.memcached' => array('resolver' => function($c)
|
'laravel.cache.memcached' => array('resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Cache\Drivers\Memcached($c->resolve('laravel.cache.memcache.connection'), Config::get('cache.key'));
|
return new Cache\Drivers\Memcached($c->core('cache.memcache.connection'), Config::get('cache.key'));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,37 +96,53 @@
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Laravel Session Components
|
| Laravel Session Components
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The following components are used by the Laravel session system.
|
||||||
|
|
|
||||||
|
| The framework allows the session ID to be transported via a variety
|
||||||
|
| of different mechanisms by resolve the ID itself and the session
|
||||||
|
| transporter instance out of the container. This allows sessions
|
||||||
|
| to be used by clients who cannot receive cookies.
|
||||||
|
|
|
||||||
|
| The session manager is responsible for loading the session payload
|
||||||
|
| from the session driver, as well as examining the payload validitiy
|
||||||
|
| and things like the CSRF token.
|
||||||
|
|
|
||||||
|
| Like the caching components, each session driver is resolved via the
|
||||||
|
| container and new drivers may be added by registering them into the
|
||||||
|
| container. Several session drivers are "driven" by the cache drivers.
|
||||||
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'laravel.session.id' => array('singleton' => true, 'resolver' => function($c)
|
'laravel.session.id' => array('singleton' => true, 'resolver' => function($c)
|
||||||
{
|
{
|
||||||
return $c->resolve('laravel.cookie')->get('laravel_session');
|
return Cookie::get('laravel_session');
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
'laravel.session.manager' => array('singleton' => true, 'resolver' => function($c)
|
'laravel.session.manager' => array('singleton' => true, 'resolver' => function($c)
|
||||||
{
|
{
|
||||||
$driver = $c->resolve('laravel.session.'.Config::get('session.driver'));
|
$driver = $c->core('session.'.Config::get('session.driver'));
|
||||||
|
|
||||||
return new Session\Manager($driver, $c->resolve('laravel.session.transporter'));
|
return new Session\Manager($driver, $c->core('session.transporter'));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
'laravel.session.transporter' => array('resolver' => function($c)
|
'laravel.session.transporter' => array('resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Session\Transporters\Cookie($c->resolve('laravel.cookie'));
|
return new Session\Transporters\Cookie;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
'laravel.session.apc' => array('resolver' => function($c)
|
'laravel.session.apc' => array('resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Session\Drivers\APC($c->resolve('laravel.cache.apc'));
|
return new Session\Drivers\APC($c->core('cache.apc'));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
'laravel.session.cookie' => array('resolver' => function($c)
|
'laravel.session.cookie' => array('resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Session\Drivers\Cookie($c->resolve('laravel.crypter'), $c->resolve('laravel.cookie'));
|
return new Session\Drivers\Cookie;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
|
@ -211,7 +160,7 @@
|
||||||
|
|
||||||
'laravel.session.memcached' => array('resolver' => function($c)
|
'laravel.session.memcached' => array('resolver' => function($c)
|
||||||
{
|
{
|
||||||
return new Session\Drivers\Memcached($c->resolve('laravel.cache.memcached'));
|
return new Session\Drivers\Memcached($c->core('cache.memcached'));
|
||||||
}),
|
}),
|
||||||
|
|
||||||
);
|
);
|
|
@ -134,19 +134,23 @@ public function instance($name, $instance)
|
||||||
* Resolve a core Laravel class from the container.
|
* Resolve a core Laravel class from the container.
|
||||||
*
|
*
|
||||||
* <code>
|
* <code>
|
||||||
* // Resolve the "laravel.input" class from the container
|
* // Resolve the "laravel.router" class from the container
|
||||||
* $input = IoC::container()->core('input');
|
* $input = IoC::container()->core('input');
|
||||||
*
|
*
|
||||||
* // Equivalent resolution using the "resolve" method
|
* // Equivalent resolution using the "resolve" method
|
||||||
* $input = IoC::container()->resolve('laravel.input');
|
* $input = IoC::container()->resolve('laravel.router');
|
||||||
|
*
|
||||||
|
* // Pass an array of parameters to the resolver
|
||||||
|
* $input = IoC::container()->core('input', array('test'));
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param array $parameters
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function core($name)
|
public function core($name, $parameters = array())
|
||||||
{
|
{
|
||||||
return $this->resolve("laravel.{$name}");
|
return $this->resolve("laravel.{$name}", $parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,12 +159,16 @@ public function core($name)
|
||||||
* <code>
|
* <code>
|
||||||
* // Get an instance of the "mailer" object registered in the container
|
* // Get an instance of the "mailer" object registered in the container
|
||||||
* $mailer = IoC::container()->resolve('mailer');
|
* $mailer = IoC::container()->resolve('mailer');
|
||||||
|
*
|
||||||
|
* // Pass an array of parameters to the resolver
|
||||||
|
* $mailer = IoC::container()->resolve('mailer', array('test'));
|
||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
|
* @param array $parameters
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function resolve($name)
|
public function resolve($name, $parameters = array())
|
||||||
{
|
{
|
||||||
if (array_key_exists($name, $this->singletons)) return $this->singletons[$name];
|
if (array_key_exists($name, $this->singletons)) return $this->singletons[$name];
|
||||||
|
|
||||||
|
@ -169,7 +177,7 @@ public function resolve($name)
|
||||||
throw new \Exception("Error resolving [$name]. No resolver has been registered in the container.");
|
throw new \Exception("Error resolving [$name]. No resolver has been registered in the container.");
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = call_user_func($this->registry[$name]['resolver'], $this);
|
$object = call_user_func($this->registry[$name]['resolver'], $this, $parameters);
|
||||||
|
|
||||||
return (isset($this->registry[$name]['singleton'])) ? $this->singletons[$name] = $object : $object;
|
return (isset($this->registry[$name]['singleton'])) ? $this->singletons[$name] = $object : $object;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,33 +2,15 @@
|
||||||
|
|
||||||
class Cookie {
|
class Cookie {
|
||||||
|
|
||||||
/**
|
|
||||||
* The cookies for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $cookies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new cookie manager instance.
|
|
||||||
*
|
|
||||||
* @param array $cookies
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(&$cookies)
|
|
||||||
{
|
|
||||||
$this->cookies =& $cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a cookie exists.
|
* Determine if a cookie exists.
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function has($name)
|
public static function has($name)
|
||||||
{
|
{
|
||||||
return ! is_null($this->get($name));
|
return ! is_null(static::get($name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,9 +20,9 @@ public function has($name)
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get($name, $default = null)
|
public static function get($name, $default = null)
|
||||||
{
|
{
|
||||||
return Arr::get($this->cookies, $name, $default);
|
return Arr::get($_COOKIE, $name, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,9 +36,9 @@ public function get($name, $default = null)
|
||||||
* @param bool $http_only
|
* @param bool $http_only
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function forever($name, $value, $path = '/', $domain = null, $secure = false, $http_only = false)
|
public static function forever($name, $value, $path = '/', $domain = null, $secure = false, $http_only = false)
|
||||||
{
|
{
|
||||||
return $this->put($name, $value, 2628000, $path, $domain, $secure, $http_only);
|
return static::put($name, $value, 2628000, $path, $domain, $secure, $http_only);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,11 +59,11 @@ public function forever($name, $value, $path = '/', $domain = null, $secure = fa
|
||||||
* @param bool $http_only
|
* @param bool $http_only
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false, $http_only = false)
|
public static function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false, $http_only = false)
|
||||||
{
|
{
|
||||||
if (headers_sent()) return false;
|
if (headers_sent()) return false;
|
||||||
|
|
||||||
if ($minutes < 0) unset($this->cookies[$name]);
|
if ($minutes < 0) unset($_COOKIE[$name]);
|
||||||
|
|
||||||
// Since PHP needs the cookie lifetime in seconds, we will calculate it here.
|
// Since PHP needs the cookie lifetime in seconds, we will calculate it here.
|
||||||
// A "0" lifetime means the cookie expires when the browser closes.
|
// A "0" lifetime means the cookie expires when the browser closes.
|
||||||
|
@ -96,9 +78,9 @@ public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $s
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function forget($name)
|
public static function forget($name)
|
||||||
{
|
{
|
||||||
return $this->put($name, null, -60);
|
return static::put($name, null, -60);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,7 @@
|
||||||
use Laravel\IoC;
|
use Laravel\IoC;
|
||||||
use Laravel\Str;
|
use Laravel\Str;
|
||||||
use Laravel\Inflector;
|
use Laravel\Inflector;
|
||||||
|
use Laravel\Paginator;
|
||||||
use Laravel\Database\Manager as DB;
|
use Laravel\Database\Manager as DB;
|
||||||
|
|
||||||
abstract class Model {
|
abstract class Model {
|
||||||
|
@ -223,6 +224,28 @@ private function _first()
|
||||||
return (count($results = $this->take(1)->_get()) > 0) ? reset($results) : null;
|
return (count($results = $this->take(1)->_get()) > 0) ? reset($results) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get paginated model results as a Paginator instance.
|
||||||
|
*
|
||||||
|
* @param int $per_page
|
||||||
|
* @return Paginator
|
||||||
|
*/
|
||||||
|
private function _paginate($per_page = null)
|
||||||
|
{
|
||||||
|
$total = $this->query->count();
|
||||||
|
|
||||||
|
// The number of models to show per page may be specified as a static property
|
||||||
|
// on the model. The models shown per page may also be overriden for the model
|
||||||
|
// by passing the number into this method. If the models to show per page is
|
||||||
|
// not available via either of these avenues, a default number will be shown.
|
||||||
|
if (is_null($per_page))
|
||||||
|
{
|
||||||
|
$per_page = (property_exists(get_class($this), 'per_page')) ? static::$per_page : 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Paginator::make($this->for_page(Paginator::page($total, $per_page), $per_page)->get(), $total, $per_page);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the query for a 1:1 relationship.
|
* Retrieve the query for a 1:1 relationship.
|
||||||
*
|
*
|
||||||
|
@ -484,7 +507,7 @@ public function __call($method, $parameters)
|
||||||
// To allow the "with", "get", "first", and "paginate" methods to be called both
|
// To allow the "with", "get", "first", and "paginate" methods to be called both
|
||||||
// staticly and on an instance, we need to have private, underscored versions
|
// staticly and on an instance, we need to have private, underscored versions
|
||||||
// of the methods and handle them dynamically.
|
// of the methods and handle them dynamically.
|
||||||
if (in_array($method, array('with', 'get', 'first')))
|
if (in_array($method, array('with', 'get', 'first', 'paginate')))
|
||||||
{
|
{
|
||||||
return call_user_func_array(array($this, '_'.$method), $parameters);
|
return call_user_func_array(array($this, '_'.$method), $parameters);
|
||||||
}
|
}
|
||||||
|
|
|
@ -525,7 +525,7 @@ private function aggregate($aggregator, $column)
|
||||||
* @param array $columns
|
* @param array $columns
|
||||||
* @return Paginator
|
* @return Paginator
|
||||||
*/
|
*/
|
||||||
public function paginate($per_page, $columns = array('*'))
|
public function paginate($per_page = 20, $columns = array('*'))
|
||||||
{
|
{
|
||||||
// Calculate the current page for the request. The page number will be validated
|
// Calculate the current page for the request. The page number will be validated
|
||||||
// and adjusted by the Paginator class, so we can assume it is valid.
|
// and adjusted by the Paginator class, so we can assume it is valid.
|
||||||
|
|
|
@ -32,12 +32,6 @@ public static function __callStatic($method, $parameters)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Auth extends Facade { public static $resolve = 'laravel.auth'; }
|
|
||||||
class Cookie extends Facade { public static $resolve = 'laravel.cookie'; }
|
|
||||||
class Crypter extends Facade { public static $resolve = 'laravel.crypter'; }
|
class Crypter extends Facade { public static $resolve = 'laravel.crypter'; }
|
||||||
class Hasher extends Facade { public static $resolve = 'laravel.hasher'; }
|
class Hasher extends Facade { public static $resolve = 'laravel.hasher'; }
|
||||||
class Input extends Facade { public static $resolve = 'laravel.input'; }
|
|
||||||
class Request extends Facade { public static $resolve = 'laravel.request'; }
|
|
||||||
class Session extends Facade { public static $resolve = 'laravel.session'; }
|
class Session extends Facade { public static $resolve = 'laravel.session'; }
|
||||||
class URI extends Facade { public static $resolve = 'laravel.uri'; }
|
|
||||||
class View extends Facade { public static $resolve = 'laravel.view'; }
|
|
|
@ -7,14 +7,7 @@ class Input {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $input;
|
protected static $input;
|
||||||
|
|
||||||
/**
|
|
||||||
* The $_FILES array for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $files;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key used to store old input in the session.
|
* The key used to store old input in the session.
|
||||||
|
@ -24,16 +17,14 @@ class Input {
|
||||||
const old_input = 'laravel_old_input';
|
const old_input = 'laravel_old_input';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new input manager instance.
|
* Set the input for the current request.
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @param array $files
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct($input, $files)
|
public static function set($input)
|
||||||
{
|
{
|
||||||
$this->input = $input;
|
static::$input = $input;
|
||||||
$this->files = $files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,9 +34,9 @@ public function __construct($input, $files)
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function all()
|
public static function all()
|
||||||
{
|
{
|
||||||
return array_merge($this->get(), $this->file());
|
return array_merge(static::get(), static::file());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,9 +47,9 @@ public function all()
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function has($key)
|
public static function has($key)
|
||||||
{
|
{
|
||||||
return ( ! is_null($this->get($key)) and trim((string) $this->get($key)) !== '');
|
return ( ! is_null(static::get($key)) and trim((string) static::get($key)) !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,9 +69,9 @@ public function has($key)
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get($key = null, $default = null)
|
public static function get($key = null, $default = null)
|
||||||
{
|
{
|
||||||
return Arr::get($this->input, $key, $default);
|
return Arr::get(static::$input, $key, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,9 +80,9 @@ public function get($key = null, $default = null)
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function had($key)
|
public static function had($key)
|
||||||
{
|
{
|
||||||
return ( ! is_null($this->old($key)) and trim((string) $this->old($key)) !== '');
|
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +100,7 @@ public function had($key)
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function old($key = null, $default = null)
|
public static function old($key = null, $default = null)
|
||||||
{
|
{
|
||||||
if (Config::get('session.driver') == '')
|
if (Config::get('session.driver') == '')
|
||||||
{
|
{
|
||||||
|
@ -136,9 +127,9 @@ public function old($key = null, $default = null)
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function file($key = null, $default = null)
|
public static function file($key = null, $default = null)
|
||||||
{
|
{
|
||||||
return Arr::get($this->files, $key, $default);
|
return Arr::get($_FILES, $key, $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,9 +146,9 @@ public function file($key = null, $default = null)
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function upload($key, $path)
|
public static function upload($key, $path)
|
||||||
{
|
{
|
||||||
return array_key_exists($key, $this->files) ? File::upload($key, $path, $this->files) : false;
|
return array_key_exists($key, $_FILES) ? File::upload($key, $path, $_FILES) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,23 +32,58 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve the incoming request instance from the IoC container
|
* Manually load some core classes that are used on every request
|
||||||
* and route the request to the proper route in the application.
|
* This allows to avoid using the loader for these classes.
|
||||||
* If a route is found, the route will be called with the current
|
|
||||||
* requst instance. If no route is found, the 404 response will
|
|
||||||
* be returned to the browser.
|
|
||||||
*/
|
*/
|
||||||
|
require SYS_PATH.'uri'.EXT;
|
||||||
require SYS_PATH.'request'.EXT;
|
require SYS_PATH.'request'.EXT;
|
||||||
require SYS_PATH.'routing/route'.EXT;
|
require SYS_PATH.'routing/route'.EXT;
|
||||||
require SYS_PATH.'routing/router'.EXT;
|
require SYS_PATH.'routing/router'.EXT;
|
||||||
require SYS_PATH.'routing/loader'.EXT;
|
require SYS_PATH.'routing/loader'.EXT;
|
||||||
require SYS_PATH.'routing/caller'.EXT;
|
require SYS_PATH.'routing/caller'.EXT;
|
||||||
|
|
||||||
$request = $container->core('request');
|
/**
|
||||||
|
* Gather the input to the application for the current request.
|
||||||
|
* The input will be gathered based on the current request method
|
||||||
|
* and will be set on the Input manager.
|
||||||
|
*/
|
||||||
|
$input = array();
|
||||||
|
|
||||||
list($method, $uri) = array($request->method(), $request->uri());
|
switch (Request::method())
|
||||||
|
{
|
||||||
|
case 'GET':
|
||||||
|
$input = $_GET;
|
||||||
|
break;
|
||||||
|
|
||||||
$route = $container->core('routing.router')->route($request, $method, $uri);
|
case 'POST':
|
||||||
|
$input = $_POST;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'PUT':
|
||||||
|
case 'DELETE':
|
||||||
|
if (Request::spoofed())
|
||||||
|
{
|
||||||
|
$input = $_POST;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parse_str(file_get_contents('php://input'), $input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($input[Request::spoofer]);
|
||||||
|
|
||||||
|
Input::set($input);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Route the request to the proper route in the application. If a
|
||||||
|
* route is found, the route will be called with the current request
|
||||||
|
* instance. If no route is found, the 404 response will be returned
|
||||||
|
* to the browser.
|
||||||
|
*/
|
||||||
|
list($method, $uri) = array(Request::method(), URI::get());
|
||||||
|
|
||||||
|
$route = $container->core('routing.router')->route($method, $uri);
|
||||||
|
|
||||||
if ( ! is_null($route))
|
if ( ! is_null($route))
|
||||||
{
|
{
|
||||||
|
@ -75,7 +110,7 @@
|
||||||
*/
|
*/
|
||||||
if (isset($session))
|
if (isset($session))
|
||||||
{
|
{
|
||||||
$flash = array(Input::old_input => $container->core('input')->get());
|
$flash = array(Input::old_input => Input::get());
|
||||||
|
|
||||||
$session->close($container->core('session'), Config::get('session'), $flash);
|
$session->close($container->core('session'), Config::get('session'), $flash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,27 +7,14 @@ class Loader {
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $paths = array();
|
public static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH, APP_PATH);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class aliases defined for the application.
|
* The class aliases defined for the application.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $aliases = array();
|
public static $aliases = array();
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new class loader instance.
|
|
||||||
*
|
|
||||||
* @param array $paths
|
|
||||||
* @param array $aliases
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($paths, $aliases = array())
|
|
||||||
{
|
|
||||||
$this->paths = $paths;
|
|
||||||
$this->aliases = $aliases;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the file for a given class.
|
* Load the file for a given class.
|
||||||
|
@ -43,7 +30,7 @@ public function __construct($paths, $aliases = array())
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function load($class)
|
public static function load($class)
|
||||||
{
|
{
|
||||||
// All Laravel core classes follow a namespace to directory convention.
|
// All Laravel core classes follow a namespace to directory convention.
|
||||||
// We will replace all of the namespace slashes with directory slashes.
|
// We will replace all of the namespace slashes with directory slashes.
|
||||||
|
@ -51,12 +38,12 @@ public function load($class)
|
||||||
|
|
||||||
// Check to determine if an alias exists. If it does, we will define the
|
// Check to determine if an alias exists. If it does, we will define the
|
||||||
// alias and bail out. Aliases are defined for most used core classes.
|
// alias and bail out. Aliases are defined for most used core classes.
|
||||||
if (array_key_exists($class, $this->aliases))
|
if (array_key_exists($class, static::$aliases))
|
||||||
{
|
{
|
||||||
return class_alias($this->aliases[$class], $class);
|
return class_alias(static::$aliases[$class], $class);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->paths as $path)
|
foreach (static::$paths as $path)
|
||||||
{
|
{
|
||||||
if (file_exists($path = $path.$file.EXT))
|
if (file_exists($path = $path.$file.EXT))
|
||||||
{
|
{
|
||||||
|
@ -74,9 +61,9 @@ public function load($class)
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function alias($alias, $class)
|
public static function alias($alias, $class)
|
||||||
{
|
{
|
||||||
$this->aliases[$alias] = $class;
|
static::$aliases[$alias] = $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,9 +72,9 @@ public function alias($alias, $class)
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function path($path)
|
public static function path($path)
|
||||||
{
|
{
|
||||||
$this->paths[] = rtrim($path, '/').'/';
|
static::$paths[] = rtrim($path, '/').'/';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,9 +83,9 @@ public function path($path)
|
||||||
* @param string $alias
|
* @param string $alias
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forget_alias($alias)
|
public static function forget_alias($alias)
|
||||||
{
|
{
|
||||||
unset($this->aliases[$alias]);
|
unset(static::$aliases[$alias]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -54,14 +54,7 @@ class Paginator {
|
||||||
protected $appendage;
|
protected $appendage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current request instance.
|
* The pagination elements that will be generated.
|
||||||
*
|
|
||||||
* @var Request
|
|
||||||
*/
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The paginatino elements that will be generated.
|
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -84,10 +77,6 @@ protected function __construct($results, $page, $total, $per_page, $last)
|
||||||
$this->total = $total;
|
$this->total = $total;
|
||||||
$this->results = $results;
|
$this->results = $results;
|
||||||
$this->per_page = $per_page;
|
$this->per_page = $per_page;
|
||||||
|
|
||||||
// Grab the active request instance. This is used to determine the current URI
|
|
||||||
// and to determine if HTTPS links should be generated.
|
|
||||||
$this->request = IoC::container()->core('request');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +101,7 @@ public static function make($results, $total, $per_page)
|
||||||
*/
|
*/
|
||||||
public static function page($total, $per_page)
|
public static function page($total, $per_page)
|
||||||
{
|
{
|
||||||
$page = IoC::container()->core('input')->get('page', 1);
|
$page = Input::get('page', 1);
|
||||||
|
|
||||||
// The page will be validated and adjusted if it is less than one or greater
|
// The page will be validated and adjusted if it is less than one or greater
|
||||||
// than the last page. For example, if the current page is not an integer or
|
// than the last page. For example, if the current page is not an integer or
|
||||||
|
@ -253,7 +242,7 @@ protected function element($element, $text, $page, $disabler)
|
||||||
// We will assume the page links should use HTTPS if the current request
|
// We will assume the page links should use HTTPS if the current request
|
||||||
// is also using HTTPS. Since pagination links automatically point to
|
// is also using HTTPS. Since pagination links automatically point to
|
||||||
// the current URI, this makes pretty good sense.
|
// the current URI, this makes pretty good sense.
|
||||||
list($uri, $secure) = array($this->request->uri(), $this->request->secure());
|
list($uri, $secure) = array(URI::get(), Request::secure());
|
||||||
|
|
||||||
return HTML::link($uri.$this->appendage($element, $page), $text, array('class' => $class), $secure);
|
return HTML::link($uri.$this->appendage($element, $page), $text, array('class' => $class), $secure);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
<?php namespace Laravel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Proxy class, like the File class, is primarily intended to get rid of
|
|
||||||
* the testability problems introduced by PHP's global functions.
|
|
||||||
*
|
|
||||||
* For instance, the APC cache driver calls the APC global functions. Instead of
|
|
||||||
* calling those functions directory in the driver, we inject a Proxy instance into
|
|
||||||
* the class, which allows us to stub the global functions.
|
|
||||||
*/
|
|
||||||
class Proxy {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic Method for calling any global function.
|
|
||||||
*/
|
|
||||||
public function __call($method, $parameters)
|
|
||||||
{
|
|
||||||
return call_user_func_array($method, $parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -7,21 +7,7 @@ class Request {
|
||||||
*
|
*
|
||||||
* @var Routing\Route
|
* @var Routing\Route
|
||||||
*/
|
*/
|
||||||
public $route;
|
public static $route;
|
||||||
|
|
||||||
/**
|
|
||||||
* The $_SERVER array for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The $_POST array for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $post;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The request data key that is used to indicate a spoofed request method.
|
* The request data key that is used to indicate a spoofed request method.
|
||||||
|
@ -30,21 +16,6 @@ class Request {
|
||||||
*/
|
*/
|
||||||
const spoofer = '__spoofer';
|
const spoofer = '__spoofer';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new request instance.
|
|
||||||
*
|
|
||||||
* @param URI $uri
|
|
||||||
* @param array $server
|
|
||||||
* @param array $post
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(URI $uri, $server, $post)
|
|
||||||
{
|
|
||||||
$this->uri = $uri;
|
|
||||||
$this->post = $post;
|
|
||||||
$this->server = $server;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the URI for the current request.
|
* Get the URI for the current request.
|
||||||
*
|
*
|
||||||
|
@ -52,9 +23,9 @@ public function __construct(URI $uri, $server, $post)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function uri()
|
public static function uri()
|
||||||
{
|
{
|
||||||
return $this->uri->get();
|
return URI::get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,9 +35,9 @@ public function uri()
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function format()
|
public static function format()
|
||||||
{
|
{
|
||||||
return (($extension = pathinfo($this->uri->get(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
|
return (($extension = pathinfo(URI::get(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,9 +49,9 @@ public function format()
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function method()
|
public static function method()
|
||||||
{
|
{
|
||||||
return ($this->spoofed()) ? $this->post[Request::spoofer] : $this->server['REQUEST_METHOD'];
|
return (static::spoofed()) ? $_POST[Request::spoofer] : $_SERVER['REQUEST_METHOD'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,9 +63,9 @@ public function method()
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function server($key = null, $default = null)
|
public static function server($key = null, $default = null)
|
||||||
{
|
{
|
||||||
return Arr::get($this->server, strtoupper($key), $default);
|
return Arr::get($_SERVER, strtoupper($key), $default);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,9 +77,9 @@ public function server($key = null, $default = null)
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function spoofed()
|
public static function spoofed()
|
||||||
{
|
{
|
||||||
return is_array($this->post) and array_key_exists(Request::spoofer, $this->post);
|
return is_array($_POST) and array_key_exists(Request::spoofer, $_POST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,19 +88,19 @@ public function spoofed()
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ip($default = '0.0.0.0')
|
public static function ip($default = '0.0.0.0')
|
||||||
{
|
{
|
||||||
if (isset($this->server['HTTP_X_FORWARDED_FOR']))
|
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
|
||||||
{
|
{
|
||||||
return $this->server['HTTP_X_FORWARDED_FOR'];
|
return $_SERVER['HTTP_X_FORWARDED_FOR'];
|
||||||
}
|
}
|
||||||
elseif (isset($this->server['HTTP_CLIENT_IP']))
|
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
|
||||||
{
|
{
|
||||||
return $this->server['HTTP_CLIENT_IP'];
|
return $_SERVER['HTTP_CLIENT_IP'];
|
||||||
}
|
}
|
||||||
elseif (isset($this->server['REMOTE_ADDR']))
|
elseif (isset($_SERVER['REMOTE_ADDR']))
|
||||||
{
|
{
|
||||||
return $this->server['REMOTE_ADDR'];
|
return $_SERVER['REMOTE_ADDR'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($default instanceof Closure) ? call_user_func($default) : $default;
|
return ($default instanceof Closure) ? call_user_func($default) : $default;
|
||||||
|
@ -143,9 +114,9 @@ public function ip($default = '0.0.0.0')
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function protocol()
|
public static function protocol()
|
||||||
{
|
{
|
||||||
return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http';
|
return (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,9 +124,9 @@ public function protocol()
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function secure()
|
public static function secure()
|
||||||
{
|
{
|
||||||
return $this->protocol() == 'https';
|
return static::protocol() == 'https';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,11 +134,11 @@ public function secure()
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function ajax()
|
public static function ajax()
|
||||||
{
|
{
|
||||||
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
|
if ( ! isset($_SERVER['HTTP_X_REQUESTED_WITH'])) return false;
|
||||||
|
|
||||||
return strtolower($this->server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
|
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -175,6 +146,6 @@ public function ajax()
|
||||||
*
|
*
|
||||||
* @return Route
|
* @return Route
|
||||||
*/
|
*/
|
||||||
public function route() { return $this->route; }
|
public static function route() { return static::$route; }
|
||||||
|
|
||||||
}
|
}
|
|
@ -133,7 +133,7 @@ public static function make($content, $status = 200, $headers = array())
|
||||||
*/
|
*/
|
||||||
public static function view($view, $data = array())
|
public static function view($view, $data = array())
|
||||||
{
|
{
|
||||||
return new static(IoC::container()->core('view')->make($view, $data));
|
return new static(View::make($view, $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,7 +153,7 @@ public static function view($view, $data = array())
|
||||||
*/
|
*/
|
||||||
public static function of($name, $data = array())
|
public static function of($name, $data = array())
|
||||||
{
|
{
|
||||||
return new static(IoC::container()->core('view')->of($name, $data));
|
return new static(View::of($name, $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,7 +177,7 @@ public static function of($name, $data = array())
|
||||||
*/
|
*/
|
||||||
public static function error($code, $data = array())
|
public static function error($code, $data = array())
|
||||||
{
|
{
|
||||||
return new static(IoC::container()->core('view')->make('error/'.$code, $data), $code);
|
return new static(View::make('error/'.$code, $data), $code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -87,12 +87,11 @@ public function find($name)
|
||||||
/**
|
/**
|
||||||
* Search the routes for the route matching a request method and URI.
|
* Search the routes for the route matching a request method and URI.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @return Route
|
* @return Route
|
||||||
*/
|
*/
|
||||||
public function route(Request $request, $method, $uri)
|
public function route($method, $uri)
|
||||||
{
|
{
|
||||||
$routes = $this->loader->load($uri);
|
$routes = $this->loader->load($uri);
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ public function route(Request $request, $method, $uri)
|
||||||
// no need to spin through all of the routes.
|
// no need to spin through all of the routes.
|
||||||
if (isset($routes[$destination]))
|
if (isset($routes[$destination]))
|
||||||
{
|
{
|
||||||
return $request->route = new Route($destination, $routes[$destination], array());
|
return Request::$route = new Route($destination, $routes[$destination], array());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($routes as $keys => $callback)
|
foreach ($routes as $keys => $callback)
|
||||||
|
@ -120,13 +119,13 @@ public function route(Request $request, $method, $uri)
|
||||||
|
|
||||||
if (preg_match('#^'.$this->translate_wildcards($key).'$#', $destination))
|
if (preg_match('#^'.$this->translate_wildcards($key).'$#', $destination))
|
||||||
{
|
{
|
||||||
return $request->route = new Route($keys, $callback, $this->parameters($destination, $key));
|
return Request::$route = new Route($keys, $callback, $this->parameters($destination, $key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $request->route = $this->route_to_controller($method, $uri, $destination);
|
return Request::$route = $this->route_to_controller($method, $uri, $destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php namespace Laravel\Security;
|
<?php namespace Laravel\Security;
|
||||||
|
|
||||||
|
use Laravel\IoC;
|
||||||
use Laravel\Config;
|
use Laravel\Config;
|
||||||
use Laravel\Session\Payload;
|
use Laravel\Session\Payload;
|
||||||
|
|
||||||
|
@ -10,14 +11,7 @@ class Auth {
|
||||||
*
|
*
|
||||||
* @var object
|
* @var object
|
||||||
*/
|
*/
|
||||||
protected $user;
|
protected static $user;
|
||||||
|
|
||||||
/**
|
|
||||||
* The session payload instance.
|
|
||||||
*
|
|
||||||
* @var Session\Payload
|
|
||||||
*/
|
|
||||||
protected $session;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The key used when storing the user ID in the session.
|
* The key used when storing the user ID in the session.
|
||||||
|
@ -26,25 +20,14 @@ class Auth {
|
||||||
*/
|
*/
|
||||||
const user_key = 'laravel_user_id';
|
const user_key = 'laravel_user_id';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new authenticator instance.
|
|
||||||
*
|
|
||||||
* @param Session\Payload $session
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Payload $session)
|
|
||||||
{
|
|
||||||
$this->session = $session;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if the current user of the application is authenticated.
|
* Determine if the current user of the application is authenticated.
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function check()
|
public static function check()
|
||||||
{
|
{
|
||||||
return ! is_null($this->user());
|
return ! is_null(static::user());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,11 +46,13 @@ public function check()
|
||||||
*
|
*
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function user()
|
public static function user()
|
||||||
{
|
{
|
||||||
if ( ! is_null($this->user)) return $this->user;
|
if ( ! is_null(static::$user)) return static::$user;
|
||||||
|
|
||||||
return $this->user = call_user_func(Config::get('auth.user'), $this->session->get(Auth::user_key));
|
$id = IoC::container()->core('session')->get(Auth::user_key);
|
||||||
|
|
||||||
|
return static::$user = call_user_func(Config::get('auth.user'), $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,11 +65,11 @@ public function user()
|
||||||
* @param string $password
|
* @param string $password
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function attempt($username, $password = null)
|
public static function attempt($username, $password = null)
|
||||||
{
|
{
|
||||||
if ( ! is_null($user = call_user_func(Config::get('auth.attempt'), $username, $password)))
|
if ( ! is_null($user = call_user_func(Config::get('auth.attempt'), $username, $password)))
|
||||||
{
|
{
|
||||||
$this->remember($user);
|
static::remember($user);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -100,11 +85,11 @@ public function attempt($username, $password = null)
|
||||||
* @param object $user
|
* @param object $user
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function remember($user)
|
public static function remember($user)
|
||||||
{
|
{
|
||||||
$this->user = $user;
|
static::$user = $user;
|
||||||
|
|
||||||
$this->session->put(Auth::user_key, $user->id);
|
IoC::container()->core('session')->put(Auth::user_key, $user->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -114,13 +99,13 @@ public function remember($user)
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function logout()
|
public static function logout()
|
||||||
{
|
{
|
||||||
call_user_func(Config::get('auth.logout'), $this->user());
|
call_user_func(Config::get('auth.logout'), static::user());
|
||||||
|
|
||||||
$this->user = null;
|
static::$user = null;
|
||||||
|
|
||||||
$this->session->forget(Auth::user_key);
|
IoC::container()->core('session')->forget(Auth::user_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,12 @@
|
||||||
<?php namespace Laravel\Security;
|
<?php namespace Laravel\Security;
|
||||||
|
|
||||||
|
use Laravel\Config;
|
||||||
|
|
||||||
|
if (trim(Config::get('application.key')) === '')
|
||||||
|
{
|
||||||
|
throw new \Exception('The encryption class may not be used without an encryption key.');
|
||||||
|
}
|
||||||
|
|
||||||
class Crypter {
|
class Crypter {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,44 +14,14 @@ class Crypter {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $cipher;
|
protected static $cipher = MCRYPT_RIJNDAEL_256;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The encryption mode.
|
* The encryption mode.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public $mode;
|
protected static $mode = 'cbc';
|
||||||
|
|
||||||
/**
|
|
||||||
* The encryption key.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new Crypter instance.
|
|
||||||
*
|
|
||||||
* A valid cipher and mode supported by the Mcrypt extension must be given to the constructor.
|
|
||||||
* Also, an encryption key (typically from the application configuration) must be specified.
|
|
||||||
*
|
|
||||||
* @param string $cipher
|
|
||||||
* @param string $mode
|
|
||||||
* @param string $key
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($cipher, $mode, $key)
|
|
||||||
{
|
|
||||||
$this->key = $key;
|
|
||||||
$this->mode = $mode;
|
|
||||||
$this->cipher = $cipher;
|
|
||||||
|
|
||||||
if (trim((string) $this->key) === '')
|
|
||||||
{
|
|
||||||
throw new \Exception('The encryption class may not be used without an encryption key.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encrypt a string using Mcrypt.
|
* Encrypt a string using Mcrypt.
|
||||||
|
@ -60,10 +37,10 @@ public function __construct($cipher, $mode, $key)
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function encrypt($value)
|
public static function encrypt($value)
|
||||||
{
|
{
|
||||||
// Determine the most appropriate random number generator for the operating
|
// Determine the most appropriate random number generator for the
|
||||||
// system and environment the application is running on.
|
// OS and system and environment the application is running on.
|
||||||
if (defined('MCRYPT_DEV_URANDOM'))
|
if (defined('MCRYPT_DEV_URANDOM'))
|
||||||
{
|
{
|
||||||
$randomizer = MCRYPT_DEV_URANDOM;
|
$randomizer = MCRYPT_DEV_URANDOM;
|
||||||
|
@ -77,16 +54,14 @@ public function encrypt($value)
|
||||||
$randomizer = MCRYPT_RAND;
|
$randomizer = MCRYPT_RAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iv = mcrypt_create_iv($this->iv_size(), $randomizer);
|
$iv = mcrypt_create_iv(static::iv_size(), $randomizer);
|
||||||
|
|
||||||
return base64_encode($iv.mcrypt_encrypt($this->cipher, $this->key, $value, $this->mode, $iv));
|
return base64_encode($iv.mcrypt_encrypt(static::$cipher, Config::get('application.key'), $value, static::$mode, $iv));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrypt a string using Mcrypt.
|
* Decrypt a string using Mcrypt.
|
||||||
*
|
*
|
||||||
* The string will be decrypted using the cipher and mode specified when the crypter was created.
|
|
||||||
*
|
|
||||||
* <code>
|
* <code>
|
||||||
* // Decrypt a string using the Mcrypt PHP extension
|
* // Decrypt a string using the Mcrypt PHP extension
|
||||||
* $decrypted = Crypter::decrypt($secret);
|
* $decrypted = Crypter::decrypt($secret);
|
||||||
|
@ -95,7 +70,7 @@ public function encrypt($value)
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function decrypt($value)
|
public static function decrypt($value)
|
||||||
{
|
{
|
||||||
// Since all encrypted strings generated by this class are base64 encoded, we will
|
// Since all encrypted strings generated by this class are base64 encoded, we will
|
||||||
// first attempt to base64 decode the string. If we can't do it, we'll bail out.
|
// first attempt to base64 decode the string. If we can't do it, we'll bail out.
|
||||||
|
@ -104,10 +79,13 @@ public function decrypt($value)
|
||||||
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the input vector and the encrypted string from the value
|
// Extract the input vector and the encrypted string from the value.
|
||||||
list($iv, $value) = array(substr($value, 0, $this->iv_size()), substr($value, $this->iv_size()));
|
// These will be used by Mcrypt to properly decrypt the value.
|
||||||
|
$iv = substr($value, 0, static::iv_size());
|
||||||
|
|
||||||
return rtrim(mcrypt_decrypt($this->cipher, $this->key, $value, $this->mode, $iv), "\0");
|
$value = substr($value, static::iv_size());
|
||||||
|
|
||||||
|
return rtrim(mcrypt_decrypt(static::$cipher, Config::get('application.key'), $value, static::$mode, $iv), "\0");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,9 +95,9 @@ public function decrypt($value)
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
private function iv_size()
|
protected static function iv_size()
|
||||||
{
|
{
|
||||||
return mcrypt_get_iv_size($this->cipher, $this->mode);
|
return mcrypt_get_iv_size(static::$cipher, static::$mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,37 +4,6 @@
|
||||||
|
|
||||||
class Cookie implements Driver {
|
class Cookie implements Driver {
|
||||||
|
|
||||||
/**
|
|
||||||
* The crypter instance.
|
|
||||||
*
|
|
||||||
* All session cookies have an encrypted payload. Since the session contains sensitive
|
|
||||||
* data that cannot be compromised, it is important that the payload be encrypted using
|
|
||||||
* the strong encryption provided by the Crypter class.
|
|
||||||
*
|
|
||||||
* @var Crypter
|
|
||||||
*/
|
|
||||||
private $crypter;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The cookie manager instance.
|
|
||||||
*
|
|
||||||
* @var Cookie
|
|
||||||
*/
|
|
||||||
private $cookies;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new Cookie session driver instance.
|
|
||||||
*
|
|
||||||
* @param Crypter $crypter
|
|
||||||
* @param Cookie $cookies
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(Crypter $crypter, \Laravel\Cookie $cookies)
|
|
||||||
{
|
|
||||||
$this->crypter = $crypter;
|
|
||||||
$this->cookies = $cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load a session from storage by a given ID.
|
* Load a session from storage by a given ID.
|
||||||
*
|
*
|
||||||
|
@ -45,9 +14,9 @@ public function __construct(Crypter $crypter, \Laravel\Cookie $cookies)
|
||||||
*/
|
*/
|
||||||
public function load($id)
|
public function load($id)
|
||||||
{
|
{
|
||||||
if ($this->cookies->has('session_payload'))
|
if (\Laravel\Cookie::has('session_payload'))
|
||||||
{
|
{
|
||||||
return unserialize($this->crypter->decrypt($this->cookies->get('session_payload')));
|
return unserialize(Crypter::decrypt(\Laravel\Cookie::get('session_payload')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +32,9 @@ public function save($session, $config, $exists)
|
||||||
{
|
{
|
||||||
extract($config);
|
extract($config);
|
||||||
|
|
||||||
$payload = $this->crypter->encrypt(serialize($session));
|
$payload = Crypter::encrypt(serialize($session));
|
||||||
|
|
||||||
$this->cookies->put('session_payload', $payload, $lifetime, $path, $domain);
|
\Laravel\Cookie::put('session_payload', $payload, $lifetime, $path, $domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,7 +45,7 @@ public function save($session, $config, $exists)
|
||||||
*/
|
*/
|
||||||
public function delete($id)
|
public function delete($id)
|
||||||
{
|
{
|
||||||
$this->cookies->forget('session_payload');
|
\Laravel\Cookie::forget('session_payload');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,13 +2,6 @@
|
||||||
|
|
||||||
class Cookie implements Transporter {
|
class Cookie implements Transporter {
|
||||||
|
|
||||||
/**
|
|
||||||
* The cookie manager instance.
|
|
||||||
*
|
|
||||||
* @var Cookie
|
|
||||||
*/
|
|
||||||
protected $cookies;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the cookie used to store the session ID.
|
* The name of the cookie used to store the session ID.
|
||||||
*
|
*
|
||||||
|
@ -16,17 +9,6 @@ class Cookie implements Transporter {
|
||||||
*/
|
*/
|
||||||
const key = 'laravel_session';
|
const key = 'laravel_session';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new cookie session transporter instance.
|
|
||||||
*
|
|
||||||
* @param Cookie $cookie
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(\Laravel\Cookie $cookies)
|
|
||||||
{
|
|
||||||
$this->cookies = $cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the session identifier for the request.
|
* Get the session identifier for the request.
|
||||||
*
|
*
|
||||||
|
@ -35,7 +17,7 @@ public function __construct(\Laravel\Cookie $cookies)
|
||||||
*/
|
*/
|
||||||
public function get($config)
|
public function get($config)
|
||||||
{
|
{
|
||||||
return $this->cookies->get(Cookie::key);
|
return \Laravel\Cookie::get(Cookie::key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,7 +34,7 @@ public function put($id, $config)
|
||||||
// deleted until the user closes their browser.
|
// deleted until the user closes their browser.
|
||||||
$minutes = ( ! $config['expire_on_close']) ? $config['lifetime'] : 0;
|
$minutes = ( ! $config['expire_on_close']) ? $config['lifetime'] : 0;
|
||||||
|
|
||||||
$this->cookies->put(Cookie::key, $id, $minutes, $config['path'], $config['domain']);
|
\Laravel\Cookie::put(Cookie::key, $id, $minutes, $config['path'], $config['domain']);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,25 +9,7 @@ class URI {
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $uri;
|
protected static $uri;
|
||||||
|
|
||||||
/**
|
|
||||||
* The $_SERVER array for the current request.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new URI parser instance.
|
|
||||||
*
|
|
||||||
* @param array $server
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($server)
|
|
||||||
{
|
|
||||||
$this->server = $server;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine the request URI.
|
* Determine the request URI.
|
||||||
|
@ -41,16 +23,16 @@ public function __construct($server)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function get()
|
public static function get()
|
||||||
{
|
{
|
||||||
if ( ! is_null($this->uri)) return $this->uri;
|
if ( ! is_null(static::$uri)) return static::$uri;
|
||||||
|
|
||||||
if (($uri = $this->from_server()) === false)
|
if (($uri = static::from_server()) === false)
|
||||||
{
|
{
|
||||||
throw new \Exception('Malformed request URI. Request terminated.');
|
throw new \Exception('Malformed request URI. Request terminated.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->uri = $this->format($this->clean($uri));
|
return static::$uri = static::format(static::clean($uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,9 +50,9 @@ public function get()
|
||||||
* @param mixed $default
|
* @param mixed $default
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function segment($segment = null, $default = null)
|
public static function segment($segment = null, $default = null)
|
||||||
{
|
{
|
||||||
$segments = Arr::without(explode('/', $this->get()), array(''));
|
$segments = Arr::without(explode('/', static::get()), array(''));
|
||||||
|
|
||||||
if ( ! is_null($segment)) $segment = $segment - 1;
|
if ( ! is_null($segment)) $segment = $segment - 1;
|
||||||
|
|
||||||
|
@ -82,20 +64,20 @@ public function segment($segment = null, $default = null)
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function from_server()
|
protected static function from_server()
|
||||||
{
|
{
|
||||||
// If the PATH_INFO $_SERVER element is set, we will use since it contains
|
// If the PATH_INFO $_SERVER element is set, we will use since it contains
|
||||||
// the request URI formatted perfectly for Laravel's routing engine.
|
// the request URI formatted perfectly for Laravel's routing engine.
|
||||||
if (isset($this->server['PATH_INFO']))
|
if (isset($_SERVER['PATH_INFO']))
|
||||||
{
|
{
|
||||||
return $this->server['PATH_INFO'];
|
return $_SERVER['PATH_INFO'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the REQUEST_URI is set, we need to extract the URL path since this
|
// If the REQUEST_URI is set, we need to extract the URL path since this
|
||||||
// should return the URI formatted in a manner similar to PATH_INFO.
|
// should return the URI formatted in a manner similar to PATH_INFO.
|
||||||
elseif (isset($this->server['REQUEST_URI']))
|
elseif (isset($_SERVER['REQUEST_URI']))
|
||||||
{
|
{
|
||||||
return parse_url($this->server['REQUEST_URI'], PHP_URL_PATH);
|
return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \Exception('Unable to determine the request URI.');
|
throw new \Exception('Unable to determine the request URI.');
|
||||||
|
@ -110,7 +92,7 @@ protected function from_server()
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function clean($uri)
|
protected static function clean($uri)
|
||||||
{
|
{
|
||||||
foreach (array(parse_url(Config::get('application.url'), PHP_URL_PATH), '/index.php') as $value)
|
foreach (array(parse_url(Config::get('application.url'), PHP_URL_PATH), '/index.php') as $value)
|
||||||
{
|
{
|
||||||
|
@ -128,7 +110,7 @@ protected function clean($uri)
|
||||||
* @param string $uri
|
* @param string $uri
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function format($uri)
|
protected static function format($uri)
|
||||||
{
|
{
|
||||||
return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ public static function to_secure($url = '')
|
||||||
*/
|
*/
|
||||||
public static function to_asset($url, $https = null)
|
public static function to_asset($url, $https = null)
|
||||||
{
|
{
|
||||||
if (is_null($https)) $https = IoC::container()->core('request')->secure();
|
if (is_null($https)) $https = Request::secure();
|
||||||
|
|
||||||
return str_replace('index.php/', '', static::to($url, $https));
|
return str_replace('index.php/', '', static::to($url, $https));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
use Laravel\IoC;
|
use Laravel\IoC;
|
||||||
use Laravel\Str;
|
use Laravel\Str;
|
||||||
use Laravel\Lang;
|
use Laravel\Lang;
|
||||||
|
use Laravel\Input;
|
||||||
use Laravel\Database\Manager as DB;
|
use Laravel\Database\Manager as DB;
|
||||||
|
|
||||||
class Validator {
|
class Validator {
|
||||||
|
@ -304,9 +305,7 @@ protected function get_size($attribute)
|
||||||
|
|
||||||
$value = $this->attributes[$attribute];
|
$value = $this->attributes[$attribute];
|
||||||
|
|
||||||
$files = IoC::container()->resolve('laravel.input')->file();
|
return (array_key_exists($attribute, Input::file())) ? $value['size'] / 1024 : Str::length(trim($value));
|
||||||
|
|
||||||
return (array_key_exists($attribute, $files)) ? $value['size'] / 1024 : Str::length(trim($value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -478,7 +477,7 @@ protected function get_message($attribute, $rule)
|
||||||
// the default error message for the appropriate units.
|
// the default error message for the appropriate units.
|
||||||
if (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules))
|
if (in_array($rule, $this->size_rules) and ! $this->has_rule($attribute, $this->numeric_rules))
|
||||||
{
|
{
|
||||||
return (array_key_exists($attribute, IoC::container()->resolve('laravel.input')->file()))
|
return (array_key_exists($attribute, Input::file()))
|
||||||
? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'
|
? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'
|
||||||
: rtrim($message, '.').' '.Lang::line('validation.characters')->get($this->language).'.';
|
: rtrim($message, '.').' '.Lang::line('validation.characters')->get($this->language).'.';
|
||||||
}
|
}
|
||||||
|
|
355
laravel/view.php
355
laravel/view.php
|
@ -1,195 +1,5 @@
|
||||||
<?php namespace Laravel; use Closure;
|
<?php namespace Laravel; use Closure;
|
||||||
|
|
||||||
class View_Factory {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The directory containing the views.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The path to the directory containing compiled views.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
public $compiled;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The view composer instance.
|
|
||||||
*
|
|
||||||
* @var View_Composer
|
|
||||||
*/
|
|
||||||
protected $composer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new view factory instance.
|
|
||||||
*
|
|
||||||
* @param View_Composer $composer
|
|
||||||
* @param string $path
|
|
||||||
* @param string $compiled
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct(View_Composer $composer, $path, $compiled)
|
|
||||||
{
|
|
||||||
$this->path = $path;
|
|
||||||
$this->composer = $composer;
|
|
||||||
$this->compiled = $compiled;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new view instance.
|
|
||||||
*
|
|
||||||
* The name of the view given to this method should correspond to a view
|
|
||||||
* within your application views directory. Dots or slashes may used to
|
|
||||||
* reference views within sub-directories.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // Create a new view instance
|
|
||||||
* $view = View::make('home.index');
|
|
||||||
*
|
|
||||||
* // Create a new view instance with bound data
|
|
||||||
* $view = View::make('home.index', array('name' => 'Taylor'));
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param string $view
|
|
||||||
* @param array $data
|
|
||||||
* @return View
|
|
||||||
*/
|
|
||||||
public function make($view, $data = array())
|
|
||||||
{
|
|
||||||
return new View($this, $this->composer, $view, $data, $this->path($view));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new view instance from a view name.
|
|
||||||
*
|
|
||||||
* View names are defined in the application composers file.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // Create an instance of the "layout" named view
|
|
||||||
* $view = View::of('layout');
|
|
||||||
*
|
|
||||||
* // Create an instance of the "layout" view with bound data
|
|
||||||
* $view = View::of('layout', array('name' => 'Taylor'));
|
|
||||||
* </code>
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @param array $data
|
|
||||||
* @return View
|
|
||||||
*/
|
|
||||||
public function of($name, $data = array())
|
|
||||||
{
|
|
||||||
if ( ! is_null($view = $this->composer->name($name))) return $this->make($view, $data);
|
|
||||||
|
|
||||||
throw new \Exception("Named view [$name] is not defined.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the path to a given view on disk.
|
|
||||||
*
|
|
||||||
* @param string $view
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function path($view)
|
|
||||||
{
|
|
||||||
$view = str_replace('.', '/', $view);
|
|
||||||
|
|
||||||
foreach (array(EXT, BLADE_EXT) as $extension)
|
|
||||||
{
|
|
||||||
if (file_exists($path = $this->path.$view.$extension)) return $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception("View [$view] does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Magic Method for handling the dynamic creation of named views.
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // Create an instance of the "layout" named view
|
|
||||||
* $view = View::of_layout();
|
|
||||||
*
|
|
||||||
* // Create an instance of a named view with data
|
|
||||||
* $view = View::of_layout(array('name' => 'Taylor'));
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
public function __call($method, $parameters)
|
|
||||||
{
|
|
||||||
if (strpos($method, 'of_') === 0)
|
|
||||||
{
|
|
||||||
return $this->of(substr($method, 3), Arr::get($parameters, 0, array()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class View_Composer {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The view composers.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $composers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new view composer instance.
|
|
||||||
*
|
|
||||||
* @param array $composers
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function __construct($composers)
|
|
||||||
{
|
|
||||||
$this->composers = $composers;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find the key for a view by name.
|
|
||||||
*
|
|
||||||
* The view's key can be used to create instances of the view through the typical
|
|
||||||
* methods available on the view factory.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function name($name)
|
|
||||||
{
|
|
||||||
// The view's name may specified in several different ways in the composers file.
|
|
||||||
// The composer may simple have a string value, which is the name. Or, the composer
|
|
||||||
// could have an array value in which a "name" key exists.
|
|
||||||
foreach ($this->composers as $key => $value)
|
|
||||||
{
|
|
||||||
if ($name === $value or (isset($value['name']) and $name === $value['name'])) { return $key; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call the composer for the view instance.
|
|
||||||
*
|
|
||||||
* @param View $view
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function compose(View $view)
|
|
||||||
{
|
|
||||||
// The shared composer is called for every view instance. This allows the
|
|
||||||
// convenient binding of global view data or partials within a single method.
|
|
||||||
if (isset($this->composers['shared'])) call_user_func($this->composers['shared'], $view);
|
|
||||||
|
|
||||||
if (isset($this->composers[$view->view]))
|
|
||||||
{
|
|
||||||
foreach ((array) $this->composers[$view->view] as $key => $value)
|
|
||||||
{
|
|
||||||
if ($value instanceof Closure) return call_user_func($value, $view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class View {
|
class View {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,36 +24,138 @@ class View {
|
||||||
protected $path;
|
protected $path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The view composer instance.
|
* All of the view composers for the application.
|
||||||
*
|
*
|
||||||
* @var View_Composer
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $composer;
|
protected static $composers;
|
||||||
|
|
||||||
/**
|
|
||||||
* The view factory instance, which is used to create sub-views.
|
|
||||||
*
|
|
||||||
* @var View_Factory
|
|
||||||
*/
|
|
||||||
protected $factory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new view instance.
|
* Create a new view instance.
|
||||||
*
|
*
|
||||||
* @param View_Factory $factory
|
* @param string $view
|
||||||
* @param View_Composer $composer
|
* @param array $data
|
||||||
* @param string $view
|
|
||||||
* @param array $data
|
|
||||||
* @param string $path
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function __construct(View_Factory $factory, View_Composer $composer, $view, $data, $path)
|
public function __construct($view, $data = array())
|
||||||
{
|
{
|
||||||
$this->view = $view;
|
$this->view = $view;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->path = $path;
|
$this->path = $this->path($view);
|
||||||
$this->factory = $factory;
|
}
|
||||||
$this->composer = $composer;
|
|
||||||
|
/**
|
||||||
|
* Get the path to a given view on disk.
|
||||||
|
*
|
||||||
|
* The view may be either a "normal" view or a "Blade" view, so we will
|
||||||
|
* need to check the view directory for either extension.
|
||||||
|
*
|
||||||
|
* @param string $view
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function path($view)
|
||||||
|
{
|
||||||
|
$view = str_replace('.', '/', $view);
|
||||||
|
|
||||||
|
foreach (array(EXT, BLADE_EXT) as $extension)
|
||||||
|
{
|
||||||
|
if (file_exists($path = VIEW_PATH.$view.$extension)) return $path;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception("View [$view] does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new view instance.
|
||||||
|
*
|
||||||
|
* The name of the view given to this method should correspond to a view
|
||||||
|
* within your application views directory. Dots or slashes may used to
|
||||||
|
* reference views within sub-directories.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* // Create a new view instance
|
||||||
|
* $view = View::make('home.index');
|
||||||
|
*
|
||||||
|
* // Create a new view instance with bound data
|
||||||
|
* $view = View::make('home.index', array('name' => 'Taylor'));
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param string $view
|
||||||
|
* @param array $data
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
public static function make($view, $data = array())
|
||||||
|
{
|
||||||
|
return new static($view, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new view instance from a view name.
|
||||||
|
*
|
||||||
|
* View names are defined in the application composers file.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* // Create an instance of the "layout" named view
|
||||||
|
* $view = View::of('layout');
|
||||||
|
*
|
||||||
|
* // Create an instance of the "layout" view with bound data
|
||||||
|
* $view = View::of('layout', array('name' => 'Taylor'));
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @param array $data
|
||||||
|
* @return View
|
||||||
|
*/
|
||||||
|
public static function of($name, $data = array())
|
||||||
|
{
|
||||||
|
if ( ! is_null($view = static::name($name))) return static::make($view, $data);
|
||||||
|
|
||||||
|
throw new \Exception("Named view [$name] is not defined.");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the key for a view by name.
|
||||||
|
*
|
||||||
|
* The view's key can be used to create instances of the view through the typical
|
||||||
|
* methods available on the view factory.
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected static function name($name)
|
||||||
|
{
|
||||||
|
if (is_null(static::$composers)) static::$composers = require APP_PATH.'composers'.EXT;
|
||||||
|
|
||||||
|
// The view's name may specified in several different ways in the composers file.
|
||||||
|
// The composer may simple have a string value, which is the name. Or, the composer
|
||||||
|
// could have an array value in which a "name" key exists.
|
||||||
|
foreach (static::$composers as $key => $value)
|
||||||
|
{
|
||||||
|
if ($name === $value or (isset($value['name']) and $name === $value['name'])) { return $key; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the composer for the view instance.
|
||||||
|
*
|
||||||
|
* @param View $view
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected static function compose(View $view)
|
||||||
|
{
|
||||||
|
if (is_null(static::$composers)) static::$composers = require APP_PATH.'composers'.EXT;
|
||||||
|
|
||||||
|
// The shared composer is called for every view instance. This allows the
|
||||||
|
// convenient binding of global view data or partials within a single method.
|
||||||
|
if (isset(static::$composers['shared'])) call_user_func(static::$composers['shared'], $view);
|
||||||
|
|
||||||
|
if (isset(static::$composers[$view->view]))
|
||||||
|
{
|
||||||
|
foreach ((array) static::$composers[$view->view] as $key => $value)
|
||||||
|
{
|
||||||
|
if ($value instanceof Closure) return call_user_func($value, $view);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,7 +165,7 @@ public function __construct(View_Factory $factory, View_Composer $composer, $vie
|
||||||
*/
|
*/
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
$this->composer->compose($this);
|
static::compose($this);
|
||||||
|
|
||||||
// All nested views and responses are evaluated before the main view. This allows
|
// All nested views and responses are evaluated before the main view. This allows
|
||||||
// the assets used by these views to be added to the asset container before the
|
// the assets used by these views to be added to the asset container before the
|
||||||
|
@ -288,7 +200,7 @@ protected function compile()
|
||||||
// For simplicity, compiled views are stored in a single directory by the MD5 hash of
|
// For simplicity, compiled views are stored in a single directory by the MD5 hash of
|
||||||
// their name. This allows us to avoid recreating the entire view directory structure
|
// their name. This allows us to avoid recreating the entire view directory structure
|
||||||
// within the compiled views directory.
|
// within the compiled views directory.
|
||||||
$compiled = $this->factory->compiled.md5($this->view);
|
$compiled = STORAGE_PATH.'views/'.md5($this->view);
|
||||||
|
|
||||||
// The view will only be re-compiled if the view has been modified since the last compiled
|
// The view will only be re-compiled if the view has been modified since the last compiled
|
||||||
// version of the view was created or no compiled view exists. Otherwise, the path will
|
// version of the view was created or no compiled view exists. Otherwise, the path will
|
||||||
|
@ -322,7 +234,7 @@ protected function compile()
|
||||||
*/
|
*/
|
||||||
public function nest($key, $view, $data = array())
|
public function nest($key, $view, $data = array())
|
||||||
{
|
{
|
||||||
return $this->with($key, $this->factory->make($view, $data));
|
return $this->with($key, static::make($view, $data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -373,4 +285,23 @@ public function __unset($key)
|
||||||
unset($this->data[$key]);
|
unset($this->data[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Magic Method for handling the dynamic creation of named views.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* // Create an instance of the "layout" named view
|
||||||
|
* $view = View::of_layout();
|
||||||
|
*
|
||||||
|
* // Create an instance of a named view with data
|
||||||
|
* $view = View::of_layout(array('name' => 'Taylor'));
|
||||||
|
* </code>
|
||||||
|
*/
|
||||||
|
public static function __callStatic($method, $parameters)
|
||||||
|
{
|
||||||
|
if (strpos($method, 'of_') === 0)
|
||||||
|
{
|
||||||
|
return static::of(substr($method, 3), Arr::get($parameters, 0, array()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue