diff --git a/application/config/aliases.php b/application/config/aliases.php index 548b80d7..5badd7de 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -19,36 +19,35 @@ */ 'Arr' => 'Laravel\\Arr', - 'Asset' => 'Laravel\\Facades\\Asset', + 'Asset' => 'Laravel\\Asset', 'Auth' => 'Laravel\\Facades\\Auth', 'Benchmark' => 'Laravel\\Benchmark', 'Cache' => 'Laravel\\Facades\\Cache', - 'Config' => 'Laravel\\Facades\\Config', + 'Config' => 'Laravel\\Config', 'Controller' => 'Laravel\\Controller', - 'Cookie' => 'Laravel\\Facades\\Cookie', + 'Cookie' => 'Laravel\\Cookie', 'Crypter' => 'Laravel\\Facades\\Crypter', - 'DB' => 'Laravel\\Facades\\DB', - 'Download' => 'Laravel\\Facades\\Download', + 'DB' => 'Laravel\\Database\\Manager', 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', - 'File' => 'Laravel\\Facades\\File', - 'Form' => 'Laravel\\Facades\\Form', + 'File' => 'Laravel\\File', + 'Form' => 'Laravel\\Form', 'Hasher' => 'Laravel\\Facades\\Hasher', - 'HTML' => 'Laravel\\Facades\\HTML', + 'HTML' => 'Laravel\\HTML', 'Inflector' => 'Laravel\\Inflector', - 'Input' => 'Laravel\\Facades\\Input', + 'Input' => 'Laravel\\Input', 'IoC' => 'Laravel\\IoC', - 'Lang' => 'Laravel\\Facades\\Lang', - 'Loader' => 'Laravel\\Facades\\Loader', + 'Lang' => 'Laravel\\Lang', + 'Loader' => 'Laravel\\Loader', 'Messages' => 'Laravel\\Validation\\Messages', 'Package' => 'Laravel\\Facades\\Package', - 'URI' => 'Laravel\\Facades\\URI', - 'URL' => 'Laravel\\Facades\\URL', - 'Redirect' => 'Laravel\\Facades\\Redirect', - 'Request' => 'Laravel\\Facades\\Request', - 'Response' => 'Laravel\\Facades\\Response', + 'URI' => 'Laravel\\URI', + 'URL' => 'Laravel\\URL', + 'Redirect' => 'Laravel\\Redirect', + 'Request' => 'Laravel\\Request', + 'Response' => 'Laravel\\Response', 'Session' => 'Laravel\\Facades\\Session', 'Str' => 'Laravel\\Str', - 'Validator' => 'Laravel\\Facades\\Validator', - 'View' => 'Laravel\\Facades\\View', + 'Validator' => 'Laravel\\Validator', + 'View' => 'Laravel\\View', ); \ No newline at end of file diff --git a/laravel/asset.php b/laravel/asset.php index 1bb2cc98..e043a356 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -7,25 +7,7 @@ class Asset { * * @var 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; - } + protected static $containers = array(); /** * Get an asset container instance. @@ -45,14 +27,14 @@ public function __construct(HTML $html) * @param string $container * @return Asset_Container */ - public function container($container = 'default') + public static function container($container = 'default') { - if ( ! isset($this->containers[$container])) + if ( ! isset(static::$containers[$container])) { - $this->containers[$container] = new Asset_Container($container, $this->html); + static::$containers[$container] = new Asset_Container($container); } - return $this->containers[$container]; + return static::$containers[$container]; } /** @@ -66,9 +48,9 @@ public function container($container = 'default') * echo Asset::styles(); * */ - public function __call($method, $parameters) + public static function __callStatic($method, $parameters) { - return call_user_func_array(array($this->container(), $method), $parameters); + return call_user_func_array(array(static::container(), $method), $parameters); } } @@ -89,13 +71,6 @@ class Asset_Container { */ public $assets = array(); - /** - * The HTML writer instance. - * - * @var HTML - */ - protected $html; - /** * Create a new asset container instance. * @@ -103,10 +78,9 @@ class Asset_Container { * @param HTML $html * @return void */ - public function __construct($name, HTML $html) + public function __construct($name) { $this->name = $name; - $this->html = $html; } /** @@ -275,7 +249,7 @@ protected function asset($group, $name) $asset = $this->assets[$group][$name]; - return $this->html->$group($asset['source'], $asset['attributes']); + return HTML::$group($asset['source'], $asset['attributes']); } /** diff --git a/laravel/cache/drivers/apc.php b/laravel/cache/drivers/apc.php index cfd7a50a..25d6bb5d 100644 --- a/laravel/cache/drivers/apc.php +++ b/laravel/cache/drivers/apc.php @@ -1,53 +1,7 @@ apc = $apc; $this->key = $key; } @@ -87,7 +39,7 @@ public function has($key) */ protected function retrieve($key) { - if ( ! is_null($cache = $this->apc->fetch($this->key.$key))) return $cache; + if ( ! is_null($cache = apc_fetch($this->key.$key))) return $cache; } /** @@ -100,7 +52,7 @@ protected function retrieve($key) */ public function put($key, $value, $minutes) { - $this->apc->store($this->key.$key, $value, $minutes * 60); + apc_store($this->key.$key, $value, $minutes * 60); } /** @@ -111,7 +63,7 @@ public function put($key, $value, $minutes) */ public function forget($key) { - $this->apc->delete($this->key.$key); + apc_delete($this->key.$key); } } \ No newline at end of file diff --git a/laravel/cache/drivers/file.php b/laravel/cache/drivers/file.php index 47ace3e6..e99bb8fb 100644 --- a/laravel/cache/drivers/file.php +++ b/laravel/cache/drivers/file.php @@ -1,13 +1,8 @@ file = $file; $this->path = $path; } @@ -48,9 +41,9 @@ public function has($key) */ protected function retrieve($key) { - if ( ! $this->file->exists($this->path.$key)) return null; + if ( ! F::exists($this->path.$key)) return null; - if (time() >= substr($cache = $this->file->get($this->path.$key), 0, 10)) + if (time() >= substr($cache = F::get($this->path.$key), 0, 10)) { return $this->forget($key); } @@ -68,7 +61,7 @@ protected function retrieve($key) */ public function put($key, $value, $minutes) { - $this->file->put($this->path.$key, (time() + ($minutes * 60)).serialize($value)); + F::put($this->path.$key, (time() + ($minutes * 60)).serialize($value)); } /** @@ -79,7 +72,7 @@ public function put($key, $value, $minutes) */ public function forget($key) { - $this->file->delete($this->path.$key); + F::delete($this->path.$key); } } \ No newline at end of file diff --git a/laravel/config.php b/laravel/config.php index 3cae3665..d951a0fa 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -9,24 +9,24 @@ class Config { * * @var array */ - protected $items = array(); + protected static $items = array(); /** * The paths to the configuration files. * * @var array */ - protected $paths = array(); + protected static $paths = array(); /** - * Create a new configuration manager instance. + * Set the paths in which the configuration files are located. * * @param array $paths * @return void */ - public function __construct($paths) + public static function paths($paths) { - $this->paths = $paths; + static::$paths = $paths; } /** @@ -43,9 +43,9 @@ public function __construct($paths) * @param string $key * @return bool */ - public function has($key) + public static function has($key) { - return ! is_null($this->get($key)); + return ! is_null(static::get($key)); } /** @@ -74,21 +74,21 @@ public function has($key) * @param string $default * @return array */ - public function get($key, $default = null) + public static function get($key, $default = null) { - list($file, $key) = $this->parse($key); + list($file, $key) = static::parse($key); - if ( ! $this->load($file)) + if ( ! static::load($file)) { return ($default instanceof \Closure) ? call_user_func($default) : $default; } if (is_null($key)) { - return $this->items[$file]; + return static::$items[$file]; } - return Arr::get($this->items[$file], $key, $default); + return Arr::get(static::$items[$file], $key, $default); } /** @@ -113,19 +113,19 @@ public function get($key, $default = null) * @param mixed $value * @return void */ - public function set($key, $value) + public static function set($key, $value) { - list($file, $key) = $this->parse($key); + list($file, $key) = static::parse($key); - $this->load($file); + static::load($file); if (is_null($key)) { - Arr::set($this->items, $file, $value); + Arr::set(static::$items, $file, $value); } else { - Arr::set($this->items[$file], $key, $value); + Arr::set(static::$items[$file], $key, $value); } } @@ -142,7 +142,7 @@ public function set($key, $value) * @param string $key * @return array */ - protected function parse($key) + protected static function parse($key) { $segments = explode('.', $key); @@ -164,13 +164,13 @@ protected function parse($key) * @param string $file * @return bool */ - protected function load($file) + protected static function load($file) { - if (isset($this->items[$file])) return true; + if (isset(static::$items[$file])) return true; $config = array(); - foreach ($this->paths as $directory) + foreach (static::$paths as $directory) { if (file_exists($path = $directory.$file.EXT)) { @@ -180,10 +180,10 @@ protected function load($file) if (count($config) > 0) { - $this->items[$file] = $config; + static::$items[$file] = $config; } - return isset($this->items[$file]); + return isset(static::$items[$file]); } } \ No newline at end of file diff --git a/laravel/config/container.php b/laravel/config/container.php index 754f649d..57a63403 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -8,64 +8,15 @@ |-------------------------------------------------------------------------- */ - 'laravel.asset' => array('singleton' => true, 'resolver' => function($c) - { - return new Asset($c->resolve('laravel.html')); - }), - - 'laravel.auth' => array('singleton' => true, 'resolver' => function($c) { - return new Security\Auth($c->resolve('laravel.config'), $c->resolve('laravel.session')); - }), - - - 'laravel.config' => array('singleton' => true, 'resolver' => function($c) - { - $paths = array(SYS_CONFIG_PATH, CONFIG_PATH); - - if (isset($_SERVER['LARAVEL_ENV'])) - { - $paths[] = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/'; - } - - return new Config($paths); + return new Security\Auth($c->resolve('laravel.session')); }), 'laravel.crypter' => array('resolver' => function($c) { - return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', $c->resolve('laravel.config')->get('application.key')); - }), - - - 'laravel.cookie' => array('singleton' => true, 'resolver' => function() - { - return new Cookie($_COOKIE); - }), - - - 'laravel.database' => array('singleton' => true, 'resolver' => function($c) - { - return new Database\Manager($c->resolve('laravel.config')); - }), - - - 'laravel.download' => array('singleton' => true, 'resolver' => function($c) - { - return new Download($c->resolve('laravel.file')); - }), - - - 'laravel.file' => array('singleton' => true, 'resolver' => function($c) - { - return new File($c->resolve('laravel.config')->get('mimes')); - }), - - - 'laravel.form' => array('singleton' => true, 'resolver' => function($c) - { - return new Form($c->resolve('laravel.request'), $c->resolve('laravel.html'), $c->resolve('laravel.url')); + return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', Config::get('application.key')); }), @@ -74,130 +25,6 @@ return new Security\Hashing\Bcrypt(8, false); }), - - 'laravel.html' => array('singleton' => true, 'resolver' => function($c) - { - return new HTML($c->resolve('laravel.url'), $c->resolve('laravel.config')->get('application.encoding')); - }), - - - 'laravel.input' => array('singleton' => true, 'resolver' => function($c) - { - list($file, $cookie, $input, $files) = array( - $c->resolve('laravel.file'), - $c->resolve('laravel.cookie'), - $c->resolve('laravel.input.array'), - $_FILES, - ); - - return new Input($file, $cookie, $input, $files); - }), - - - 'laravel.input.array' => 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 $input; - }), - - - 'laravel.lang' => array('singleton' => true, 'resolver' => function($c) - { - require_once SYS_PATH.'lang'.EXT; - - return new Lang_Factory($c->resolve('laravel.config'), array(SYS_LANG_PATH, LANG_PATH)); - }), - - - 'laravel.loader' => array('singleton' => true, 'resolver' => function($c) - { - require_once SYS_PATH.'loader'.EXT; - - $aliases = $c->resolve('laravel.config')->get('aliases'); - - return new Loader(array(BASE_PATH, APP_PATH.'models/', APP_PATH), $aliases); - }), - - - 'laravel.redirect' => array('singleton' => true, 'resolver' => function($c) - { - return new Redirect($c->resolve('laravel.url')); - }), - - - 'laravel.request' => array('singleton' => true, 'resolver' => function($c) - { - return new Request($c->resolve('laravel.uri')->get(), $_SERVER, $_POST); - }), - - - 'laravel.response' => array('singleton' => true, 'resolver' => function($c) - { - require_once SYS_PATH.'response'.EXT; - - return new Response_Factory($c->resolve('laravel.view'), $c->resolve('laravel.file')); - }), - - - 'laravel.uri' => array('singleton' => true, 'resolver' => function($c) - { - return new URI($_SERVER, $c->resolve('laravel.config')->get('application.url')); - }), - - - 'laravel.url' => array('singleton' => true, 'resolver' => function($c) - { - list($router, $request, $base, $index) = array( - $c->resolve('laravel.routing.router'), - $c->resolve('laravel.request'), - $c->resolve('laravel.config')->get('application.url'), - $c->resolve('laravel.config')->get('application.index'), - ); - - return new URL($router, $base, $index, $request->secure()); - }), - - - 'laravel.validator' => array('singleton' => true, 'resolver' => function($c) - { - require_once SYS_PATH.'validation/validator'.EXT; - - return new Validation\Validator_Factory($c->resolve('laravel.lang')); - }), - - - 'laravel.view' => array('singleton' => true, 'resolver' => function($c) - { - require_once SYS_PATH.'view'.EXT; - - return new View_Factory(new View_Composer(require APP_PATH.'composers'.EXT), VIEW_PATH); - }), - /* |-------------------------------------------------------------------------- | Laravel Routing Components @@ -229,31 +56,25 @@ 'laravel.cache' => array('singleton' => true, 'resolver' => function($c) { - return new Cache\Manager($c, $c->resolve('laravel.config')->get('cache.driver')); + return new Cache\Manager($c, Config::get('cache.driver')); }), 'laravel.cache.apc' => array('resolver' => function($c) { - require_once SYS_PATH.'cache/drivers/apc'.EXT; - - $key = $c->resolve('laravel.config')->get('cache.key'); - - return new Cache\Drivers\APC(new Cache\Drivers\APC_Engine, $key); + return new Cache\Drivers\APC(Config::get('cache.key')); }), 'laravel.cache.file' => array('resolver' => function($c) { - return new Cache\Drivers\File($c->resolve('laravel.file'), CACHE_PATH); + return new Cache\Drivers\File(CACHE_PATH); }), 'laravel.cache.memcached' => array('resolver' => function($c) { - $key = $c->resolve('laravel.config')->get('cache.key'); - - return new Cache\Drivers\Memcached($c->resolve('laravel.cache.memcache.connection'), $key); + return new Cache\Drivers\Memcached($c->resolve('laravel.cache.memcache.connection'), Config::get('cache.key')); }), @@ -261,7 +82,7 @@ { $memcache = new \Memcache; - foreach ($c->resolve('laravel.config')->get('cache.servers') as $server) + foreach (Config::get('cache.servers') as $server) { $memcache->addServer($server['host'], $server['port'], true, $server['weight']); } @@ -282,23 +103,21 @@ '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) { - $config = $c->resolve('laravel.config'); + $driver = $c->resolve('laravel.session.'.Config::get('session.driver')); - $driver = $c->resolve('laravel.session.'.$config->get('session.driver')); - - return new Session\Manager($driver, $c->resolve('laravel.session.transporter'), $config); + return new Session\Manager($driver, $c->resolve('laravel.session.transporter')); }), 'laravel.session.transporter' => array('resolver' => function($c) { - return new Session\Transporters\Cookie($c->resolve('laravel.cookie')); + return new Session\Transporters\Cookie; }), @@ -318,13 +137,13 @@ 'laravel.session.database' => array('resolver' => function($c) { - return new Session\Drivers\Database($c->resolve('laravel.database')->connection()); + return new Session\Drivers\Database(Database\Manager::connection()); }), 'laravel.session.file' => array('resolver' => function($c) { - return new Session\Drivers\File($c->resolve('laravel.file'), SESSION_PATH); + return new Session\Drivers\File(SESSION_PATH); }), diff --git a/laravel/controller.php b/laravel/controller.php index 2b1ee887..03b0a786 100644 --- a/laravel/controller.php +++ b/laravel/controller.php @@ -21,7 +21,7 @@ public function before() {} */ public function __call($method, $parameters) { - return IoC::container()->resolve('laravel.response')->error('404'); + return Response::error('404'); } /** diff --git a/laravel/cookie.php b/laravel/cookie.php index c78ea0ca..65fb1c14 100644 --- a/laravel/cookie.php +++ b/laravel/cookie.php @@ -2,30 +2,12 @@ class Cookie { - /** - * All of the cookies for the current request. - * - * @var array - */ - protected $cookies; - /** * The cookies that will be sent to the browser at the end of the request. * * @var array */ - protected $queue = array(); - - /** - * Create a new cookie manager instance. - * - * @param array $cookies - * @return void - */ - public function __construct(&$cookies) - { - $this->cookies = &$cookies; - } + protected static $queue = array(); /** * Determine if a cookie exists. @@ -33,9 +15,9 @@ public function __construct(&$cookies) * @param string $name * @return bool */ - public function has($name) + public static function has($name) { - return ! is_null($this->get($name)); + return ! is_null(static::get($name)); } /** @@ -53,9 +35,9 @@ public function has($name) * @param mixed $default * @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); } /** @@ -69,9 +51,9 @@ public function get($name, $default = null) * @param bool $http_only * @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); } /** @@ -100,13 +82,13 @@ public function forever($name, $value, $path = '/', $domain = null, $secure = fa * @param bool $http_only * @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 ($minutes < 0) unset($this->cookies[$name]); + if ($minutes < 0) unset($_COOKIE[$name]); $time = ($minutes != 0) ? time() + ($minutes * 60) : 0; - $this->queue[] = compact('name', 'value', 'time', 'path', 'domain', 'secure', 'http_only'); + static::$queue[] = compact('name', 'value', 'time', 'path', 'domain', 'secure', 'http_only'); } /** @@ -116,9 +98,9 @@ public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $s * * @return void */ - public function send() + public static function send() { - foreach ($this->queue as $cookie) + foreach (static::$queue as $cookie) { call_user_func_array('setcookie', $cookie); } @@ -130,9 +112,9 @@ public function send() * @param string $name * @return bool */ - public function forget($name) + public static function forget($name) { - return $this->put($name, null, -60); + return static::put($name, null, -60); } } \ No newline at end of file diff --git a/laravel/core.php b/laravel/core.php index f79fdd4d..200c74c0 100644 --- a/laravel/core.php +++ b/laravel/core.php @@ -36,50 +36,50 @@ // -------------------------------------------------------------- require SYS_PATH.'facades'.EXT; require SYS_PATH.'config'.EXT; +require SYS_PATH.'loader'.EXT; require SYS_PATH.'arr'.EXT; +// -------------------------------------------------------------- +// Determine the application environment. +// -------------------------------------------------------------- +$environment = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : null; + +// -------------------------------------------------------------- +// Register the configuration file paths. +// -------------------------------------------------------------- +$config = array(SYS_CONFIG_PATH, CONFIG_PATH); + +if ( ! is_null($environment)) $config[] = CONFIG_PATH.$environment.'/'; + +Config::paths($config); + // -------------------------------------------------------------- // Bootstrap the IoC container. // -------------------------------------------------------------- require SYS_PATH.'container'.EXT; -$dependencies = require SYS_CONFIG_PATH.'container'.EXT; - -if (file_exists($path = CONFIG_PATH.'container'.EXT)) -{ - $dependencies = array_merge($dependencies, require $path); -} - -$env = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : null; - -if ( ! is_null($env) and file_exists($path = CONFIG_PATH.$env.'/container'.EXT)) -{ - $dependencies = array_merge($dependencies, require $path); -} - -$container = new Container($dependencies); +$container = new Container(Config::get('container')); IoC::$container = $container; // -------------------------------------------------------------- // Register the auto-loader on the auto-loader stack. // -------------------------------------------------------------- -spl_autoload_register(array($container->resolve('laravel.loader'), 'load')); +spl_autoload_register(array('Laravel\\Loader', 'load')); -// -------------------------------------------------------------- -// Set the application environment configuration option. -// -------------------------------------------------------------- -$container->resolve('laravel.config')->set('application.env', $env); +Loader::$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH); + +Loader::$aliases = Config::get('aliases'); // -------------------------------------------------------------- // Define some convenient global functions. // -------------------------------------------------------------- function e($value) { - return IoC::container()->resolve('laravel.html')->entities($value); + return HTML::entities($value); } function __($key, $replacements = array(), $language = null) { - return IoC::container()->resolve('laravel.lang')->line($key, $replacements, $language); + return Lang::line($key, $replacements, $language); } \ No newline at end of file diff --git a/laravel/database/manager.php b/laravel/database/manager.php index b7cb6844..0234d018 100644 --- a/laravel/database/manager.php +++ b/laravel/database/manager.php @@ -9,25 +9,7 @@ class Manager { * * @var array */ - protected $connections = array(); - - /** - * The configuration manager instance. - * - * @var Config - */ - protected $config; - - /** - * Create a new database manager instance. - * - * @param Connector $connector - * @return void - */ - public function __construct(Config $config) - { - $this->config = $config; - } + protected static $connections = array(); /** * Get a database connection. @@ -39,23 +21,23 @@ public function __construct(Config $config) * @param string $connection * @return Connection */ - public function connection($connection = null) + public static function connection($connection = null) { - if (is_null($connection)) $connection = $this->config->get('database.default'); + if (is_null($connection)) $connection = Config::get('database.default'); - if ( ! array_key_exists($connection, $this->connections)) + if ( ! array_key_exists($connection, static::$connections)) { - $config = $this->config->get("database.connections.{$connection}"); + $config = Config::get("database.connections.{$connection}"); if (is_null($config)) { throw new \Exception("Database connection configuration is not defined for connection [$connection]."); } - $this->connections[$connection] = new Connection($this->connect($config), $config); + static::$connections[$connection] = new Connection(static::connect($config), $config); } - return $this->connections[$connection]; + return static::$connections[$connection]; } /** @@ -64,7 +46,7 @@ public function connection($connection = null) * @param array $config * @return PDO */ - protected function connect($config) + protected static function connect($config) { if (isset($config['connector'])) { return call_user_func($config['connector'], $config); } @@ -96,9 +78,9 @@ protected function connect($config) * @param string $connection * @return Queries\Query */ - public function table($table, $connection = null) + public static function table($table, $connection = null) { - return $this->connection($connection)->table($table); + return static::connection($connection)->table($table); } /** @@ -106,9 +88,9 @@ public function table($table, $connection = null) * * This provides a convenient API for querying or examining the default database connection. */ - public function __call($method, $parameters) + public static function __callStatic($method, $parameters) { - return call_user_func_array(array($this->connection(), $method), $parameters); + return call_user_func_array(array(static::connection(), $method), $parameters); } } \ No newline at end of file diff --git a/laravel/facades.php b/laravel/facades.php index 1ba4a6b3..46fbe0a0 100644 --- a/laravel/facades.php +++ b/laravel/facades.php @@ -32,27 +32,9 @@ public static function __callStatic($method, $parameters) } -class Asset extends Facade { public static $resolve = 'laravel.asset'; } class Auth extends Facade { public static $resolve = 'laravel.auth'; } class Cache extends Facade { public static $resolve = 'laravel.cache'; } -class Config extends Facade { public static $resolve = 'laravel.config'; } -class Cookie extends Facade { public static $resolve = 'laravel.cookie'; } class Crypter extends Facade { public static $resolve = 'laravel.crypter'; } -class DB extends Facade { public static $resolve = 'laravel.database'; } -class Download extends Facade { public static $resolve = 'laravel.download'; } -class File extends Facade { public static $resolve = 'laravel.file'; } -class Form extends Facade { public static $resolve = 'laravel.form'; } class Hasher extends Facade { public static $resolve = 'laravel.hasher'; } -class HTML extends Facade { public static $resolve = 'laravel.html'; } -class Input extends Facade { public static $resolve = 'laravel.input'; } -class Lang extends Facade { public static $resolve = 'laravel.lang'; } -class Loader extends Facade { public static $resolve = 'laravel.loader'; } class Package extends Facade { public static $resolve = 'laravel.package'; } -class Redirect extends Facade { public static $resolve = 'laravel.redirect'; } -class Request extends Facade { public static $resolve = 'laravel.request'; } -class Response extends Facade { public static $resolve = 'laravel.response'; } -class Session extends Facade { public static $resolve = 'laravel.session'; } -class URI extends Facade { public static $resolve = 'laravel.uri'; } -class URL extends Facade { public static $resolve = 'laravel.url'; } -class Validator extends Facade { public static $resolve = 'laravel.validator'; } -class View extends Facade { public static $resolve = 'laravel.view'; } \ No newline at end of file +class Session extends Facade { public static $resolve = 'laravel.session'; } \ No newline at end of file diff --git a/laravel/file.php b/laravel/file.php index 72095804..52731f32 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -1,37 +1,14 @@ mimes = $mimes; - } - /** * Determine if a file exists. * * @param string $path * @return bool */ - public function exists($path) + public static function exists($path) { return file_exists($path); } @@ -42,7 +19,7 @@ public function exists($path) * @param string $path * @return string */ - public function get($path) + public static function get($path) { return file_get_contents($path); } @@ -54,7 +31,7 @@ public function get($path) * @param string $data * @return int */ - public function put($path, $data) + public static function put($path, $data) { return file_put_contents($path, $data, LOCK_EX); } @@ -66,7 +43,7 @@ public function put($path, $data) * @param string $data * @return int */ - public function append($path, $data) + public static function append($path, $data) { return file_put_contents($path, $data, LOCK_EX | FILE_APPEND); } @@ -77,9 +54,9 @@ public function append($path, $data) * @param string $path * @return void */ - public function delete($path) + public static function delete($path) { - if ($this->exists($path)) @unlink($path); + if (static::exists($path)) @unlink($path); } /** @@ -88,7 +65,7 @@ public function delete($path) * @param string $path * @return string */ - public function extension($path) + public static function extension($path) { return pathinfo($path, PATHINFO_EXTENSION); } @@ -99,7 +76,7 @@ public function extension($path) * @param string $path * @return string */ - public function type($path) + public static function type($path) { return filetype($path); } @@ -110,7 +87,7 @@ public function type($path) * @param string $file * @return int */ - public function size($path) + public static function size($path) { return filesize($path); } @@ -121,7 +98,7 @@ public function size($path) * @param string $path * @return int */ - public function modified($path) + public static function modified($path) { return filemtime($path); } @@ -134,7 +111,7 @@ public function modified($path) * @param array $files * @return bool */ - public function upload($key, $path, $files) + public static function upload($key, $path, $files) { return move_uploaded_file($files[$key]['tmp_name'], $path); } @@ -153,11 +130,13 @@ public function upload($key, $path, $files) * @param string $default * @return string */ - public function mime($extension, $default = 'application/octet-stream') + public static function mime($extension, $default = 'application/octet-stream') { - if ( ! array_key_exists($extension, $this->mimes)) return $default; + $mimes = Config::get('mimes'); - return (is_array($this->mimes[$extension])) ? $this->mimes[$extension][0] : $this->mimes[$extension]; + if ( ! array_key_exists($extension, $mimes)) return $default; + + return (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension]; } /** @@ -177,13 +156,15 @@ public function mime($extension, $default = 'application/octet-stream') * @param string $path * @return bool */ - public function is($extensions, $path) + public static function is($extensions, $path) { + $mimes = Config::get('mimes'); + foreach ((array) $extensions as $extension) { $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); - if (isset($this->mimes[$extension]) and in_array((array) $this->mimes[$extension])) return true; + if (isset($mimes[$extension]) and in_array((array) $mimes[$extension])) return true; } return false; diff --git a/laravel/form.php b/laravel/form.php index 63695f47..dd90bf0b 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -2,27 +2,6 @@ class Form { - /** - * The request instance. - * - * @var Request - */ - protected $request; - - /** - * The HTML writer instance. - * - * @var HTML - */ - protected $html; - - /** - * The URL generator instance. - * - * @var URL - */ - protected $url; - /** * All of the label names that have been created. * @@ -31,22 +10,7 @@ class Form { * * @var array */ - protected $labels = array(); - - /** - * Create a new form writer instance. - * - * @param Request $request - * @param HTML $html - * @param URL $url - * @return void - */ - public function __construct(Request $request, HTML $html, URL $url) - { - $this->url = $url; - $this->html = $html; - $this->request = $request; - } + protected static $labels = array(); /** * Open a HTML form. @@ -72,18 +36,18 @@ public function __construct(Request $request, HTML $html, URL $url) * @param bool $https * @return string */ - public function open($action = null, $method = 'POST', $attributes = array(), $https = false) + public static function open($action = null, $method = 'POST', $attributes = array(), $https = false) { - list($attributes['action'], $attributes['method']) = array($this->action($action, $https), $this->method($method)); + list($attributes['action'], $attributes['method']) = array(static::action($action, $https), static::method($method)); if ( ! array_key_exists('accept-charset', $attributes)) { - $attributes['accept-charset'] = $this->html->encoding; + $attributes['accept-charset'] = Config::get('application.encoding'); } - $append = ($method == 'PUT' or $method == 'DELETE') ? $this->hidden(Request::spoofer, $method) : ''; + $append = ($method == 'PUT' or $method == 'DELETE') ? static::hidden(Request::spoofer, $method) : ''; - return '
'; } @@ -171,9 +135,9 @@ public function close() * * @return string */ - public function token() + public static function token() { - return $this->input('hidden', 'csrf_token', $this->raw_token()); + return static::input('hidden', 'csrf_token', static::raw_token()); } /** @@ -181,9 +145,9 @@ public function token() * * @return string */ - public function raw_token() + public static function raw_token() { - if (IoC::container()->resolve('laravel.config')->get('session.driver') == '') + if (Config::get('session.driver') == '') { throw new \Exception("A session driver must be specified before using CSRF tokens."); } @@ -207,11 +171,11 @@ public function raw_token() * @param array $attributes * @return string */ - public function label($name, $value, $attributes = array()) + public static function label($name, $value, $attributes = array()) { - $this->labels[] = $name; + static::$labels[] = $name; - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -236,13 +200,13 @@ public function label($name, $value, $attributes = array()) * @param array $attributes * @return string */ - public function input($type, $name, $value = null, $attributes = array()) + public static function input($type, $name, $value = null, $attributes = array()) { $name = (isset($attributes['name'])) ? $attributes['name'] : $name; - $id = $this->id($name, $attributes); + $id = static::id($name, $attributes); - return 'html->attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.PHP_EOL; + return ''.PHP_EOL; } /** @@ -253,9 +217,9 @@ public function input($type, $name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function text($name, $value = null, $attributes = array()) + public static function text($name, $value = null, $attributes = array()) { - return $this->input('text', $name, $value, $attributes); + return static::input('text', $name, $value, $attributes); } /** @@ -265,9 +229,9 @@ public function text($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function password($name, $attributes = array()) + public static function password($name, $attributes = array()) { - return $this->input('password', $name, null, $attributes); + return static::input('password', $name, null, $attributes); } /** @@ -278,9 +242,9 @@ public function password($name, $attributes = array()) * @param array $attributes * @return string */ - public function hidden($name, $value = null, $attributes = array()) + public static function hidden($name, $value = null, $attributes = array()) { - return $this->input('hidden', $name, $value, $attributes); + return static::input('hidden', $name, $value, $attributes); } /** @@ -291,9 +255,9 @@ public function hidden($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function search($name, $value = null, $attributes = array()) + public static function search($name, $value = null, $attributes = array()) { - return $this->input('search', $name, $value, $attributes); + return static::input('search', $name, $value, $attributes); } /** @@ -304,9 +268,9 @@ public function search($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function email($name, $value = null, $attributes = array()) + public static function email($name, $value = null, $attributes = array()) { - return $this->input('email', $name, $value, $attributes); + return static::input('email', $name, $value, $attributes); } /** @@ -317,9 +281,9 @@ public function email($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function telephone($name, $value = null, $attributes = array()) + public static function telephone($name, $value = null, $attributes = array()) { - return $this->input('tel', $name, $value, $attributes); + return static::input('tel', $name, $value, $attributes); } /** @@ -330,9 +294,9 @@ public function telephone($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function url($name, $value = null, $attributes = array()) + public static function url($name, $value = null, $attributes = array()) { - return $this->input('url', $name, $value, $attributes); + return static::input('url', $name, $value, $attributes); } /** @@ -343,9 +307,9 @@ public function url($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function number($name, $value = null, $attributes = array()) + public static function number($name, $value = null, $attributes = array()) { - return $this->input('number', $name, $value, $attributes); + return static::input('number', $name, $value, $attributes); } /** @@ -355,9 +319,9 @@ public function number($name, $value = null, $attributes = array()) * @param array $attributes * @return string */ - public function file($name, $attributes = array()) + public static function file($name, $attributes = array()) { - return $this->input('file', $name, null, $attributes); + return static::input('file', $name, null, $attributes); } /** @@ -376,15 +340,15 @@ public function file($name, $attributes = array()) * @param array $attributes * @return string */ - public function textarea($name, $value = '', $attributes = array()) + public static function textarea($name, $value = '', $attributes = array()) { - $attributes = array_merge($attributes, array('id' => $this->id($name, $attributes), 'name' => $name)); + $attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'name' => $name)); if ( ! isset($attributes['rows'])) $attributes['rows'] = 10; if ( ! isset($attributes['cols'])) $attributes['cols'] = 50; - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -404,20 +368,20 @@ public function textarea($name, $value = '', $attributes = array()) * @param array $attributes * @return string */ - public function select($name, $options = array(), $selected = null, $attributes = array()) + public static function select($name, $options = array(), $selected = null, $attributes = array()) { - $attributes = array_merge($attributes, array('id' => $this->id($name, $attributes), 'name' => $name)); + $attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'name' => $name)); $html = array(); foreach ($options as $value => $display) { - $option_attributes = array('value' => $this->html->entities($value), 'selected' => ($value == $selected) ? 'selected' : null); + $option_attributes = array('value' => HTML::entities($value), 'selected' => ($value == $selected) ? 'selected' : null); - $html[] = ''; + $html[] = ''; } - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -437,9 +401,9 @@ public function select($name, $options = array(), $selected = null, $attributes * @param array $attributes * @return string */ - public function checkbox($name, $value = 1, $checked = false, $attributes = array()) + public static function checkbox($name, $value = 1, $checked = false, $attributes = array()) { - return $this->checkable('checkbox', $name, $value, $checked, $attributes); + return static::checkable('checkbox', $name, $value, $checked, $attributes); } /** @@ -459,11 +423,11 @@ public function checkbox($name, $value = 1, $checked = false, $attributes = arra * @param array $attributes * @return string */ - public function radio($name, $value = null, $checked = false, $attributes = array()) + public static function radio($name, $value = null, $checked = false, $attributes = array()) { if (is_null($value)) $value = $name; - return $this->checkable('radio', $name, $value, $checked, $attributes); + return static::checkable('radio', $name, $value, $checked, $attributes); } /** @@ -476,11 +440,11 @@ public function radio($name, $value = null, $checked = false, $attributes = arra * @param array $attributes * @return string */ - protected function checkable($type, $name, $value, $checked, $attributes) + protected static function checkable($type, $name, $value, $checked, $attributes) { - $attributes = array_merge($attributes, array('id' => $this->id($name, $attributes), 'checked' => ($checked) ? 'checked' : null)); + $attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'checked' => ($checked) ? 'checked' : null)); - return $this->input($type, $name, $value, $attributes); + return static::input($type, $name, $value, $attributes); } /** @@ -498,9 +462,9 @@ protected function checkable($type, $name, $value, $checked, $attributes) * @param array $attributes * @return string */ - public function submit($value, $attributes = array()) + public static function submit($value, $attributes = array()) { - return $this->input('submit', null, $value, $attributes); + return static::input('submit', null, $value, $attributes); } /** @@ -510,9 +474,9 @@ public function submit($value, $attributes = array()) * @param array $attributes * @return string */ - public function reset($value, $attributes = array()) + public static function reset($value, $attributes = array()) { - return $this->input('reset', null, $value, $attributes); + return static::input('reset', null, $value, $attributes); } /** @@ -527,11 +491,11 @@ public function reset($value, $attributes = array()) * @param array $attributes * @return string */ - public function image($url, $name = null, $attributes = array()) + public static function image($url, $name = null, $attributes = array()) { - $attributes['src'] = $this->url->to_asset($url); + $attributes['src'] = URL::to_asset($url); - return $this->input('image', $name, null, $attributes); + return static::input('image', $name, null, $attributes); } /** @@ -550,9 +514,9 @@ public function image($url, $name = null, $attributes = array()) * @param array $attributes * @return string */ - public function button($value, $attributes = array()) + public static function button($value, $attributes = array()) { - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -565,11 +529,11 @@ public function button($value, $attributes = array()) * @param array $attributes * @return mixed */ - protected function id($name, $attributes) + protected static function id($name, $attributes) { if (array_key_exists('id', $attributes)) return $attributes['id']; - if (in_array($name, $this->labels)) return $name; + if (in_array($name, static::$labels)) return $name; } } \ No newline at end of file diff --git a/laravel/html.php b/laravel/html.php index 6b521c67..53390187 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -2,32 +2,6 @@ class HTML { - /** - * The encoding being used by the application. - * - * @var string - */ - protected $encoding; - - /** - * The URL generator instance. - * - * @var URL - */ - protected $url; - - /** - * Create a new HTML writer instance. - * - * @param string $encoding - * @return void - */ - public function __construct(URL $url, $encoding) - { - $this->url = $url; - $this->encoding = $encoding; - } - /** * Convert HTML characters to entities. * @@ -36,9 +10,9 @@ public function __construct(URL $url, $encoding) * @param string $value * @return string */ - public function entities($value) + public static function entities($value) { - return htmlentities($value, ENT_QUOTES, $this->encoding, false); + return htmlentities($value, ENT_QUOTES, Config::get('application.encoding'), false); } /** @@ -56,11 +30,11 @@ public function entities($value) * @param array $attributes * @return string */ - public function script($url, $attributes = array()) + public static function script($url, $attributes = array()) { - $url = $this->entities($this->url->to_asset($url)); + $url = static::entities(URL::to_asset($url)); - return ''.PHP_EOL; + return ''.PHP_EOL; } /** @@ -80,13 +54,13 @@ public function script($url, $attributes = array()) * @param array $attributes * @return string */ - public function style($url, $attributes = array()) + public static function style($url, $attributes = array()) { if ( ! array_key_exists('media', $attributes)) $attributes['media'] = 'all'; $attributes = array_merge($attributes, array('rel' => 'stylesheet', 'type' => 'text/css')); - return 'attributes($attributes).'>'.PHP_EOL; + return ''.PHP_EOL; } /** @@ -104,9 +78,9 @@ public function style($url, $attributes = array()) * @param array $attributes * @return string */ - public function span($value, $attributes = array()) + public static function span($value, $attributes = array()) { - return 'attributes($attributes).'>'.$this->entities($value).''; + return ''.static::entities($value).''; } /** @@ -127,11 +101,11 @@ public function span($value, $attributes = array()) * @param bool $asset * @return string */ - public function link($url, $title, $attributes = array(), $https = false, $asset = false) + public static function link($url, $title, $attributes = array(), $https = false, $asset = false) { - $url = $this->entities($this->url->to($url, $https, $asset)); + $url = static::entities(URL::to($url, $https, $asset)); - return 'attributes($attributes).'>'.$this->entities($title).''; + return ''.static::entities($title).''; } /** @@ -142,9 +116,9 @@ public function link($url, $title, $attributes = array(), $https = false, $asset * @param array $attributes * @return string */ - public function link_to_secure($url, $title, $attributes = array()) + public static function link_to_secure($url, $title, $attributes = array()) { - return $this->link($url, $title, $attributes, true); + return static::link($url, $title, $attributes, true); } /** @@ -157,9 +131,9 @@ public function link_to_secure($url, $title, $attributes = array()) * @param array $attributes * @return string */ - public function link_to_asset($url, $title, $attributes = array(), $https = false) + public static function link_to_asset($url, $title, $attributes = array(), $https = false) { - return $this->link($url, $title, $attributes, $https, true); + return static::link($url, $title, $attributes, $https, true); } /** @@ -170,9 +144,9 @@ public function link_to_asset($url, $title, $attributes = array(), $https = fals * @param array $attributes * @return string */ - public function link_to_secure_asset($url, $title, $attributes = array()) + public static function link_to_secure_asset($url, $title, $attributes = array()) { - return $this->link_to_asset($url, $title, $attributes, true); + return static::link_to_asset($url, $title, $attributes, true); } /** @@ -195,9 +169,9 @@ public function link_to_secure_asset($url, $title, $attributes = array()) * @param array $attributes * @return string */ - public function link_to_route($name, $title, $parameters = array(), $attributes = array(), $https = false) + public static function link_to_route($name, $title, $parameters = array(), $attributes = array(), $https = false) { - return $this->link($this->url->to_route($name, $parameters, $https), $title, $attributes); + return static::link(URL::to_route($name, $parameters, $https), $title, $attributes); } /** @@ -209,9 +183,9 @@ public function link_to_route($name, $title, $parameters = array(), $attributes * @param array $attributes * @return string */ - public function link_to_secure_route($name, $title, $parameters = array(), $attributes = array()) + public static function link_to_secure_route($name, $title, $parameters = array(), $attributes = array()) { - return $this->link_to_route($name, $title, $parameters, $attributes, true); + return static::link_to_route($name, $title, $parameters, $attributes, true); } /** @@ -235,15 +209,15 @@ public function link_to_secure_route($name, $title, $parameters = array(), $attr * @param array $attributes * @return string */ - public function mailto($email, $title = null, $attributes = array()) + public static function mailto($email, $title = null, $attributes = array()) { - $email = $this->email($email); + $email = static::email($email); if (is_null($title)) $title = $email; $email = 'mailto:'.$email; - return 'attributes($attributes).'>'.$this->entities($title).''; + return ''.static::entities($title).''; } /** @@ -252,9 +226,9 @@ public function mailto($email, $title = null, $attributes = array()) * @param string $email * @return string */ - public function email($email) + public static function email($email) { - return str_replace('@', '@', $this->obfuscate($email)); + return str_replace('@', '@', static::obfuscate($email)); } /** @@ -276,11 +250,11 @@ public function email($email) * @param array $attributes * @return string */ - public function image($url, $alt = '', $attributes = array()) + public static function image($url, $alt = '', $attributes = array()) { $attributes['alt'] = $alt; - return '
- * // Retrieve the "name" input item from a controller method
- * $name = $this->input->name;
- *
- */
- public function __get($key)
- {
- return $this->get($key);
- }
+}
-}
\ No newline at end of file
+/**
+ * Set the input values for the current request.
+ */
+$input = array();
+
+switch (Request::method())
+{
+ case 'GET':
+ $input = $_GET;
+ break;
+
+ 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::$input = $input;
\ No newline at end of file
diff --git a/laravel/lang.php b/laravel/lang.php
index 7fdc3c6a..3cbfe15a 100644
--- a/laravel/lang.php
+++ b/laravel/lang.php
@@ -1,65 +1,5 @@
paths = $paths;
- $this->config = $config;
- }
-
- /**
- * Begin retrieving a language line.
- *
- *
- * // Begin retrieving a language line
- * $lang = Lang::line('messages.welcome');
- *
- * // Begin retrieving a language line with replacements
- * $lang = Lang::line('validation.required', array('attribute' => 'email'));
- *
- * // Begin retrieving a language line in a given language
- * $lang = Lang::line('messages.welcome', null, 'sp');
- *
- *
- * @param string $key
- * @param array $replacements
- * @param string $language
- * @return Lang
- */
- public function line($key, $replacements = array(), $language = null)
- {
- $language = ( ! is_null($language)) $this->config->get('application.language') : $language;
-
- return new Lang($key, (array) $replacements, $language, $this->paths);
- }
-
-}
-
class Lang {
/**
@@ -105,17 +45,28 @@ class Lang {
* @param string $key
* @param array $replacements
* @param string $language
- * @param array $paths
* @return void
*/
- public function __construct($key, $replacements, $language, $paths)
+ protected function __construct($key, $replacements = array(), $language = null)
{
$this->key = $key;
- $this->paths = $paths;
$this->language = $language;
$this->replacements = $replacements;
}
+ /**
+ * Create a new language line instance.
+ *
+ * @param string $key
+ * @param array $replacements
+ * @param string $language
+ * @return Lang
+ */
+ public static function line($key, $replacements = array(), $language = null)
+ {
+ return new static($key, $replacements, $language);
+ }
+
/**
* Get the language line.
*
@@ -191,7 +142,7 @@ protected function load($file)
$language = array();
- foreach ($this->paths as $directory)
+ foreach (array(SYS_LANG_PATH, LANG_PATH) as $directory)
{
if (file_exists($path = $directory.$this->language.'/'.$file.EXT))
{
diff --git a/laravel/laravel.php b/laravel/laravel.php
index 36cf0ec2..7c12ef18 100644
--- a/laravel/laravel.php
+++ b/laravel/laravel.php
@@ -8,27 +8,25 @@
// --------------------------------------------------------------
// Get an instance of the configuration manager.
// --------------------------------------------------------------
-$config = $container->resolve('laravel.config');
-
-set_exception_handler(function($e) use ($config)
+set_exception_handler(function($e)
{
- call_user_func($config->get('error.handler'), $e);
+ call_user_func(Config::get('error.handler'), $e);
});
-set_error_handler(function($number, $error, $file, $line) use ($config)
+set_error_handler(function($number, $error, $file, $line)
{
$exception = new \ErrorException($error, $number, 0, $file, $line);
- call_user_func($config->get('error.handler'), $exception);
+ call_user_func(Config::get('error.handler'), $exception);
});
-register_shutdown_function(function() use ($config)
+register_shutdown_function(function()
{
if ( ! is_null($error = error_get_last()))
{
$exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
- call_user_func($config->get('error.handler'), $exception);
+ call_user_func(Config::get('error.handler'), $exception);
}
});
@@ -42,22 +40,22 @@
// --------------------------------------------------------------
// Set the default timezone.
// --------------------------------------------------------------
-date_default_timezone_set($config->get('application.timezone'));
+date_default_timezone_set(Config::get('application.timezone'));
// --------------------------------------------------------------
// Load the session and session manager.
// --------------------------------------------------------------
-if ($config->get('session.driver') !== '')
+if (Config::get('session.driver') !== '')
{
$session = $container->resolve('laravel.session.manager');
- $container->instance('laravel.session', $session->payload($config->get('session')));
+ $container->instance('laravel.session', $session->payload(Config::get('session')));
}
// --------------------------------------------------------------
// Route the request and get the response from the route.
// --------------------------------------------------------------
-$route = $container->resolve('laravel.routing.router')->route($container->resolve('laravel.request'));
+$route = $container->resolve('laravel.routing.router')->route(Request::method(), Request::uri());
if ( ! is_null($route))
{
@@ -65,7 +63,7 @@
}
else
{
- $response = $container->resolve('laravel.response')->error('404');
+ $response = Response::error('404');
}
// --------------------------------------------------------------
@@ -78,13 +76,13 @@
// --------------------------------------------------------------
if (isset($session))
{
- $session->close($container->resolve('laravel.session'), $config->get('session'));
+ $session->close($container->resolve('laravel.session'), Config::get('session'));
}
// --------------------------------------------------------------
// Send the queued cookies to the browser.
// --------------------------------------------------------------
-$container->resolve('laravel.cookie')->send();
+Cookie::send();
// --------------------------------------------------------------
// Send the response to the browser.
diff --git a/laravel/loader.php b/laravel/loader.php
index 96e27d15..6d61fea8 100644
--- a/laravel/loader.php
+++ b/laravel/loader.php
@@ -7,27 +7,14 @@ class Loader {
*
* @var array
*/
- protected $paths;
+ public static $paths = array();
/**
* The class aliases defined for the application.
*
* @var array
*/
- protected $aliases;
-
- /**
- * Create a new class loader instance.
- *
- * @param array $paths
- * @param array $aliases
- * @return void
- */
- public function __construct($paths, $aliases)
- {
- $this->paths = $paths;
- $this->aliases = $aliases;
- }
+ public static $aliases = array();
/**
* Load the file for a given class.
@@ -35,7 +22,7 @@ public function __construct($paths, $aliases)
* @param string $class
* @return void
*/
- public function load($class)
+ public static function load($class)
{
// All Laravel core classes follow a namespace to directory convention. So, we will
// replace all of the namespace slashes with directory slashes.
@@ -43,9 +30,9 @@ public function load($class)
// First, we'll check to determine if an alias exists. If it does, we will define the
// alias and bail out. Aliases are defined for most developer used core classes.
- if (array_key_exists($class, $this->aliases)) return class_alias($this->aliases[$class], $class);
+ if (array_key_exists($class, static::$aliases)) return class_alias(static::$aliases[$class], $class);
- foreach ($this->paths as $path)
+ foreach (static::$paths as $path)
{
if (file_exists($path = $path.$file.EXT))
{
@@ -70,9 +57,9 @@ public function load($class)
* @param string $class
* @return void
*/
- public function alias($alias, $class)
+ public static function alias($alias, $class)
{
- $this->aliases[$alias] = $class;
+ static::$aliases[$alias] = $class;
}
/**
@@ -88,9 +75,9 @@ public function alias($alias, $class)
* @param string $path
* @return void
*/
- public function path($path)
+ public static function path($path)
{
- $this->paths[] = rtrim($path, '/').'/';
+ static::$paths[] = rtrim($path, '/').'/';
}
/**
@@ -104,9 +91,9 @@ public function path($path)
* @param string $alias
* @return void
*/
- public function forget_alias($alias)
+ public static function forget_alias($alias)
{
- unset($this->aliases[$alias]);
+ unset(static::$aliases[$alias]);
}
}
\ No newline at end of file
diff --git a/laravel/paginator.php b/laravel/paginator.php
new file mode 100644
index 00000000..dd8fede5
--- /dev/null
+++ b/laravel/paginator.php
@@ -0,0 +1,303 @@
+html = $html;
+ $this->lang = $lang;
+ $this->request = $request;
+ }
+
+ public function make($results, $total, $per_page)
+ {
+ $page = Paginator::page($total, $per_page);
+
+ $last_page = ceil($total / $per_page);
+
+ return new Paginator($this->request, $this->html, $this->lang, $results, $page, $total, $per_page, $last_page);
+ }
+
+}
+
+class Paginator {
+
+ /**
+ * The results for the current page.
+ *
+ * @var array
+ */
+ public $results;
+
+ /**
+ * The total number of results.
+ *
+ * @var int
+ */
+ public $total;
+
+ /**
+ * The current page.
+ *
+ * @var int
+ */
+ public $page;
+
+ /**
+ * The number of items per page.
+ *
+ * @var int
+ */
+ public $per_page;
+
+ /**
+ * The last page available for the result set.
+ *
+ * @var int
+ */
+ public $last_page;
+
+ /**
+ * The language that should be used when generating page links.
+ *
+ * @var string
+ */
+ public $language;
+
+ /**
+ * The values that should be appended to the end of the link query strings.
+ *
+ * @var array
+ */
+ public $append = array();
+
+ /**
+ * Create a new Paginator instance.
+ *
+ * @param array $results
+ * @param int $page
+ * @param int $total
+ * @param int $per_page
+ * @param int $last_page
+ * @return void
+ */
+ protected function __construct(Request $request, HTML $html, Lang_Factory $lang, $results, $page, $total, $per_page, $last_page)
+ {
+ $this->html = $html;
+ $this->lang = $lang;
+ $this->page = $page;
+ $this->total = $total;
+ $this->request = $request;
+ $this->results = $results;
+ $this->per_page = $per_page;
+ $this->last_page = $last_page;
+ }
+
+ /**
+ * Create a new Paginator instance.
+ *
+ * @param array $results
+ * @param int $total
+ * @param int $per_page
+ * @return Paginator
+ */
+ public static function make($results, $total, $per_page)
+ {
+ return new static($results, static::page($total, $per_page), $total, $per_page, ceil($total / $per_page));
+ }
+
+ /**
+ * Get the current page from the request query string.
+ *
+ * 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 less than one, one will be returned.
+ * If the current page is greater than the last page, the last page will be returned.
+ *
+ * @param int $total
+ * @param int $per_page
+ * @return int
+ */
+ public static function page($total, $per_page)
+ {
+ $page = IoC::container()->resolve('laravel.input')->get('page', 1);
+
+ if (is_numeric($page) and $page > $last_page = ceil($total / $per_page))
+ {
+ return ($last_page > 0) ? $last_page : 1;
+ }
+
+ return ($page < 1 or filter_var($page, FILTER_VALIDATE_INT) === false) ? 1 : $page;
+ }
+
+ /**
+ * Create the HTML pagination links.
+ *
+ * @param int $adjacent
+ * @return string
+ */
+ public function links($adjacent = 3)
+ {
+ if ($this->last_page <= 1) return '';
+
+ // The hard-coded "7" is to account for all of the constant elements in a sliding range.
+ // Namely: The the current page, the two ellipses, the two beginning pages, and the two ending pages.
+ if ($this->last_page < 7 + ($adjacent * 2))
+ {
+ $numbers = $this->range(1, $this->last_page);
+ }
+ else
+ {
+ $numbers = $this->slider($adjacent);
+ }
+
+ return '
- * // Create a response instance
- * return Response::make('Hello World');
- *
- * // Create a response instance with a given status code
- * return Response::make('Hello World', 200);
- *
- *
- * @param mixed $content
- * @param int $status
- * @param array $headers
- * @return Response
- */
- public function make($content, $status = 200, $headers = array())
- {
- return new Response($content, $status, $headers);
- }
-
- /**
- * Create a new response instance containing a view.
- *
- *
- * // Create a new response instance with view content
- * return Response::view('home.index');
- *
- * // Create a new response instance with a view and bound data
- * return Response::view('home.index', array('name' => 'Fred'));
- *
- *
- * @param string $view
- * @param array $data
- * @return Response
- */
- public function view($view, $data = array())
- {
- return new Response($this->view->make($view, $data));
- }
-
- /**
- * Create a new response instance containing a named view.
- *
- *
- * // Create a new response instance with a named view
- * return Response::with('layout');
- *
- * // Create a new response instance with a named view and bound data
- * return Response::with('layout', array('name' => 'Fred'));
- *
- *
- * @param string $name
- * @param array $data
- * @return Response
- */
- public function with($name, $data = array())
- {
- return new Response($this->view->of($name, $data));
- }
-
- /**
- * Create a new error response instance.
- *
- * The response status code will be set using the specified code.
- *
- * Note: The specified error code should correspond to a view in your views/error directory.
- *
- *
- * // Create an error response for status 500
- * return Response::error('500');
- *
- *
- * @param int $code
- * @param array $data
- * @return Response
- */
- public function error($code, $data = array())
- {
- return new Response($this->view->make('error/'.$code, $data), $code);
- }
-
- /**
- * Create a new download response instance.
- *
- * @param string $path
- * @param string $name
- * @param array $headers
- * @return Response
- */
- public function download($path, $name = null, $headers = array())
- {
- if (is_null($name)) $name = basename($path);
-
- $headers = array_merge(array(
- 'Content-Description' => 'File Transfer',
- 'Content-Type' => $this->file->mime($this->file->extension($path)),
- 'Content-Disposition' => 'attachment; filename="'.$name.'"',
- 'Content-Transfer-Encoding' => 'binary',
- 'Expires' => 0,
- 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
- 'Pragma' => 'public',
- 'Content-Length' => $this->file-size($path),
- ), $headers);
-
- return new Response($this->file->get($path), 200, $headers);
- }
-
- /**
- * Magic Method for handling the dynamic creation of Responses containing named views.
- *
- *
- * // Create a Response instance with the "layout" named view
- * $response = Response::with_layout();
- *
- * // Create a Response instance with the "layout" named view and bound data
- * $response = Response::with_layout(array('name' => 'Fred'));
- *
- */
- public function __call($method, $parameters)
- {
- if (strpos($method, 'with_') === 0)
- {
- return $this->with(substr($method, 5), Arr::get($parameters, 0, array()));
- }
- }
-
-}
-
class Response {
/**
@@ -245,10 +87,118 @@ class Response {
*/
public function __construct($content, $status = 200, $headers = array())
{
+ $this->status = $status;
$this->content = $content;
$this->headers = $headers;
- $this->status = $status;
- }
+ }
+
+ /**
+ * Create a new response instance.
+ *
+ *
+ * // Create a response instance
+ * return Response::make('Hello World');
+ *
+ * // Create a response instance with a given status code
+ * return Response::make('Hello World', 200);
+ *
+ *
+ * @param mixed $content
+ * @param int $status
+ * @param array $headers
+ * @return Response
+ */
+ public static function make($content, $status = 200, $headers = array())
+ {
+ return new static($content, $status, $headers);
+ }
+
+ /**
+ * Create a new response instance containing a view.
+ *
+ *
+ * // Create a new response instance with view content
+ * return Response::view('home.index');
+ *
+ * // Create a new response instance with a view and bound data
+ * return Response::view('home.index', array('name' => 'Fred'));
+ *
+ *
+ * @param string $view
+ * @param array $data
+ * @return Response
+ */
+ public static function view($view, $data = array())
+ {
+ return new static(View::make($view, $data));
+ }
+
+ /**
+ * Create a new response instance containing a named view.
+ *
+ *
+ * // Create a new response instance with a named view
+ * return Response::with('layout');
+ *
+ * // Create a new response instance with a named view and bound data
+ * return Response::with('layout', array('name' => 'Fred'));
+ *
+ *
+ * @param string $name
+ * @param array $data
+ * @return Response
+ */
+ public static function with($name, $data = array())
+ {
+ return new static(View::of($name, $data));
+ }
+
+ /**
+ * Create a new error response instance.
+ *
+ * The response status code will be set using the specified code.
+ *
+ * Note: The specified error code should correspond to a view in your views/error directory.
+ *
+ *
+ * // Create an error response for status 500
+ * return Response::error('500');
+ *
+ *
+ * @param int $code
+ * @param array $data
+ * @return Response
+ */
+ public static function error($code, $data = array())
+ {
+ return new static(View::make('error/'.$code, $data), $code);
+ }
+
+ /**
+ * Create a new download response instance.
+ *
+ * @param string $path
+ * @param string $name
+ * @param array $headers
+ * @return Response
+ */
+ public static function download($path, $name = null, $headers = array())
+ {
+ if (is_null($name)) $name = basename($path);
+
+ $headers = array_merge(array(
+ 'Content-Description' => 'File Transfer',
+ 'Content-Type' => File::mime(File::extension($path)),
+ 'Content-Disposition' => 'attachment; filename="'.$name.'"',
+ 'Content-Transfer-Encoding' => 'binary',
+ 'Expires' => 0,
+ 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
+ 'Pragma' => 'public',
+ 'Content-Length' => File::size($path),
+ ), $headers);
+
+ return new static(File::get($path), 200, $headers);
+ }
/**
* Get the evaluated string contents of the response.
@@ -320,4 +270,23 @@ public function status($status)
return $this;
}
+ /**
+ * Magic Method for handling the dynamic creation of Responses containing named views.
+ *
+ *
+ * // Create a Response instance with the "layout" named view
+ * $response = Response::with_layout();
+ *
+ * // Create a Response instance with the "layout" named view and bound data
+ * $response = Response::with_layout(array('name' => 'Fred'));
+ *
+ */
+ public static function __callStatic($method, $parameters)
+ {
+ if (strpos($method, 'with_') === 0)
+ {
+ return static::with(substr($method, 5), Arr::get($parameters, 0, array()));
+ }
+ }
+
}
\ No newline at end of file
diff --git a/laravel/routing/router.php b/laravel/routing/router.php
index 616d5fed..40cd2095 100644
--- a/laravel/routing/router.php
+++ b/laravel/routing/router.php
@@ -69,22 +69,23 @@ public function find($name)
*
* If no route can be found, the application controllers will be searched.
*
- * @param Request $request
+ * @param string $method
+ * @param string $uri
* @return Route
*/
- public function route(Request $request)
+ public function route($method, $uri)
{
- $routes = $this->loader->load($request->uri());
+ $routes = $this->loader->load($uri);
// Put the request method and URI in route form. Routes begin with
// the request method and a forward slash.
- $destination = $request->method().' /'.trim($request->uri(), '/');
+ $destination = $method.' /'.trim($uri, '/');
// Check for a literal route match first. If we find one, there is
// no need to spin through all of the routes.
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)
@@ -100,13 +101,13 @@ public function route(Request $request)
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($request, $destination);
+ return Request::$route = $this->route_to_controller($method, $uri, $destination);
}
/**
@@ -114,17 +115,18 @@ public function route(Request $request)
*
* If no corresponding controller can be found, NULL will be returned.
*
- * @param Request $request
- * @param string $destination
+ * @param string $method
+ * @param string $uri
+ * @param string $destination
* @return Route
*/
- protected function route_to_controller(Request $request, $destination)
+ protected function route_to_controller($method, $uri, $destination)
{
// If the request is to the root of the application, an ad-hoc route will be generated
// to the home controller's "index" method, making it the default controller method.
- if ($request->uri() === '/') return new Route($request->method().' /', 'home@index');
+ if ($uri === '/') return new Route($method.' /', 'home@index');
- $segments = explode('/', trim($request->uri(), '/'));
+ $segments = explode('/', trim($uri, '/'));
if ( ! is_null($key = $this->controller_key($segments)))
{
diff --git a/laravel/security/auth.php b/laravel/security/auth.php
index 9db736df..b0e684dd 100644
--- a/laravel/security/auth.php
+++ b/laravel/security/auth.php
@@ -1,5 +1,6 @@
config = $config;
$this->session = $session;
}
@@ -59,7 +51,7 @@ public function user()
{
if ( ! is_null($this->user)) return $this->user;
- return $this->user = call_user_func($this->config->get('auth.user'), $this->session->get('laravel_user_id'));
+ return $this->user = call_user_func(Config::get('auth.user'), $this->session->get('laravel_user_id'));
}
/**
@@ -74,7 +66,7 @@ public function user()
*/
public function attempt($username, $password = null)
{
- if ( ! is_null($user = call_user_func($this->config->get('auth.attempt'), $username, $password)))
+ if ( ! is_null($user = call_user_func(Config::get('auth.attempt'), $username, $password)))
{
$this->remember($user);
@@ -106,7 +98,7 @@ public function remember($user)
*/
public function logout()
{
- call_user_func($this->config->get('auth.logout'), $this->user()->id);
+ call_user_func(Config::get('auth.logout'), $this->user()->id);
$this->user = null;
diff --git a/laravel/session/drivers/database.php b/laravel/session/drivers/database.php
index ec6b2ae9..0968539c 100644
--- a/laravel/session/drivers/database.php
+++ b/laravel/session/drivers/database.php
@@ -1,5 +1,6 @@
connection->table($this->config->get('session.table'));
+ return $this->connection->table(Config::get('session.table'));
}
}
\ No newline at end of file
diff --git a/laravel/session/drivers/file.php b/laravel/session/drivers/file.php
index dbf73a67..33669894 100644
--- a/laravel/session/drivers/file.php
+++ b/laravel/session/drivers/file.php
@@ -1,13 +1,8 @@
file = $file;
$this->path = $path;
}
@@ -39,7 +32,7 @@ public function __construct(\Laravel\File $file, $path)
*/
public function load($id)
{
- if ($this->file->exists($path = $this->path.$id)) return unserialize($this->file->get($path));
+ if (F::exists($path = $this->path.$id)) return unserialize(F::get($path));
}
/**
@@ -51,7 +44,7 @@ public function load($id)
*/
public function save($session, $config)
{
- $this->file->put($this->path.$session['id'], serialize($session), LOCK_EX);
+ F::put($this->path.$session['id'], serialize($session), LOCK_EX);
}
/**
@@ -62,7 +55,7 @@ public function save($session, $config)
*/
public function delete($id)
{
- $this->file->delete($this->path.$id);
+ F::delete($this->path.$id);
}
/**
@@ -75,9 +68,9 @@ public function sweep($expiration)
{
foreach (glob($this->path.'*') as $file)
{
- if ($this->file->type($file) == 'file' and $this->file->modified($file) < $expiration)
+ if (F::type($file) == 'file' and F::modified($file) < $expiration)
{
- $this->file->delete($file);
+ F::delete($file);
}
}
}
diff --git a/laravel/session/transporters/cookie.php b/laravel/session/transporters/cookie.php
index 1590b272..b1d5c9ad 100644
--- a/laravel/session/transporters/cookie.php
+++ b/laravel/session/transporters/cookie.php
@@ -1,17 +1,8 @@
cookie = $cookie;
- }
+class Cookie implements Transporter {
/**
* Get the session identifier for the request.
@@ -21,7 +12,7 @@ public function __construct(\Laravel\Cookie $cookie)
*/
public function get($config)
{
- return $this->cookie->get('laravel_session');
+ return C::get('laravel_session');
}
/**
@@ -35,7 +26,7 @@ public function put($id, $config)
{
$minutes = ($config['expire_on_close']) ? 0 : $config['lifetime'];
- $this->cookie->put('laravel_session', $id, $minutes, $config['path'], $config['domain']);
+ C::put('laravel_session', $id, $minutes, $config['path'], $config['domain']);
}
}
\ No newline at end of file
diff --git a/laravel/str.php b/laravel/str.php
index 4cc0fb59..f0945d61 100644
--- a/laravel/str.php
+++ b/laravel/str.php
@@ -74,7 +74,7 @@ public static function length($value)
*/
public static function ascii($value)
{
- $foreign = IoC::container()->resolve('laravel.config')->get('ascii');
+ $foreign = Config::get('ascii');
$value = preg_replace(array_keys($foreign), array_values($foreign), $value);
@@ -106,7 +106,7 @@ public static function random($length = 16, $type = 'alpha_num')
*/
protected static function encoding()
{
- return IoC::container()->resolve('laravel.config')->get('application.encoding');
+ return Config::get('application.encoding');
}
}
\ No newline at end of file
diff --git a/laravel/uri.php b/laravel/uri.php
index 6ec82420..59db01e0 100644
--- a/laravel/uri.php
+++ b/laravel/uri.php
@@ -2,20 +2,6 @@
class URI {
- /**
- * The $_SERVER array for the current request.
- *
- * @var array
- */
- protected $server;
-
- /**
- * The application URL as specified in the application configuration file.
- *
- * @var string
- */
- protected $url;
-
/**
* The URI for the current request.
*
@@ -23,36 +9,30 @@ class URI {
*
* @var string
*/
- protected $uri;
+ protected static $uri;
/**
- * Create a new URI instance.
+ * Determine the request URI.
*
- * @param array $server
- * @param string $url
- * @return void
- */
- public function __construct($server, $url)
- {
- $this->url = $url;
- $this->server = $server;
- }
-
- /**
- * Get the URI for the current request.
+ * The request URI will be trimmed to remove to the application URL and application index file.
+ * If the request is to the root of the application, the URI will be set to a forward slash.
+ *
+ * If the $_SERVER "PATH_INFO" variable is available, it will be used; otherwise, we will try
+ * to determine the URI using the REQUEST_URI variable. If neither are available, an exception
+ * will be thrown by the method.
*
* @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.');
}
- return $this->uri = $this->format($this->clean($uri));
+ return static::$uri = static::format(static::clean($uri));
}
/**
@@ -73,9 +53,9 @@ public function get()
* @param mixed $default
* @return string
*/
- public function segment($segment = null, $default = null)
+ public static function segment($segment = null, $default = null)
{
- $segments = Arr::without(explode('/', $this->detect()), array(''));
+ $segments = Arr::without(explode('/', static::get()), array(''));
if ( ! is_null($segment)) $segment = $segment - 1;
@@ -87,20 +67,20 @@ public function segment($segment = null, $default = null)
*
* @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
// 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
// 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.');
@@ -115,9 +95,9 @@ protected function from_server()
* @param string $uri
* @return string
*/
- protected function clean($uri)
+ protected static function clean($uri)
{
- foreach (array(parse_url($this->url, PHP_URL_PATH), '/index.php') as $value)
+ foreach (array(parse_url(Config::get('application.url'), PHP_URL_PATH), '/index.php') as $value)
{
$uri = (strpos($uri, $value) === 0) ? substr($uri, strlen($value)) : $uri;
}
@@ -133,7 +113,7 @@ protected function clean($uri)
* @param string $uri
* @return string
*/
- protected function format($uri)
+ protected static function format($uri)
{
return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
}
diff --git a/laravel/url.php b/laravel/url.php
index ff607aa0..36ce21bf 100644
--- a/laravel/url.php
+++ b/laravel/url.php
@@ -2,51 +2,6 @@
class URL {
- /**
- * The application router instance.
- *
- * @var Routing\Router
- */
- protected $router;
-
- /**
- * The base URL of the application.
- *
- * @var string
- */
- protected $base;
-
- /**
- * The application index file.
- *
- * @var string
- */
- protected $index;
-
- /**
- * Indicates if the current request is using HTTPS.
- *
- * @var bool
- */
- protected $https;
-
- /**
- * Create a new URL writer instance.
- *
- * @param Routing\Router $router
- * @param string $base
- * @param string $index
- * @param bool $https
- * @return void
- */
- public function __construct(Routing\Router $router, $base, $index, $https)
- {
- $this->base = $base;
- $this->https = $https;
- $this->index = $index;
- $this->router = $router;
- }
-
/**
* Generate an application URL.
*
@@ -64,11 +19,11 @@ public function __construct(Routing\Router $router, $base, $index, $https)
* @param bool $https
* @return string
*/
- public function to($url = '', $https = false)
+ public static function to($url = '', $https = false)
{
if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url;
- $base = $this->base.'/'.$this->index;
+ $base = Config::get('application.url').'/'.Config::get('application.index');
if ($https) $base = preg_replace('~http://~', 'https://', $base, 1);
@@ -86,9 +41,9 @@ public function to($url = '', $https = false)
* @param string $url
* @return string
*/
- public function to_secure($url = '')
+ public static function to_secure($url = '')
{
- return $this->to($url, true);
+ return static::to($url, true);
}
/**
@@ -109,11 +64,11 @@ public function to_secure($url = '')
* @param bool $https
* @return string
*/
- public function to_asset($url, $https = null)
+ public static function to_asset($url, $https = null)
{
- if (is_null($https)) $https = $this->https;
+ if (is_null($https)) $https = Request::secure();
- return str_replace('index.php/', '', $this->to($url, $https));
+ return str_replace('index.php/', '', static::to($url, $https));
}
/**
@@ -133,14 +88,14 @@ public function to_asset($url, $https = null)
* echo URL::to_route('profile', array($username));
*
*
- * @param string $name
- * @param array $parameters
- * @param bool $https
+ * @param string $name
+ * @param array $parameters
+ * @param bool $https
* @return string
*/
- public function to_route($name, $parameters = array(), $https = false)
+ public static function to_route($name, $parameters = array(), $https = false)
{
- if ( ! is_null($route = $this->router->find($name)))
+ if ( ! is_null($route = IoC::container()->resolve('laravel.routing.router')->find($name)))
{
$uris = explode(', ', key($route));
@@ -155,7 +110,7 @@ public function to_route($name, $parameters = array(), $https = false)
// Before generating the route URL, we will replace all remaining optional
// wildcard segments that were not replaced by parameters with spaces.
- return $this->to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https);
+ return static::to(str_replace(array('/(:any?)', '/(:num?)'), '', $uri), $https);
}
throw new \Exception("Error generating named route for route [$name]. Route is not defined.");
@@ -176,9 +131,9 @@ public function to_route($name, $parameters = array(), $https = false)
* @param array $parameters
* @return string
*/
- public function to_secure_route($name, $parameters = array())
+ public static function to_secure_route($name, $parameters = array())
{
- return $this->to_route($name, $parameters, true);
+ return static::to_route($name, $parameters, true);
}
/**
@@ -188,7 +143,7 @@ public function to_secure_route($name, $parameters = array())
* @param string $separator
* @return string
*/
- public function slug($title, $separator = '-')
+ public static function slug($title, $separator = '-')
{
$title = Str::ascii($title);
@@ -215,18 +170,18 @@ public function slug($title, $separator = '-')
* echo URL::to_secure_profile();
*
*/
- public function __call($method, $parameters)
+ public static function __callStatic($method, $parameters)
{
$parameters = (isset($parameters[0])) ? $parameters[0] : array();
if (strpos($method, 'to_secure_') === 0)
{
- return $this->to_route(substr($method, 10), $parameters, true);
+ return static::to_route(substr($method, 10), $parameters, true);
}
if (strpos($method, 'to_') === 0)
{
- return $this->to_route(substr($method, 3), $parameters);
+ return static::to_route(substr($method, 3), $parameters);
}
throw new \Exception("Method [$method] is not defined on the URL class.");
diff --git a/laravel/validation/validator.php b/laravel/validation/validator.php
index 2b21f335..1b84dca3 100644
--- a/laravel/validation/validator.php
+++ b/laravel/validation/validator.php
@@ -3,74 +3,10 @@
use Closure;
use Laravel\IoC;
use Laravel\Str;
-use Laravel\Lang_Factory;
-
-class Validator_Factory {
-
- /**
- * The language factory instance.
- *
- * @var Lang_Factory
- */
- protected $lang;
-
- /**
- * The registered custom validators.
- *
- * @var array
- */
- protected $validators = array();
-
- /**
- * Create a new validator factory instance.
- *
- * @param Lang_Factory $lang
- * @return void
- */
- public function __construct(Lang_Factory $lang)
- {
- $this->lang = $lang;
- }
-
- /**
- * Create a new validator instance.
- *
- * @param array $attributes
- * @param array $rules
- * @param array $messages
- * @return Validator
- */
- public function make($attributes, $rules, $messages = array())
- {
- return new Validator($this->lang, $this->validators, $attributes, $rules, $messages);
- }
-
- /**
- * Register a custom validation callback.
- *
- * @param string $name
- * @param string $message
- * @param Closure $closure
- * @return Validator
- */
- public function register($name, $message, Closure $closure)
- {
- $this->validators[$name] = compact('message', 'closure');
-
- return $this;
- }
-
-}
+use Laravel\Lang;
class Validator {
- /**
- * The registered custom validators.
- *
- * @var array
- */
- protected $validators = array();
-
/**
* The validation rules.
*
@@ -130,36 +66,36 @@ class Validator {
/**
* Create a new validator instance.
*
- * @param Lang_Factory $lang
- * @param array $validators
- * @param array $attributes
- * @param array $rules
- * @param array $messages
+ * @param array $attributes
+ * @param array $rules
+ * @param array $messages
* @return void
*/
- public function __construct(Lang_Factory $lang, $validators, $attributes, $rules, $messages = array())
+ public function __construct($attributes, $rules, $messages = array())
{
foreach ($rules as $key => &$rule)
{
$rule = (is_string($rule)) ? explode('|', $rule) : $rule;
}
- // Register all of the custom validators and their corresponding error messages.
- // The validators are executed via the magic __call method. The validator names
- // are prefixed with "validate_" to match the built-in validators.
- foreach ($validators as $key => $value)
- {
- $this->messages[$key] = $value['message'];
-
- $this->validators['validate_'.$key] = $value['closure'];
- }
-
- $this->lang = $lang;
$this->rules = $rules;
$this->attributes = $attributes;
$this->messages = array_merge($this->messages, $messages);
}
+ /**
+ * Create a new validator instance.
+ *
+ * @param array $attributes
+ * @param array $rules
+ * @param array $messages
+ * @return Validator
+ */
+ public static function make($attributes, $rules, $messages = array())
+ {
+ return new static($attributes, $rules, $messages);
+ }
+
/**
* Validate the target array using the specified validation rules.
*
@@ -201,7 +137,7 @@ protected function check($attribute, $rule)
{
list($rule, $parameters) = $this->parse($rule);
- if ( ! method_exists($this, $validator = 'validate_'.$rule) and ! isset($this->validators[$validator]))
+ if ( ! method_exists($this, $validator = 'validate_'.$rule))
{
throw new \Exception("Validation rule [$rule] doesn't exist.");
}
@@ -516,15 +452,15 @@ protected function get_message($attribute, $rule)
}
else
{
- $message = $this->lang->line('validation.'.$rule)->get($this->language);
+ $message = Lang::line('validation.'.$rule)->get($this->language);
// For "size" rules that are validating strings or files, we need to adjust
// the default error message for the appropriate units.
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')->files()))
- ? rtrim($message, '.').' '.$this->lang->line('validation.kilobytes')->get($this->language).'.'
- : rtrim($message, '.').' '.$this->lang->line('validation.characters')->get($this->language).'.';
+ ? rtrim($message, '.').' '.Lang::line('validation.kilobytes')->get($this->language).'.'
+ : rtrim($message, '.').' '.Lang::line('validation.characters')->get($this->language).'.';
}
return $message;
@@ -542,7 +478,7 @@ protected function get_message($attribute, $rule)
*/
protected function format_message($message, $attribute, $rule, $parameters)
{
- $display = $this->lang->line('attributes.'.$attribute)->get($this->language, str_replace('_', ' ', $attribute));
+ $display = Lang::line('attributes.'.$attribute)->get($this->language, str_replace('_', ' ', $attribute));
$message = str_replace(':attribute', $display, $message);
@@ -616,12 +552,4 @@ public function connection(Database\Connection $connection)
return $this;
}
- /**
- * Magic Method for calling custom registered validators.
- */
- public function __call($method, $parameters)
- {
- return call_user_func_array($this->validators[$method], $parameters);
- }
-
}
\ No newline at end of file
diff --git a/laravel/view.php b/laravel/view.php
index d2934de2..752c7ce6 100644
--- a/laravel/view.php
+++ b/laravel/view.php
@@ -1,199 +1,5 @@
composer = $composer;
- $this->path = $path;
- }
-
- /**
- * 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.
- *
- *
- * // 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' => 'Fred'));
- *
- *
- * @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.
- *
- *
- * // Create a new named view instance
- * $view = View::of('layout');
- *
- * // Create a new named view instance with bound data
- * $view = View::of('layout', array('name' => 'Fred'));
- *
- *
- * @param string $name
- * @param array $data
- * @return View
- */
- protected 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);
-
- if (file_exists($path = $this->path.$view.'.blade'.EXT))
- {
- return $path;
- }
- elseif (file_exists($path = $this->path.$view.EXT))
- {
- return $path;
- }
-
- throw new \Exception('View ['.$view.'] does not exist.');
- }
-
- /**
- * Magic Method for handling the dynamic creation of named views.
- *
- *
- * // Create an instance of the "layout" named view
- * $view = View::of_layout();
- *
- * // Create an instance of the "layout" named view with bound data
- * $view = View::of_layout(array('name' => 'Fred'));
- *
- */
- public function __call($method, $parameters)
- {
- if (strpos($method, 'of_') === 0)
- {
- return $this->of(substr($method, 3), Arr::get($parameters, 0, array()));
- }
- }
-
-}
-
-/**
- * The view composer class is responsible for calling the composer on a view and
- * searching through the view composers for a given view name. It is injected
- * into the View_Factory and View instances themselves, and is managed as a singleton
- * by the application IoC container.
- */
-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.
- *
- * @param string $name
- * @return string
- */
- public function name($name)
- {
- 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)
- {
- 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);
- }
- }
- }
-
-}
-
-/**
- * The view class is returned by the View Factory "make" method, and is the primary
- * class for working with individual views. It provides methods for binding data to
- * views as well as evaluating and rendering their contents.
- */
class View {
/**
@@ -218,36 +24,78 @@ class View {
protected $path;
/**
- * The view composer instance.
+ * Create a new view instance.
*
- * @var View_Composer
+ * @param string $view
+ * @param array $data
+ * @return void
*/
- protected $composer;
-
- /**
- * The view factory instance, which is used to create sub-views.
- *
- * @var View_Factory
- */
- protected $factory;
+ protected function __construct($view, $data = array())
+ {
+ $this->view = $view;
+ $this->data = $data;
+ $this->path = $this->path($view);
+ }
/**
* Create a new view instance.
*
- * @param View_Factory $factory
- * @param View_Composer $composer
* @param string $view
* @param array $data
- * @param string $path
- * @return void
+ * @return View
*/
- public function __construct(View_Factory $factory, View_Composer $composer, $view, $data, $path)
+ public static function make($view, $data = array())
{
- $this->view = $view;
- $this->data = $data;
- $this->path = $path;
- $this->factory = $factory;
- $this->composer = $composer;
+ return new static($view, $data);
+ }
+
+ /**
+ * Create a new view instance from a view name.
+ *
+ * View names are defined in the application composers file.
+ *
+ *
+ * // Create a new named view instance
+ * $view = View::of('layout');
+ *
+ * // Create a new named view instance with bound data
+ * $view = View::of('layout', array('name' => 'Fred'));
+ *
+ *
+ * @param string $name
+ * @param array $data
+ * @return View
+ */
+ public static function of($name, $data = array())
+ {
+ if ( ! is_null($view = Composer::name($name)))
+ {
+ return new static($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);
+
+ if (file_exists($path = VIEW_PATH.$view.'.blade'.EXT))
+ {
+ return $path;
+ }
+ elseif (file_exists($path = VIEW_PATH.$view.EXT))
+ {
+ return $path;
+ }
+
+ throw new \Exception('View ['.$view.'] does not exist.');
}
/**
@@ -260,7 +108,7 @@ public function __construct(View_Factory $factory, View_Composer $composer, $vie
*/
public function render()
{
- $this->composer->compose($this);
+ Composer::compose($this);
foreach ($this->data as &$data)
{
@@ -304,7 +152,7 @@ protected function bladed()
*/
public function partial($key, $view, $data = array())
{
- return $this->with($key, $this->factory->make($view, $data));
+ return $this->with($key, new static($view, $data));
}
/**
@@ -359,4 +207,76 @@ public function __unset($key)
unset($this->data[$key]);
}
-}
\ No newline at end of file
+ /**
+ * Magic Method for handling the dynamic creation of named views.
+ *
+ *
+ * // Create an instance of the "layout" named view
+ * $view = View::of_layout();
+ *
+ * // Create an instance of the "layout" named view with bound data
+ * $view = View::of_layout(array('name' => 'Fred'));
+ *
+ */
+ public static function __callStatic($method, $parameters)
+ {
+ if (strpos($method, 'of_') === 0)
+ {
+ return static::of(substr($method, 3), Arr::get($parameters, 0, array()));
+ }
+ }
+
+}
+
+/**
+ * The view composer class is responsible for calling the composer on a view and
+ * searching through the view composers for a given view name.
+ */
+class Composer {
+
+ /**
+ * The view composers.
+ *
+ * @var array
+ */
+ public static $composers;
+
+ /**
+ * Find the key for a view by name.
+ *
+ * @param string $name
+ * @return string
+ */
+ public static function name($name)
+ {
+ 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
+ */
+ public static function compose(View $view)
+ {
+ 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);
+ }
+ }
+ }
+
+}
+
+/**
+ * Load the application's composers into the composers property.
+ */
+Composer::$composers = require APP_PATH.'composers'.EXT;
\ No newline at end of file
diff --git a/public/index.php b/public/index.php
index 44e94ffe..7c03c0d8 100644
--- a/public/index.php
+++ b/public/index.php
@@ -43,4 +43,6 @@
| 3... 2... 1... Lift-off!
|--------------------------------------------------------------------------
*/
-require $laravel.'/laravel.php';
\ No newline at end of file
+require $laravel.'/laravel.php';
+
+echo number_format((microtime(true) - START_TIME) * 1000, 2);
\ No newline at end of file