Commit 4525eae2 authored by Taylor Otwell's avatar Taylor Otwell

revert back to more sensible architecture.

parent 47db2ff1
......@@ -19,36 +19,35 @@ return array(
*/
'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
......@@ -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 @@ class Asset {
* @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 @@ class Asset {
* echo Asset::styles();
* </code>
*/
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 @@ class Asset_Container {
$asset = $this->assets[$group][$name];
return $this->html->$group($asset['source'], $asset['attributes']);
return HTML::$group($asset['source'], $asset['attributes']);
}
/**
......
<?php namespace Laravel\Cache\Drivers;
class APC_Engine {
/**
* Retrieve an item from the APC cache.
*
* @param string $key
* @return mixed
*/
public function fetch($key)
{
return apc_fetch($key);
}
/**
* Store an item in the APC cache.
*
* @param string $key
* @param mixed $value
* @param int $seconds
* @return void
*/
public function store($key, $value, $seconds)
{
apc_store($key, $value, $seconds);
}
/**
* Delete an item from the APC cache.
*
* @param string $key
* @return void
*/
public function delete($key)
{
apc_delete($key);
}
}
class APC extends Driver {
/**
* The APC engine instance.
*
* @var APC_Engine
*/
private $apc;
/**
* The cache key from the cache configuration file.
*
......@@ -58,13 +12,11 @@ class APC extends Driver {
/**
* Create a new APC cache driver instance.
*
* @param APC_Engine $apc
* @param string $key
* @return void
*/
public function __construct(APC_Engine $apc, $key)
public function __construct($key)
{
$this->apc = $apc;
$this->key = $key;
}
......@@ -87,7 +39,7 @@ class APC extends Driver {
*/
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 @@ class APC extends Driver {
*/
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 @@ class APC extends Driver {
*/
public function forget($key)
{
$this->apc->delete($this->key.$key);
apc_delete($this->key.$key);
}
}
\ No newline at end of file
<?php namespace Laravel\Cache\Drivers;
class File extends Driver {
use Laravel\File as F;
/**
* The file engine instance.
*
* @var Laravel\File
*/
private $file;
class File extends Driver {
/**
* The path to which the cache files should be written.
......@@ -19,13 +14,11 @@ class File extends Driver {
/**
* Create a new File cache driver instance.
*
* @param Laravel\File $file
* @param string $path
* @return void
*/
public function __construct(\Laravel\File $file, $path)
public function __construct($path)
{
$this->file = $file;
$this->path = $path;
}
......@@ -48,9 +41,9 @@ class File extends Driver {
*/
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 @@ class File extends Driver {
*/
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 @@ class File extends Driver {
*/
public function forget($key)
{
$this->file->delete($this->path.$key);
F::delete($this->path.$key);
}
}
\ No newline at end of file
......@@ -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 @@ class Config {
* @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 @@ class Config {
* @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 @@ class Config {
* @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 @@ class Config {
* @param string $key
* @return array
*/
protected function parse($key)
protected static function parse($key)
{
$segments = explode('.', $key);
......@@ -164,13 +164,13 @@ class Config {
* @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 @@ class Config {
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
......@@ -8,64 +8,15 @@ return array(
|--------------------------------------------------------------------------
*/
'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 array(
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 @@ return array(
'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 @@ return array(
{
$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 @@ return array(
'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 @@ return array(
'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);
}),
......
......@@ -21,7 +21,7 @@ abstract class Controller {
*/
public function __call($method, $parameters)
{
return IoC::container()->resolve('laravel.response')->error('404');
return Response::error('404');
}
/**
......
......@@ -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 @@ class Cookie {
* @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 @@ class Cookie {
* @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 @@ class Cookie {
* @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 @@ class Cookie {
* @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 @@ class Cookie {
*
* @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 @@ class Cookie {
* @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
......@@ -36,50 +36,50 @@ define('VIEW_PATH', APP_PATH.'views/');
// --------------------------------------------------------------
require SYS_PATH.'facades'.EXT;
require SYS_PATH.'config'.EXT;
require SYS_PATH.'loader'.EXT;
require SYS_PATH.'arr'.EXT;
// --------------------------------------------------------------
// Bootstrap the IoC container.
// Determine the application environment.
// --------------------------------------------------------------
require SYS_PATH.'container'.EXT;
$environment = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : null;
$dependencies = require SYS_CONFIG_PATH.'container'.EXT;
// --------------------------------------------------------------
// Register the configuration file paths.
// --------------------------------------------------------------
$config = array(SYS_CONFIG_PATH, CONFIG_PATH);
if (file_exists($path = CONFIG_PATH.'container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
if ( ! is_null($environment)) $config[] = CONFIG_PATH.$environment.'/';
$env = (isset($_SERVER['LARAVEL_ENV'])) ? $_SERVER['LARAVEL_ENV'] : null;
Config::paths($config);
if ( ! is_null($env) and file_exists($path = CONFIG_PATH.$env.'/container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
// --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
require SYS_PATH.'container'.EXT;
$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
......@@ -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 @@ class Manager {
* @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 @@ class Manager {
* @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 @@ class Manager {
* @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 @@ class Manager {
*
* 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
......@@ -32,27 +32,9 @@ abstract class Facade {
}
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'; }
\ No newline at end of file
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
<?php namespace Laravel;
/**
* While this class may appear totally useless. It is actually quite helpful for dealing with
* the global scope of the PHP file functions. Injecting this class into the classes that need
* access to these functions allows us to test the classes without hitting the actual file system.
*/
class File {
/**
* All of the MIME types understood by the manager.
*
* @var array
*/
private $mimes;
/**
* Create a new file engine instance.
*
* @param array $mimes
* @return void
*/
public function __construct($mimes)
{
$this->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 @@ class File {
* @param string $path
* @return string
*/
public function get($path)
public static function get($path)
{
return file_get_contents($path);
}
......@@ -54,7 +31,7 @@ class File {
* @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 @@ class File {
* @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 @@ class File {
* @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 @@ class File {
* @param string $path
* @return string
*/
public function extension($path)
public static function extension($path)
{
return pathinfo($path, PATHINFO_EXTENSION);
}
......@@ -99,7 +76,7 @@ class File {
* @param string $path
* @return string
*/
public function type($path)
public static function type($path)
{
return filetype($path);
}
......@@ -110,7 +87,7 @@ class File {
* @param string $file
* @return int
*/
public function size($path)
public static function size($path)
{
return filesize($path);
}
......@@ -121,7 +98,7 @@ class File {
* @param string $path
* @return int
*/
public function modified($path)
public static function modified($path)
{
return filemtime($path);
}
......@@ -134,7 +111,7 @@ class File {
* @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 @@ class File {
* @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');
if ( ! array_key_exists($extension, $mimes)) return $default;
return (is_array($this->mimes[$extension])) ? $this->mimes[$extension][0] : $this->mimes[$extension];
return (is_array($mimes[$extension])) ? $mimes[$extension][0] : $mimes[$extension];
}
/**
......@@ -177,13 +156,15 @@ class File {
* @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;
......
......@@ -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 @@ class Form {
* @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 '<form'.$this->html->attributes($attributes).'>'.$append.PHP_EOL;
return '<form'.HTML::attributes($attributes).'>'.$append.PHP_EOL;
}
/**
......@@ -95,7 +59,7 @@ class Form {
* @param string $method
* @return string
*/
protected function method($method)
protected static function method($method)
{
return strtoupper(($method == 'PUT' or $method == 'DELETE') ? 'POST' : $method);
}
......@@ -109,9 +73,9 @@ class Form {
* @param bool $https
* @return string
*/
protected function action($action, $https)
protected static function action($action, $https)
{
return $this->html->entities($this->url->to(((is_null($action)) ? $this->request->uri() : $action), $https));
return HTML::entities(URL::to(((is_null($action)) ? Request::uri() : $action), $https));
}
/**
......@@ -122,9 +86,9 @@ class Form {
* @param array $attributes
* @return string
*/
public function open_secure($action = null, $method = 'POST', $attributes = array())
public static function open_secure($action = null, $method = 'POST', $attributes = array())
{
return $this->open($action, $method, $attributes, true);
return static::open($action, $method, $attributes, true);
}
/**
......@@ -136,11 +100,11 @@ class Form {
* @param bool $https
* @return string
*/
public function open_for_files($action = null, $method = 'POST', $attributes = array(), $https = false)
public static function open_for_files($action = null, $method = 'POST', $attributes = array(), $https = false)
{
$attributes['enctype'] = 'multipart/form-data';
return $this->open($action, $method, $attributes, $https);
return static::open($action, $method, $attributes, $https);
}
/**
......@@ -151,9 +115,9 @@ class Form {
* @param array $attributes
* @return string
*/
public function open_secure_for_files($action = null, $method = 'POST', $attributes = array())
public static function open_secure_for_files($action = null, $method = 'POST', $attributes = array())
{
return $this->open_for_files($action, $method, $attributes, true);
return static::open_for_files($action, $method, $attributes, true);
}
/**
......@@ -161,7 +125,7 @@ class Form {
*
* @return string
*/
public function close()
public static function close()
{
return '</form>';
}
......@@ -171,9 +135,9 @@ class Form {
*
* @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 @@ class Form {
*
* @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 @@ class Form {
* @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 '<label for="'.$name.'"'.$this->html->attributes($attributes).'>'.$this->html->entities($value).'</label>'.PHP_EOL;
return '<label for="'.$name.'"'.HTML::attributes($attributes).'>'.HTML::entities($value).'</label>'.PHP_EOL;
}
/**
......@@ -236,13 +200,13 @@ class Form {
* @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 '<input'.$this->html->attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.PHP_EOL;
return '<input'.HTML::attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.PHP_EOL;
}
/**
......@@ -253,9 +217,9 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 '<textarea'.$this->html->attributes($attributes).'>'.$this->html->entities($value).'</textarea>'.PHP_EOL;
return '<textarea'.HTML::attributes($attributes).'>'.HTML::entities($value).'</textarea>'.PHP_EOL;
}
/**
......@@ -404,20 +368,20 @@ class Form {
* @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[] = '<option'.$this->html->attributes($option_attributes).'>'.$this->html->entities($display).'</option>';
$html[] = '<option'.HTML::attributes($option_attributes).'>'.HTML::entities($display).'</option>';
}
return '<select'.$this->html->attributes($attributes).'>'.implode('', $html).'</select>'.PHP_EOL;
return '<select'.HTML::attributes($attributes).'>'.implode('', $html).'</select>'.PHP_EOL;
}
/**
......@@ -437,9 +401,9 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @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 @@ class Form {
* @param array $attributes
* @return string
*/
public function button($value, $attributes = array())
public static function button($value, $attributes = array())
{
return '<button'.$this->html->attributes($attributes).'>'.$this->html->entities($value).'</button>'.PHP_EOL;
return '<button'.HTML::attributes($attributes).'>'.HTML::entities($value).'</button>'.PHP_EOL;
}
/**
......@@ -565,11 +529,11 @@ class Form {
* @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
......@@ -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 @@ class HTML {
* @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 @@ class HTML {
* @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 '<script type="text/javascript" src="'.$url.'"'.$this->attributes($attributes).'></script>'.PHP_EOL;
return '<script type="text/javascript" src="'.$url.'"'.static::attributes($attributes).'></script>'.PHP_EOL;
}
/**
......@@ -80,13 +54,13 @@ class HTML {
* @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 '<link href="'.$this->entities($this->url->to_asset($url)).'"'.$this->attributes($attributes).'>'.PHP_EOL;
return '<link href="'.static::entities(URL::to_asset($url)).'"'.static::attributes($attributes).'>'.PHP_EOL;
}
/**
......@@ -104,9 +78,9 @@ class HTML {
* @param array $attributes
* @return string
*/
public function span($value, $attributes = array())
public static function span($value, $attributes = array())
{
return '<span'.$this->attributes($attributes).'>'.$this->entities($value).'</span>';
return '<span'.static::attributes($attributes).'>'.static::entities($value).'</span>';
}
/**
......@@ -127,11 +101,11 @@ class HTML {
* @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 '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
return '<a href="'.$url.'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
}
/**
......@@ -142,9 +116,9 @@ class HTML {
* @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 @@ class HTML {
* @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 @@ class HTML {
* @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 @@ class HTML {
* @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 @@ class HTML {
* @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 @@ class HTML {
* @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 = '&#109;&#097;&#105;&#108;&#116;&#111;&#058;'.$email;
return '<a href="'.$email.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';
return '<a href="'.$email.'"'.static::attributes($attributes).'>'.static::entities($title).'</a>';
}
/**
......@@ -252,9 +226,9 @@ class HTML {
* @param string $email
* @return string
*/
public function email($email)
public static function email($email)
{
return str_replace('@', '&#64;', $this->obfuscate($email));
return str_replace('@', '&#64;', static::obfuscate($email));
}
/**
......@@ -276,11 +250,11 @@ class HTML {
* @param array $attributes
* @return string
*/
public function image($url, $alt = '', $attributes = array())
public static function image($url, $alt = '', $attributes = array())
{
$attributes['alt'] = $alt;
return '<img src="'.$this->entities($this->url->to_asset($url)).'"'.$this->attributes($attributes).'>';
return '<img src="'.static::entities(URL::to_asset($url)).'"'.static::attributes($attributes).'>';
}
/**
......@@ -298,9 +272,9 @@ class HTML {
* @param array $attributes
* @return string
*/
public function ol($list, $attributes = array())
public static function ol($list, $attributes = array())
{
return $this->list_elements('ol', $list, $attributes);
return static::list_elements('ol', $list, $attributes);
}
/**
......@@ -318,9 +292,9 @@ class HTML {
* @param array $attributes
* @return string
*/
public function ul($list, $attributes = array())
public static function ul($list, $attributes = array())
{
return $this->list_elements('ul', $list, $attributes);
return static::list_elements('ul', $list, $attributes);
}
/**
......@@ -331,16 +305,16 @@ class HTML {
* @param array $attributes
* @return string
*/
private function list_elements($type, $list, $attributes = array())
private static function list_elements($type, $list, $attributes = array())
{
$html = '';
foreach ($list as $key => $value)
{
$html .= (is_array($value)) ? $this->list_elements($type, $value) : '<li>'.$this->entities($value).'</li>';
$html .= (is_array($value)) ? static::list_elements($type, $value) : '<li>'.static::entities($value).'</li>';
}
return '<'.$type.$this->attributes($attributes).'>'.$html.'</'.$type.'>';
return '<'.$type.static::attributes($attributes).'>'.$html.'</'.$type.'>';
}
/**
......@@ -349,7 +323,7 @@ class HTML {
* @param array $attributes
* @return string
*/
public function attributes($attributes)
public static function attributes($attributes)
{
$html = array();
......@@ -361,7 +335,7 @@ class HTML {
if ( ! is_null($value))
{
$html[] = $key.'="'.$this->entities($value).'"';
$html[] = $key.'="'.static::entities($value).'"';
}
}
......@@ -374,7 +348,7 @@ class HTML {
* @param string $value
* @return string
*/
public function obfuscate($value)
public static function obfuscate($value)
{
$safe = '';
......@@ -420,20 +394,20 @@ class HTML {
* echo HTML::link_to_secure_posts('Posts', array($year, $month));
* </code>
*/
public function __call($method, $parameters)
public static function __callStatic($method, $parameters)
{
if (strpos($method, 'link_to_secure_') === 0)
{
array_unshift($parameters, substr($method, 15));
return call_user_func_array(array($this, 'link_to_secure_route'), $parameters);
return forward_static_call_array('HTML::link_to_secure_route', $parameters);
}
if (strpos($method, 'link_to_') === 0)
{
array_unshift($parameters, substr($method, 8));
return call_user_func_array(array($this, 'link_to_route'), $parameters);
return forward_static_call_array('HTML::link_to_route', $parameters);
}
throw new \Exception("Method [$method] is not defined on the HTML class.");
......
......@@ -2,50 +2,12 @@
class Input {
/**
* The file manager instance.
*
* @var File
*/
protected $file;
/**
* The applicable input for the request.
*
* @var array
*/
protected $input;
/**
* The $_FILES array for the request.
*
* @var array
*/
protected $files;
/**
* The cookie engine instance.
*
* @var Cookie
*/
public $cookies;
/**
* Create a new Input manager instance.
*
* @param File $file
* @param Cookie $cookies
* @param array $input
* @param array $files
* @return void
*/
public function __construct(File $file, Cookie $cookies, $input, $files)
{
$this->file = $file;
$this->input = $input;
$this->files = $files;
$this->cookies = $cookies;
}
public static $input;
/**
* Get all of the input data for the request.
......@@ -54,9 +16,9 @@ class Input {
*
* @return array
*/
public function all()
public static function all()
{
return array_merge($this->get(), $this->file());
return array_merge(static::get(), static::file());
}
/**
......@@ -65,9 +27,9 @@ class Input {
* @param string $key
* @return bool
*/
public function has($key)
public static function has($key)
{
return ( ! is_null($this->get($key)) and trim((string) $this->get($key)) !== '');
return ( ! is_null(static::get($key)) and trim((string) static::get($key)) !== '');
}
/**
......@@ -87,9 +49,9 @@ class Input {
* @param mixed $default
* @return mixed
*/
public function get($key = null, $default = null)
public static function get($key = null, $default = null)
{
return Arr::get($this->input, $key, $default);
return Arr::get(static::$input, $key, $default);
}
/**
......@@ -98,9 +60,9 @@ class Input {
* @param string $key
* @return bool
*/
public function had($key)
public static function had($key)
{
return ( ! is_null($this->old($key)) and trim((string) $this->old($key)) !== '');
return ( ! is_null(static::old($key)) and trim((string) static::old($key)) !== '');
}
/**
......@@ -118,9 +80,9 @@ class Input {
* @param mixed $default
* @return string
*/
public function old($key = null, $default = null)
public static function old($key = null, $default = null)
{
if (IoC::container()->resolve('laravel.config')->get('session.driver') == '')
if (Config::get('session.driver') == '')
{
throw new \Exception('A session driver must be specified in order to access old input.');
}
......@@ -147,9 +109,9 @@ class Input {
* @param mixed $default
* @return array
*/
public function file($key = null, $default = null)
public static function file($key = null, $default = null)
{
return Arr::get($this->files, $key, $default);
return Arr::get($_FILES, $key, $default);
}
/**
......@@ -166,25 +128,40 @@ class Input {
* @param string $path
* @return bool
*/
public function upload($key, $path)
public static function upload($key, $path)
{
return array_key_exists($key, $this->files) ? $this->file->upload($key, $path, $this->files) : false;
return array_key_exists($key, $_FILES) ? File::upload($key, $path, $_FILES) : false;
}
/**
* Magic Method for retrieving items from the request input.
*
* This method is particularly helpful in controllers where access to the IoC container
* is provided through the controller's magic __get method.
*
* <code>
* // Retrieve the "name" input item from a controller method
* $name = $this->input->name;
* </code>
}
/**
* Set the input values for the current request.
*/
public function __get($key)
$input = array();
switch (Request::method())
{
case 'GET':
$input = $_GET;
break;
case 'POST':
$input = $_POST;
break;
case 'PUT':
case 'DELETE':
if (Request::spoofed())
{
return $this->get($key);
$input = $_POST;
}
else
{
parse_str(file_get_contents('php://input'), $input);
}
}
unset($input[Request::spoofer]);
Input::$input = $input;
\ No newline at end of file
<?php namespace Laravel;
class Lang_Factory {
/**
* The configuration manager instance.
*
* @var Config
*/
protected $config;
/**
* The paths containing the language files.
*
* @var array
*/
protected $paths;
/**
* Create a new language factory instance.
*
* Note: The entire configuration manager is used in case the default language
* is changed during the course of a request to the application.
*
* @param Config $config
* @param array $paths
* @return void
*/
public function __construct(Config $config, $paths)
{
$this->paths = $paths;
$this->config = $config;
}
/**
* Begin retrieving a language line.
*
* <code>
* // 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');
* </code>
*
* @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 @@ class Lang {
$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))
{
......
......@@ -8,27 +8,25 @@ require 'core.php';
// --------------------------------------------------------------
// 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 @@ ini_set('display_errors', 'Off');
// --------------------------------------------------------------
// 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 @@ if ( ! is_null($route))
}
else
{
$response = $container->resolve('laravel.response')->error('404');
$response = Response::error('404');
}
// --------------------------------------------------------------
......@@ -78,13 +76,13 @@ $response->content = $response->render();
// --------------------------------------------------------------
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.
......
......@@ -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 @@ class Loader {
* @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 @@ class Loader {
// 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 @@ class Loader {
* @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 @@ class Loader {
* @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 @@ class Loader {
* @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
<?php namespace Laravel;
class Paginator_Factory {
protected $request;
protected $html;
protected $lang;
public function __construct(Request $request, HTML $html, Lang_Factory $lang)
{
$this->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 '<div class="pagination">'.$this->previous().$numbers.$this->next().'</div>';
}
/**
* Build sliding list of HTML numeric page links.
*
* @param int $adjacent
* @return string
*/
private function slider($adjacent)
{
if ($this->page <= $adjacent * 2)
{
return $this->range(1, 2 + ($adjacent * 2)).$this->ending();
}
elseif ($this->page >= $this->last_page - ($adjacent * 2))
{
return $this->beginning().$this->range($this->last_page - 2 - ($adjacent * 2), $this->last_page);
}
else
{
return $this->beginning().$this->range($this->page - $adjacent, $this->page + $adjacent).$this->ending();
}
}
/**
* Generate the "previous" HTML link.
*
* @return string
*/
public function previous()
{
$text = Lang::line('pagination.previous')->get($this->language);
if ($this->page > 1)
{
return $this->link($this->page - 1, $text, 'prev_page').' ';
}
return HTML::span($text, array('class' => 'disabled prev_page')).' ';
}
/**
* Generate the "next" HTML link.
*
* @return string
*/
public function next()
{
$text = Lang::line('pagination.next')->get($this->language);
if ($this->page < $this->last_page)
{
return $this->link($this->page + 1, $text, 'next_page');
}
return HTML::span($text, array('class' => 'disabled next_page'));
}
/**
* Build the first two page links for a sliding page range.
*
* @return string
*/
private function beginning()
{
return $this->range(1, 2).'<span class="dots">...</span>';
}
/**
* Build the last two page links for a sliding page range.
*
* @return string
*/
private function ending()
{
return '<span class="dots">...</span>'.$this->range($this->last_page - 1, $this->last_page);
}
/**
* Build a range of page links.
*
* For the current page, an HTML span element will be generated instead of a link.
*
* @param int $start
* @param int $end
* @return string
*/
private function range($start, $end)
{
$pages = '';
for ($i = $start; $i <= $end; $i++)
{
$pages .= ($this->page == $i) ? HTML::span($i, array('class' => 'current')).' ' : $this->link($i, $i, null).' ';
}
return $pages;
}
/**
* Create a HTML page link.
*
* @param int $page
* @param string $text
* @param string $attributes
* @return string
*/
private function link($page, $text, $class)
{
$append = '';
foreach ($this->append as $key => $value)
{
$append .= '&'.$key.'='.$value;
}
return HTML::link(Request::uri().'?page='.$page.$append, $text, compact('class'), Request::is_secure());
}
/**
* Set the language that should be used when generating page links.
*
* @param string $language
* @return Paginator
*/
public function lang($language)
{
$this->language = $language;
return $this;
}
/**
* Set the items that should be appended to the link query strings.
*
* @param array $values
* @return Paginator
*/
public function append($values)
{
$this->append = $values;
return $this;
}
}
\ No newline at end of file
......@@ -2,24 +2,6 @@
class Redirect extends Response {
/**
* The URL generator instance.
*
* @var URL
*/
private $url;
/**
* Create a new redirect generator instance.
*
* @param URL $url
* @return void
*/
public function __construct(URL $url)
{
$this->url = $url;
}
/**
* Create a redirect response.
*
......@@ -36,11 +18,11 @@ class Redirect extends Response {
* @param bool $https
* @return Redirect
*/
public function to($url, $status = 302, $https = false)
public static function to($url, $status = 302, $https = false)
{
parent::__construct('', $status);
$response = new static('', $status);
return $this->header('Location', $this->url->to($url, $https));
return $response->header('Location', URL::to($url, $https));
}
/**
......@@ -55,9 +37,9 @@ class Redirect extends Response {
* @param int $status
* @return Response
*/
public function to_secure($url, $status = 302)
public static function to_secure($url, $status = 302)
{
return $this->to($url, $status, true);
return static::to($url, $status, true);
}
/**
......@@ -76,7 +58,7 @@ class Redirect extends Response {
*/
public function with($key, $value)
{
if (IoC::container()->resolve('laravel.config')->get('session.driver') == '')
if (Config::get('session.driver') == '')
{
throw new \Exception('A session driver must be set before setting flash data.');
}
......@@ -100,18 +82,18 @@ class Redirect extends Response {
* return Redirect::to_secure_profile();
* </code>
*/
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($this->url->to_route(substr($method, 10), $parameters, true));
return static::to(URL::to_route(substr($method, 10), $parameters, true));
}
if (strpos($method, 'to_') === 0)
{
return $this->to($this->url->to_route(substr($method, 3), $parameters));
return static::to(URL::to_route(substr($method, 3), $parameters));
}
throw new \Exception("Method [$method] is not defined on the Redirect class.");
......
......@@ -2,33 +2,12 @@
class Request {
/**
* The URI for the current request.
*
* @var string
*/
protected $uri;
/**
* The $_SERVER array for the request.
*
* @var array
*/
protected $server;
/**
* The $_POST array for the request.
*
* @var array
*/
protected $post;
/**
* The route handling the current request.
*
* @var Routing\Route
*/
public $route;
public static $route;
/**
* The request data key that is used to indicate the spoofed request method.
......@@ -38,35 +17,15 @@ class Request {
const spoofer = '__spoofer';
/**
* Create a new request instance.
*
* @param string $uri
* @param array $server
* @param array $post
* @return void
*/
public function __construct($uri, $server, $post)
{
$this->uri = $uri;
$this->post = $post;
$this->server = $server;
}
/**
* Determine the request URI.
*
* 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.
* Get the URI for the current request.
*
* 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.
* Note: This method is the equivalent of calling the URI::get method.
*
* @return string
*/
public function uri()
public static function uri()
{
return $this->uri;
return URI::get();
}
/**
......@@ -84,9 +43,9 @@ class Request {
*
* @return string
*/
public function format()
public static function format()
{
return (($extension = pathinfo($this->uri(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
return (($extension = pathinfo(URI::get(), PATHINFO_EXTENSION)) !== '') ? $extension : 'html';
}
/**
......@@ -98,9 +57,9 @@ class Request {
*
* @return string
*/
public function method()
public static function method()
{
return ($this->spoofed()) ? $this->post[Request::spoofer] : $this->server['REQUEST_METHOD'];
return (static::spoofed()) ? $_POST[Request::spoofer] : $_SERVER['REQUEST_METHOD'];
}
/**
......@@ -120,9 +79,9 @@ class Request {
* @param mixed $default
* @return string
*/
public function server($key = null, $default = null)
public static function server($key = null, $default = null)
{
return Arr::get($this->server, strtoupper($key), $default);
return Arr::get($_SERVER, strtoupper($key), $default);
}
/**
......@@ -134,9 +93,9 @@ class Request {
*
* @return bool
*/
public function spoofed()
public static function spoofed()
{
return is_array($this->post) and array_key_exists(Request::spoofer, $this->post);
return is_array($_POST) and array_key_exists(Request::spoofer, $_POST);
}
/**
......@@ -155,19 +114,19 @@ class Request {
* @param mixed $default
* @return string
*/
public function ip($default = '0.0.0.0')
public static function ip($default = '0.0.0.0')
{
if (isset($this->server['HTTP_X_FORWARDED_FOR']))
if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
return $this->server['HTTP_X_FORWARDED_FOR'];
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
elseif (isset($this->server['HTTP_CLIENT_IP']))
elseif (isset($_SERVER['HTTP_CLIENT_IP']))
{
return $this->server['HTTP_CLIENT_IP'];
return $_SERVER['HTTP_CLIENT_IP'];
}
elseif (isset($this->server['REMOTE_ADDR']))
elseif (isset($_SERVER['REMOTE_ADDR']))
{
return $this->server['REMOTE_ADDR'];
return $_SERVER['REMOTE_ADDR'];
}
return ($default instanceof \Closure) ? call_user_func($default) : $default;
......@@ -181,9 +140,9 @@ class Request {
*
* @return string
*/
public function protocol()
public static function protocol()
{
return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http';
return (isset($_SERVER['HTTPS']) and $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
}
/**
......@@ -191,9 +150,9 @@ class Request {
*
* @return bool
*/
public function secure()
public static function secure()
{
return $this->protocol() == 'https';
return static::protocol() == 'https';
}
/**
......@@ -201,11 +160,11 @@ class Request {
*
* @return bool
*/
public function ajax()
public static function ajax()
{
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
if ( ! isset($_SERVER['HTTP_X_REQUESTED_WITH'])) return false;
return strtolower($this->server['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
return strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest';
}
/**
......@@ -213,6 +172,6 @@ class Request {
*
* @return Route
*/
public function route() { return $this->route; }
public function route() { return static::$route; }
}
\ No newline at end of file
<?php namespace Laravel;
class Response_Factory {
class Response {
/**
* The content of the response.
*
* @var mixed
*/
public $content;
/**
* The HTTP status code of the response.
*
* @var int
*/
public $status;
/**
* The view factory instance.
* The response headers.
*
* @var View_Factory
* @var array
*/
protected $view;
public $headers = array();
/**
* The file manager instance.
* HTTP status codes.
*
* @var File
* @var array
*/
protected $file;
private $statuses = array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
507 => 'Insufficient Storage',
509 => 'Bandwidth Limit Exceeded'
);
/**
* Create a new response factory instance.
* Create a new response instance.
*
* @param View_Factory $view
* @param File $file
* @param mixed $content
* @param int $status
* @param array $headers
* @return void
*/
public function __construct(View_Factory $view, File $file)
public function __construct($content, $status = 200, $headers = array())
{
$this->view = $view;
$this->file = $file;
$this->status = $status;
$this->content = $content;
$this->headers = $headers;
}
/**
......@@ -45,9 +108,9 @@ class Response_Factory {
* @param array $headers
* @return Response
*/
public function make($content, $status = 200, $headers = array())
public static function make($content, $status = 200, $headers = array())
{
return new Response($content, $status, $headers);
return new static($content, $status, $headers);
}
/**
......@@ -65,9 +128,9 @@ class Response_Factory {
* @param array $data
* @return Response
*/
public function view($view, $data = array())
public static function view($view, $data = array())
{
return new Response($this->view->make($view, $data));
return new static(View::make($view, $data));
}
/**
......@@ -85,9 +148,9 @@ class Response_Factory {
* @param array $data
* @return Response
*/
public function with($name, $data = array())
public static function with($name, $data = array())
{
return new Response($this->view->of($name, $data));
return new static(View::of($name, $data));
}
/**
......@@ -106,9 +169,9 @@ class Response_Factory {
* @param array $data
* @return Response
*/
public function error($code, $data = array())
public static function error($code, $data = array())
{
return new Response($this->view->make('error/'.$code, $data), $code);
return new static(View::make('error/'.$code, $data), $code);
}
/**
......@@ -119,135 +182,22 @@ class Response_Factory {
* @param array $headers
* @return Response
*/
public function download($path, $name = null, $headers = array())
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' => $this->file->mime($this->file->extension($path)),
'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' => $this->file-size($path),
'Content-Length' => 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.
*
* <code>
* // 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'));
* </code>
*/
public function __call($method, $parameters)
{
if (strpos($method, 'with_') === 0)
{
return $this->with(substr($method, 5), Arr::get($parameters, 0, array()));
}
}
}
class Response {
/**
* The content of the response.
*
* @var mixed
*/
public $content;
/**
* The HTTP status code of the response.
*
* @var int
*/
public $status;
/**
* The response headers.
*
* @var array
*/
public $headers = array();
/**
* HTTP status codes.
*
* @var array
*/
private $statuses = array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
207 => 'Multi-Status',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',
423 => 'Locked',
424 => 'Failed Dependency',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
507 => 'Insufficient Storage',
509 => 'Bandwidth Limit Exceeded'
);
/**
* Create a new response instance.
*
* @param mixed $content
* @param int $status
* @param array $headers
* @return void
*/
public function __construct($content, $status = 200, $headers = array())
{
$this->content = $content;
$this->headers = $headers;
$this->status = $status;
return new static(File::get($path), 200, $headers);
}
/**
......@@ -320,4 +270,23 @@ class Response {
return $this;
}
/**
* Magic Method for handling the dynamic creation of Responses containing named views.
*
* <code>
* // 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'));
* </code>
*/
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
......@@ -69,22 +69,23 @@ class Router {
*
* 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 @@ class Router {
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 @@ class Router {
*
* If no corresponding controller can be found, NULL will be returned.
*
* @param Request $request
* @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)))
{
......
<?php namespace Laravel\Security;
use Laravel\Config;
use Laravel\Session\Driver;
class Auth {
......@@ -11,13 +12,6 @@ class Auth {
*/
protected $user;
/**
* The configuration manager instance.
*
* @var Config
*/
protected $config;
/**
* The session driver instance.
*
......@@ -28,13 +22,11 @@ class Auth {
/**
* Create a new authenticator instance.
*
* @param Config $config
* @param Session\Driver $session
* @return void
*/
public function __construct(Config $config, Driver $session)
public function __construct(Driver $session)
{
$this->config = $config;
$this->session = $session;
}
......@@ -59,7 +51,7 @@ class Auth {
{
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 @@ class Auth {
*/
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 @@ class Auth {
*/
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;
......
<?php namespace Laravel\Session\Drivers;
use Laravel\Config;
use Laravel\Database\Connection;
class Database implements Driver, Sweeper {
......@@ -91,7 +92,7 @@ class Database implements Driver, Sweeper {
*/
private function table()
{
return $this->connection->table($this->config->get('session.table'));
return $this->connection->table(Config::get('session.table'));
}
}
\ No newline at end of file
<?php namespace Laravel\Session\Drivers;
class File implements Driver, Sweeper {
use Laravel\File as F;
/**
* The file engine instance.
*
* @var Laravel\File
*/
private $file;
class File implements Driver, Sweeper {
/**
* The path to which the session files should be written.
......@@ -19,13 +14,11 @@ class File implements Driver, Sweeper {
/**
* Create a new File session driver instance.
*
* @param Laravel\File $file
* @param string $path
* @return void
*/
public function __construct(\Laravel\File $file, $path)
public function __construct($path)
{
$this->file = $file;
$this->path = $path;
}
......@@ -39,7 +32,7 @@ class File implements Driver, Sweeper {
*/
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 @@ class File implements Driver, Sweeper {
*/
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 @@ class File implements Driver, Sweeper {
*/
public function delete($id)
{
$this->file->delete($this->path.$id);
F::delete($this->path.$id);
}
/**
......@@ -75,9 +68,9 @@ class File implements Driver, Sweeper {
{
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);
}
}
}
......
<?php namespace Laravel\Session\Transporters;
class Cookie implements Transporter {
use Laravel\Cookie as C;
/**
* Create a new cookie session transporter instance.
*
* @param Cookie $cookie
* @return void
*/
public function __construct(\Laravel\Cookie $cookie)
{
$this->cookie = $cookie;
}
class Cookie implements Transporter {
/**
* Get the session identifier for the request.
......@@ -21,7 +12,7 @@ class Cookie implements Transporter {
*/
public function get($config)
{
return $this->cookie->get('laravel_session');
return C::get('laravel_session');
}
/**
......@@ -35,7 +26,7 @@ class Cookie implements Transporter {
{
$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
......@@ -74,7 +74,7 @@ class Str {
*/
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 @@ class Str {
*/
protected static function encoding()
{
return IoC::container()->resolve('laravel.config')->get('application.encoding');
return Config::get('application.encoding');
}
}
\ No newline at end of file
......@@ -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 @@ class URI {
* @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 @@ class URI {
*
* @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 @@ class URI {
* @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 @@ class URI {
* @param string $uri
* @return string
*/
protected function format($uri)
protected static function format($uri)
{
return (($uri = trim($uri, '/')) == '') ? '/' : $uri;
}
......
......@@ -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 @@ class URL {
* @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 @@ class URL {
* @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 @@ class 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));
}
/**
......@@ -138,9 +93,9 @@ class URL {
* @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 @@ class URL {
// 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 @@ class URL {
* @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 @@ class URL {
* @param string $separator
* @return string
*/
public function slug($title, $separator = '-')
public static function slug($title, $separator = '-')
{
$title = Str::ascii($title);
......@@ -215,18 +170,18 @@ class URL {
* echo URL::to_secure_profile();
* </code>
*/
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.");
......
......@@ -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
* @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 @@ class Validator {
{
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 @@ class Validator {
}
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 @@ class Validator {
*/
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 @@ class Validator {
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
<?php namespace Laravel;
/**
* The view factory class is responsible for the instantiation of Views. It is typically
* access through the application instance from a route or controller, and is managed
* as a singleton by the application IoC container.
class View {
/**
* The name of the view.
*
* @var string
*/
class View_Factory {
public $view;
/**
* The view composer instance.
* The view data.
*
* @var View_Composer
* @var array
*/
protected $composer;
public $data;
/**
* The directory containing the views.
* The path to the view on disk.
*
* @var string
*/
protected $path;
/**
* Create a new view factory instance.
* Create a new view instance.
*
* @param View_Composer $composer
* @param string $path
* @param string $view
* @param array $data
* @return void
*/
public function __construct(View_Composer $composer, $path)
protected function __construct($view, $data = array())
{
$this->composer = $composer;
$this->path = $path;
$this->view = $view;
$this->data = $data;
$this->path = $this->path($view);
}
/**
* Create a new view instance.
*
* The name of the view given to this method should correspond to a view
* within your application views directory. Dots or slashes may used to
* reference views within sub-directories.
*
* <code>
* // Create a new view instance
* $view = View::make('home.index');
*
* // Create a new view instance with bound data
* $view = View::make('home.index', array('name' => 'Fred'));
* </code>
*
* @param string $view
* @param array $data
* @return View
*/
public function make($view, $data = array())
public static function make($view, $data = array())
{
return new View($this, $this->composer, $view, $data, $this->path($view));
return new static($view, $data);
}
/**
......@@ -75,11 +66,11 @@ class View_Factory {
* @param array $data
* @return View
*/
protected function of($name, $data = array())
public static function of($name, $data = array())
{
if ( ! is_null($view = $this->composer->name($name)))
if ( ! is_null($view = Composer::name($name)))
{
return $this->make($view, $data);
return new static($view, $data);
}
throw new \Exception("Named view [$name] is not defined.");
......@@ -95,11 +86,11 @@ class View_Factory {
{
$view = str_replace('.', '/', $view);
if (file_exists($path = $this->path.$view.'.blade'.EXT))
if (file_exists($path = VIEW_PATH.$view.'.blade'.EXT))
{
return $path;
}
elseif (file_exists($path = $this->path.$view.EXT))
elseif (file_exists($path = VIEW_PATH.$view.EXT))
{
return $path;
}
......@@ -107,149 +98,6 @@ class View_Factory {
throw new \Exception('View ['.$view.'] does not exist.');
}
/**
* Magic Method for handling the dynamic creation of named views.
*
* <code>
* // Create an instance of the "layout" named view
* $view = View::of_layout();
*
* // Create an instance of the "layout" named view with bound data
* $view = View::of_layout(array('name' => 'Fred'));
* </code>
*/
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 {
/**
* The name of the view.
*
* @var string
*/
public $view;
/**
* The view data.
*
* @var array
*/
public $data;
/**
* The path to the view on disk.
*
* @var string
*/
protected $path;
/**
* The view composer instance.
*
* @var View_Composer
*/
protected $composer;
/**
* The view factory instance, which is used to create sub-views.
*
* @var View_Factory
*/
protected $factory;
/**
* Create a new view instance.
*
* @param View_Factory $factory
* @param View_Composer $composer
* @param string $view
* @param array $data
* @param string $path
* @return void
*/
public function __construct(View_Factory $factory, View_Composer $composer, $view, $data, $path)
{
$this->view = $view;
$this->data = $data;
$this->path = $path;
$this->factory = $factory;
$this->composer = $composer;
}
/**
* Get the evaluated string content of the view.
*
......@@ -260,7 +108,7 @@ class View {
*/
public function render()
{
$this->composer->compose($this);
Composer::compose($this);
foreach ($this->data as &$data)
{
......@@ -304,7 +152,7 @@ class View {
*/
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 @@ class View {
unset($this->data[$key]);
}
/**
* Magic Method for handling the dynamic creation of named views.
*
* <code>
* // Create an instance of the "layout" named view
* $view = View::of_layout();
*
* // Create an instance of the "layout" named view with bound data
* $view = View::of_layout(array('name' => 'Fred'));
* </code>
*/
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
......@@ -44,3 +44,5 @@ $public = __DIR__;
|--------------------------------------------------------------------------
*/
require $laravel.'/laravel.php';
echo number_format((microtime(true) - START_TIME) * 1000, 2);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment