Commit abc1fad6 authored by Taylor Otwell's avatar Taylor Otwell

more refactoring and changes.

parent 03654fc5
...@@ -39,12 +39,12 @@ return array( ...@@ -39,12 +39,12 @@ return array(
| |
*/ */
'shared' => function($view, $laravel) 'shared' => function($view)
{ {
// //
}, },
'home.index' => array('name' => 'home', function($view, $laravel) 'home.index' => array('name' => 'home', function($view)
{ {
// //
}), }),
......
...@@ -19,7 +19,7 @@ return array( ...@@ -19,7 +19,7 @@ return array(
*/ */
'Arr' => 'Laravel\\Arr', 'Arr' => 'Laravel\\Arr',
'Asset' => 'Laravel\\Asset', 'Asset' => 'Laravel\\Facades\\Asset',
'Auth' => 'Laravel\\Facades\\Auth', 'Auth' => 'Laravel\\Facades\\Auth',
'Benchmark' => 'Laravel\\Benchmark', 'Benchmark' => 'Laravel\\Benchmark',
'Cache' => 'Laravel\\Facades\\Cache', 'Cache' => 'Laravel\\Facades\\Cache',
...@@ -37,16 +37,16 @@ return array( ...@@ -37,16 +37,16 @@ return array(
'Inflector' => 'Laravel\\Inflector', 'Inflector' => 'Laravel\\Inflector',
'Input' => 'Laravel\\Facades\\Input', 'Input' => 'Laravel\\Facades\\Input',
'IoC' => 'Laravel\\IoC', 'IoC' => 'Laravel\\IoC',
'Lang' => 'Laravel\\Lang', 'Lang' => 'Laravel\\Facades\\Lang',
'Loader' => 'Laravel\\Facades\\Loader', 'Loader' => 'Laravel\\Facades\\Loader',
'Package' => 'Laravel\\Facades\\Package', 'Package' => 'Laravel\\Facades\\Package',
'URL' => 'Laravel\\Facades\\URL', 'URL' => 'Laravel\\Facades\\URL',
'Redirect' => 'Laravel\\Facades\\Redirect', 'Redirect' => 'Laravel\\Facades\\Redirect',
'Request' => 'Laravel\\Facades\\Request', 'Request' => 'Laravel\\Facades\\Request',
'Response' => 'Laravel\\Response', 'Response' => 'Laravel\\Facades\\Response',
'Session' => 'Laravel\\Facades\\Session', 'Session' => 'Laravel\\Facades\\Session',
'Str' => 'Laravel\\Str', 'Str' => 'Laravel\\Str',
'Validator' => 'Laravel\\Facades\\Validator', 'Validator' => 'Laravel\\Facades\\Validator',
'View' => 'Laravel\\View', 'View' => 'Laravel\\Facades\\View',
); );
\ No newline at end of file
...@@ -47,7 +47,7 @@ class Arr { ...@@ -47,7 +47,7 @@ class Arr {
* method, JavaScript "dot" syntax is supported. * method, JavaScript "dot" syntax is supported.
* *
* <code> * <code>
* // Set the "name" item to "Fred" in the array * // Set an array's "name" item to "Fred"
* Arr::set($array, 'name', 'Fred'); * Arr::set($array, 'name', 'Fred');
* </code> * </code>
* *
......
...@@ -58,8 +58,8 @@ class Asset { ...@@ -58,8 +58,8 @@ class Asset {
/** /**
* Magic Method for calling methods on the default Asset container. * Magic Method for calling methods on the default Asset container.
* *
* This provides a convenient API, allowing the develop to skip the "container" * This provides a convenient API, allowing the developer to skip the
* method when using the default container. * "container" method when using the default container.
* *
* <code> * <code>
* // Add a JavaScript file to the default container * // Add a JavaScript file to the default container
...@@ -81,8 +81,6 @@ class Asset_Container { ...@@ -81,8 +81,6 @@ class Asset_Container {
/** /**
* The asset container name. * The asset container name.
* *
* This name may be used to access the container instance via the Asset::container method.
*
* @var string * @var string
*/ */
public $name; public $name;
...@@ -127,10 +125,10 @@ class Asset_Container { ...@@ -127,10 +125,10 @@ class Asset_Container {
* *
* <code> * <code>
* // Add an asset to the container * // Add an asset to the container
* Asset::container()->add('jquery', 'js/jquery.js'); * Asset::add('jquery', 'js/jquery.js');
* *
* // Add an asset that has dependencies * // Add an asset that has dependencies
* Asset::container()->add('jquery', 'js/jquery.js', array('jquery-ui')); * Asset::add('jquery', 'js/jquery.js', array('jquery-ui'));
* </code> * </code>
* *
* @param string $name * @param string $name
...@@ -147,13 +145,13 @@ class Asset_Container { ...@@ -147,13 +145,13 @@ class Asset_Container {
} }
/** /**
* Add CSS to the registered assets. * Add a CSS file to the registered assets.
* *
* @param string $name * @param string $name
* @param string $source * @param string $source
* @param array $dependencies * @param array $dependencies
* @param array $attributes * @param array $attributes
* @return void * @return Asset_Container
*/ */
public function style($name, $source, $dependencies = array(), $attributes = array()) public function style($name, $source, $dependencies = array(), $attributes = array())
{ {
...@@ -163,20 +161,24 @@ class Asset_Container { ...@@ -163,20 +161,24 @@ class Asset_Container {
} }
$this->register('style', $name, $source, $dependencies, $attributes); $this->register('style', $name, $source, $dependencies, $attributes);
return $this;
} }
/** /**
* Add JavaScript to the registered assets. * Add a JavaScript file to the registered assets.
* *
* @param string $name * @param string $name
* @param string $source * @param string $source
* @param array $dependencies * @param array $dependencies
* @param array $attributes * @param array $attributes
* @return void * @return Asset_Container
*/ */
public function script($name, $source, $dependencies = array(), $attributes = array()) public function script($name, $source, $dependencies = array(), $attributes = array())
{ {
$this->register('script', $name, $source, $dependencies, $attributes); $this->register('script', $name, $source, $dependencies, $attributes);
return $this;
} }
/** /**
......
...@@ -10,9 +10,14 @@ class Benchmark { ...@@ -10,9 +10,14 @@ class Benchmark {
protected static $marks = array(); protected static $marks = array();
/** /**
* Start a benchmark. * Start a benchmark starting time.
* *
* After starting a benchmark, the elapsed time in milliseconds may be retrieved via the "check" method. * The elapsed time since setting a benchmark may checked via the "check" method.
*
* <code>
* // Set a benchmark starting time
* Benchmark::start('database');
* </code>
* *
* @param string $name * @param string $name
* @return void * @return void
...@@ -25,6 +30,11 @@ class Benchmark { ...@@ -25,6 +30,11 @@ class Benchmark {
/** /**
* Get the elapsed time in milliseconds since starting a benchmark. * Get the elapsed time in milliseconds since starting a benchmark.
* *
* <code>
* // Get the elapsed time since starting a benchmark
* $time = Benchmark::check('database');
* </code>
*
* @param string $name * @param string $name
* @return float * @return float
*/ */
...@@ -45,7 +55,7 @@ class Benchmark { ...@@ -45,7 +55,7 @@ class Benchmark {
*/ */
public static function memory() public static function memory()
{ {
return number_format(memory_get_usage() / 1024 / 1024, 2); return (float) number_format(memory_get_usage() / 1024 / 1024, 2);
} }
} }
\ No newline at end of file
<?php namespace Laravel;
class Blade {
/**
* Rewrites the specified file containing Blade pseudo-code into valid PHP.
*
* @param string $path
* @return string
*/
public static function parse($path)
{
return static::parse_string(file_get_contents($path));
}
/**
* Rewrites the specified string containing Blade pseudo-code into valid PHP.
*
* @param string $value
* @return string
*/
public static function parse_string($value)
{
$value = static::rewrite_echos($value);
$value = static::rewrite_openings($value);
$value = static::rewrite_closings($value);
return $value;
}
/**
* Rewrites Blade echo statements into PHP echo statements.
*
* @param string $value
* @return string
*/
protected static function rewrite_echos($value)
{
return preg_replace('/\{\{(.+)\}\}/', '<?php echo $1; ?>', $value);
}
/**
* Rewrites Blade structure openings into PHP structure openings.
*
* @param string $value
* @return string
*/
protected static function rewrite_openings($value)
{
return preg_replace('/@(if|elseif|foreach|for|while)(\s*\(.*?\))\:/', '<?php $1$2: ?>', $value);
}
/**
* Rewrites Blade structure closings into PHP structure closings.
*
* @param string $value
* @return string
*/
protected static function rewrite_closings($value)
{
$value = preg_replace('/(\s*)@(else)(.*?)\:/', '$1<?php $2$3: ?>', $value);
$value = preg_replace('/(\s*)@(endif|endforeach|endfor|endwhile)(\s*)/', '$1<?php $2; ?> $3', $value);
return $value;
}
}
\ No newline at end of file
...@@ -25,9 +25,7 @@ define('CONFIG_PATH', APP_PATH.'config/'); ...@@ -25,9 +25,7 @@ define('CONFIG_PATH', APP_PATH.'config/');
define('CONTROLLER_PATH', APP_PATH.'controllers/'); define('CONTROLLER_PATH', APP_PATH.'controllers/');
define('DATABASE_PATH', STORAGE_PATH.'database/'); define('DATABASE_PATH', STORAGE_PATH.'database/');
define('LANG_PATH', APP_PATH.'language/'); define('LANG_PATH', APP_PATH.'language/');
define('SCRIPT_PATH', PUBLIC_PATH.'js/');
define('SESSION_PATH', STORAGE_PATH.'sessions/'); define('SESSION_PATH', STORAGE_PATH.'sessions/');
define('STYLE_PATH', PUBLIC_PATH.'css/');
define('SYS_CONFIG_PATH', SYS_PATH.'config/'); define('SYS_CONFIG_PATH', SYS_PATH.'config/');
define('SYS_LANG_PATH', SYS_PATH.'language/'); define('SYS_LANG_PATH', SYS_PATH.'language/');
define('VIEW_PATH', APP_PATH.'views/'); define('VIEW_PATH', APP_PATH.'views/');
...@@ -36,7 +34,6 @@ define('VIEW_PATH', APP_PATH.'views/'); ...@@ -36,7 +34,6 @@ define('VIEW_PATH', APP_PATH.'views/');
// Load the configuration manager and its dependencies. // Load the configuration manager and its dependencies.
// -------------------------------------------------------------- // --------------------------------------------------------------
require SYS_PATH.'facades'.EXT; require SYS_PATH.'facades'.EXT;
require SYS_PATH.'loader'.EXT;
require SYS_PATH.'config'.EXT; require SYS_PATH.'config'.EXT;
require SYS_PATH.'arr'.EXT; require SYS_PATH.'arr'.EXT;
...@@ -62,6 +59,6 @@ $container = new Container($dependencies); ...@@ -62,6 +59,6 @@ $container = new Container($dependencies);
IoC::$container = $container; IoC::$container = $container;
// -------------------------------------------------------------- // --------------------------------------------------------------
// Register the auto-loader on the stack. // Register the auto-loader on the auto-loader stack.
// -------------------------------------------------------------- // --------------------------------------------------------------
spl_autoload_register(array($container->loader, 'load')); spl_autoload_register(array($container->resolve('laravel.loader'), 'load'));
\ No newline at end of file \ No newline at end of file
<?php namespace Laravel\Cache; <?php namespace Laravel\Cache;
use Closure;
abstract class Driver { abstract class Driver {
/** /**
...@@ -25,7 +27,7 @@ abstract class Driver { ...@@ -25,7 +27,7 @@ abstract class Driver {
{ {
if ( ! is_null($item = $this->retrieve($key))) return $item; if ( ! is_null($item = $this->retrieve($key))) return $item;
return ($default instanceof \Closure) ? call_user_func($default) : $default; return ($default instanceof Closure) ? call_user_func($default) : $default;
} }
/** /**
...@@ -59,7 +61,7 @@ abstract class Driver { ...@@ -59,7 +61,7 @@ abstract class Driver {
{ {
if ( ! is_null($item = $this->get($key, null))) return $item; if ( ! is_null($item = $this->get($key, null))) return $item;
$default = ($default instanceof \Closure) ? call_user_func($default) : $default; $default = ($default instanceof Closure) ? call_user_func($default) : $default;
$this->put($key, $default, $minutes); $this->put($key, $default, $minutes);
......
...@@ -5,14 +5,14 @@ class Config { ...@@ -5,14 +5,14 @@ class Config {
/** /**
* All of the loaded configuration items. * All of the loaded configuration items.
* *
* The configuration arrays are keyed by file names. * The configuration arrays are keyed by their owning file name.
* *
* @var array * @var array
*/ */
protected $items = array(); protected $items = array();
/** /**
* The paths containing the configuration files. * The paths to the configuration files.
* *
* @var array * @var array
*/ */
...@@ -46,6 +46,17 @@ class Config { ...@@ -46,6 +46,17 @@ class Config {
* If the name of a configuration file is passed without specifying an item, the * If the name of a configuration file is passed without specifying an item, the
* entire configuration array will be returned. * entire configuration array will be returned.
* *
* <code>
* // Get the "timezone" option from the "application" file
* $timezone = Config::get('application.timezone');
*
* // Get the SQLite connection configuration from the "database" file
* $sqlite = Config::get('database.connections.sqlite');
*
* // Get a configuration option and return "Fred" if it doesn't exist
* $option = Config::get('config.option', 'Fred');
* </code>
*
* @param string $key * @param string $key
* @param string $default * @param string $default
* @return array * @return array
...@@ -70,6 +81,14 @@ class Config { ...@@ -70,6 +81,14 @@ class Config {
* If a specific configuration item is not specified, the entire configuration * If a specific configuration item is not specified, the entire configuration
* array will be replaced with the given value. * array will be replaced with the given value.
* *
* <code>
* // Set the "timezone" option in the "application" file
* Config::set('application.timezone', 'America/Chicago');
*
* // Set the entire "session" array to an empty array
* Config::set('session', array());
* </code>
*
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @return void * @return void
...@@ -91,11 +110,13 @@ class Config { ...@@ -91,11 +110,13 @@ class Config {
* @param string $key * @param string $key
* @return array * @return array
*/ */
private function parse($key) protected function parse($key)
{ {
$segments = explode('.', $key); $segments = explode('.', $key);
return array($segments[0], (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null); $key = (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null;
return array($segments[0], $key);
} }
/** /**
......
...@@ -110,7 +110,7 @@ return array( ...@@ -110,7 +110,7 @@ return array(
($request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input); ($request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input);
} }
return new Input($input, $_FILES, $container->resolve('laravel.cookie')); return new Input($container->resolve('laravel.file'), $container->resolve('laravel.cookie'), $input, $_FILES);
}), }),
...@@ -124,9 +124,11 @@ return array( ...@@ -124,9 +124,11 @@ return array(
'laravel.loader' => array('singleton' => true, 'resolver' => function($container) 'laravel.loader' => array('singleton' => true, 'resolver' => function($container)
{ {
$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'); require_once SYS_PATH.'loader'.EXT;
return new Loader($container->resolve('laravel.config')->get('aliases'), $paths); $aliases = $container->resolve('laravel.config')->get('aliases');
return new Loader(array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'), $aliases);
}), }),
...@@ -152,7 +154,7 @@ return array( ...@@ -152,7 +154,7 @@ return array(
{ {
require_once SYS_PATH.'response'.EXT; require_once SYS_PATH.'response'.EXT;
return new Response_Factory($container->resolve('laravel.view')); return new Response_Factory($container->resolve('laravel.view'), $container->resolve('laravel.file'));
}), }),
...@@ -220,7 +222,7 @@ return array( ...@@ -220,7 +222,7 @@ return array(
'laravel.view.composer' => array('resolver' => function($container) 'laravel.view.composer' => array('resolver' => function($container)
{ {
return new View_Composer($container, require APP_PATH.'composers'.EXT); return new View_Composer(require APP_PATH.'composers'.EXT);
}), }),
/* /*
......
...@@ -46,26 +46,31 @@ class Container { ...@@ -46,26 +46,31 @@ class Container {
* *
* @var array * @var array
*/ */
protected $resolvers = array(); protected $registry = array();
/** /**
* Create a new IoC container instance. * Create a new IoC container instance.
* *
* @param array $dependencies * @param array $registry
* @return void * @return void
*/ */
public function __construct($dependencies = array()) public function __construct($registry = array())
{ {
foreach ($dependencies as $key => $value) $this->registry = $registry;
{
$this->register($key, $value['resolver'], (isset($value['singleton'])) ? $value['singleton'] : false);
}
} }
/** /**
* Register a dependency and its resolver. * Register a dependency and its resolver.
* *
* The resolver function when the registered dependency is requested. * The resolver function is called when the registered dependency is requested.
*
* <code>
* // Register a dependency in the container
* IoC::register('something', function($container) {return new Something;});
*
* // Register a dependency in the container as a singleton
* IoC::register('something', function($container) {return new Something;}, true);
* </code>
* *
* @param string $name * @param string $name
* @param Closure $resolver * @param Closure $resolver
...@@ -73,7 +78,7 @@ class Container { ...@@ -73,7 +78,7 @@ class Container {
*/ */
public function register($name, $resolver, $singleton = false) public function register($name, $resolver, $singleton = false)
{ {
$this->resolvers[$name] = array('resolver' => $resolver, 'singleton' => $singleton); $this->registry[$name] = array('resolver' => $resolver, 'singleton' => $singleton);
} }
/** /**
...@@ -84,7 +89,7 @@ class Container { ...@@ -84,7 +89,7 @@ class Container {
*/ */
public function registered($name) public function registered($name)
{ {
return array_key_exists($name, $this->resolvers); return array_key_exists($name, $this->registry);
} }
/** /**
...@@ -93,6 +98,11 @@ class Container { ...@@ -93,6 +98,11 @@ class Container {
* Singletons will only be instantiated the first time they are resolved. On subsequent * Singletons will only be instantiated the first time they are resolved. On subsequent
* requests for the object, the original instance will be returned. * requests for the object, the original instance will be returned.
* *
* <code>
* // Register a dependency in the container as a singleton
* IoC::singleton('something', function($container) {return new Something;});
* </code>
*
* @param string $name * @param string $name
* @param Closure $resolver * @param Closure $resolver
* @return void * @return void
...@@ -108,6 +118,13 @@ class Container { ...@@ -108,6 +118,13 @@ class Container {
* This method allows you to register an already existing object instance with the * This method allows you to register an already existing object instance with the
* container as a singleton instance. * container as a singleton instance.
* *
* <code>
* // Register an instance with the IoC container
* $something = new Something;
*
* IoC::instance('something', $something);
* </code>
*
* @param string $name * @param string $name
* @param mixed $instance * @param mixed $instance
* @return void * @return void
...@@ -122,6 +139,11 @@ class Container { ...@@ -122,6 +139,11 @@ class Container {
* *
* The dependency's resolver will be called and its result will be returned. * The dependency's resolver will be called and its result will be returned.
* *
* <code>
* // Get the "something" dependency out of the IoC container
* $something = IoC::resolve('something');
* </code>
*
* @param string $name * @param string $name
* @return mixed * @return mixed
*/ */
...@@ -134,26 +156,25 @@ class Container { ...@@ -134,26 +156,25 @@ class Container {
throw new \Exception("Error resolving [$name]. No resolver has been registered in the container."); throw new \Exception("Error resolving [$name]. No resolver has been registered in the container.");
} }
$object = call_user_func($this->resolvers[$name]['resolver'], $this); $object = call_user_func($this->registry[$name]['resolver'], $this);
if ($this->resolvers[$name]['singleton']) $this->singletons[$name] = $object; return (isset($this->registry[$name]['singleton'])) ? $this->singletons[$name] = $object : $object;
return $object;
} }
/** /**
* Magic Method for resolving classes out of the IoC container. * Magic Method for resolving classes out of the IoC container.
*
* <code>
* // Get the "something" instance out of the IoC container
* $something = IoC::container()->something;
*
* // Equivalent method of retrieving the instance using the resolve method
* $something = IoC::container()->resolve('something');
* </code>
*/ */
public function __get($key) public function __get($key)
{ {
if ($this->registered('laravel.'.$key)) if ($this->registered($key)) return $this->resolve($key);
{
return $this->resolve('laravel.'.$key);
}
elseif ($this->registered($key))
{
return $this->resolve($key);
}
throw new \Exception("Attempting to resolve undefined class [$key]."); throw new \Exception("Attempting to resolve undefined class [$key].");
} }
......
...@@ -2,13 +2,6 @@ ...@@ -2,13 +2,6 @@
abstract class Controller { abstract class Controller {
/**
* The IoC container instance.
*
* @var Container
*/
public $container;
/** /**
* A stub method that will be called before every request to the controller. * A stub method that will be called before every request to the controller.
* *
...@@ -28,15 +21,26 @@ abstract class Controller { ...@@ -28,15 +21,26 @@ abstract class Controller {
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
return $this->container->resolve('laravel.response')->error('404'); return IoC::container()->resolve('laravel.response')->error('404');
} }
/** /**
* Magic Method for retrieving items out of the IoC container. * Dynamically resolve items from the application IoC container.
*/ */
public function __get($key) public function __get($key)
{ {
return $this->container->$key; $container = IoC::container();
if ($container->registered('laravel.'.$key))
{
return $container->resolve('laravel.'.$key);
}
elseif ($container->registered($key))
{
return $container->resolve($key);
}
throw new \Exception("Attempting to access undefined property [$key] on controller.");
} }
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ class Cookie { ...@@ -7,7 +7,7 @@ class Cookie {
* *
* @var array * @var array
*/ */
private $cookies; protected $cookies;
/** /**
* Create a new cookie manager instance. * Create a new cookie manager instance.
...@@ -34,6 +34,14 @@ class Cookie { ...@@ -34,6 +34,14 @@ class Cookie {
/** /**
* Get the value of a cookie. * Get the value of a cookie.
* *
* <code>
* // Get the value of a cookie
* $value = Cookie::get('color');
*
* // Get the value of a cookie and return "blue" if the cookie doesn't exist
* $value = Cookie::get('color', 'blue');
* </code>
*
* @param string $name * @param string $name
* @param mixed $default * @param mixed $default
* @return string * @return string
...@@ -60,8 +68,9 @@ class Cookie { ...@@ -60,8 +68,9 @@ class Cookie {
} }
/** /**
* Set the value of a cookie. If a negative number of minutes is * Set the value of a cookie.
* specified, the cookie will be deleted. *
* If a negative number of minutes is specified, the cookie will be deleted.
* *
* @param string $name * @param string $name
* @param string $value * @param string $value
...@@ -74,9 +83,11 @@ class Cookie { ...@@ -74,9 +83,11 @@ class Cookie {
*/ */
public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false, $http_only = false) public function put($name, $value, $minutes = 0, $path = '/', $domain = null, $secure = false, $http_only = false)
{ {
if ($minutes < 0) unset($_COOKIE[$name]); if ($minutes < 0) unset($this->cookies[$name]);
$time = ($minutes != 0) ? time() + ($minutes * 60) : 0;
return setcookie($name, $value, ($minutes != 0) ? time() + ($minutes * 60) : 0, $path, $domain, $secure, $http_only); return setcookie($name, $value, $time, $path, $domain, $secure, $http_only);
} }
/** /**
......
<?php namespace Laravel;
class Download extends Response {
/**
* The file engine instance.
*
* @var File
*/
protected $file;
/**
* Create a new download engine instance.
*
* @param File $file
* @return void
*/
public function __construct(File $file)
{
$this->file = $file;
}
/**
* Create a new download response instance.
*
* @param string $path
* @param string $name
* @param array $headers
* @return Response
*/
public function of($path, $name = null, $headers = array())
{
if (is_null($name)) $name = basename($path);
$headers = array_merge(array(
'Content-Description' => 'File Transfer',
'Content-Type' => $this->mime($this->file->extension($path)),
'Content-Disposition' => 'attachment; filename="'.$name.'"',
'Content-Transfer-Encoding' => 'binary',
'Expires' => 0,
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'public',
'Content-Length' => $this->file-size($path),
), $headers);
$response = parent::__construct($this->file->get($path), 200, $headers);
return $response;
}
}
\ No newline at end of file
...@@ -15,28 +15,31 @@ abstract class Facade { ...@@ -15,28 +15,31 @@ abstract class Facade {
*/ */
public static function __callStatic($method, $parameters) public static function __callStatic($method, $parameters)
{ {
return call_user_func_array(array(IoC::container()->resolve('laravel.'.static::$resolve), $method), $parameters); return call_user_func_array(array(IoC::container()->resolve(static::$resolve), $method), $parameters);
} }
} }
class Asset extends Facade { public static $resolve = 'asset'; } class Asset extends Facade { public static $resolve = 'laravel.asset'; }
class Auth extends Facade { public static $resolve = 'auth'; } class Auth extends Facade { public static $resolve = 'laravel.auth'; }
class Cache extends Facade { public static $resolve = 'cache'; } class Cache extends Facade { public static $resolve = 'laravel.cache'; }
class Config extends Facade { public static $resolve = 'config'; } class Config extends Facade { public static $resolve = 'laravel.config'; }
class Cookie extends Facade { public static $resolve = 'cookie'; } class Cookie extends Facade { public static $resolve = 'laravel.cookie'; }
class Crypter extends Facade { public static $resolve = 'crypter'; } class Crypter extends Facade { public static $resolve = 'laravel.crypter'; }
class DB extends Facade { public static $resolve = 'database'; } class DB extends Facade { public static $resolve = 'laravel.database'; }
class Download extends Facade { public static $resolve = 'download'; } class Download extends Facade { public static $resolve = 'laravel.download'; }
class File extends Facade { public static $resolve = 'file'; } class File extends Facade { public static $resolve = 'laravel.file'; }
class Form extends Facade { public static $resolve = 'form'; } class Form extends Facade { public static $resolve = 'laravel.form'; }
class Hasher extends Facade { public static $resolve = 'hasher'; } class Hasher extends Facade { public static $resolve = 'laravel.hasher'; }
class HTML extends Facade { public static $resolve = 'html'; } class HTML extends Facade { public static $resolve = 'laravel.html'; }
class Input extends Facade { public static $resolve = 'input'; } class Input extends Facade { public static $resolve = 'laravel.input'; }
class Loader extends Facade { public static $resolve = 'loader'; } class Lang extends Facade { public static $resolve = 'laravel.lang'; }
class Package extends Facade { public static $resolve = 'package'; } class Loader extends Facade { public static $resolve = 'laravel.loader'; }
class Redirect extends Facade { public static $resolve = 'redirect'; } class Package extends Facade { public static $resolve = 'laravel.package'; }
class Request extends Facade { public static $resolve = 'request'; } class Redirect extends Facade { public static $resolve = 'laravel.redirect'; }
class Session extends Facade { public static $resolve = 'session'; } class Request extends Facade { public static $resolve = 'laravel.request'; }
class URL extends Facade { public static $resolve = 'url'; } class Response extends Facade { public static $resolve = 'laravel.response'; }
class Validator extends Facade { public static $resolve = 'validator'; } class Session extends Facade { public static $resolve = 'laravel.session'; }
\ No newline at end of file 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
...@@ -121,9 +121,29 @@ class File { ...@@ -121,9 +121,29 @@ class File {
return filemtime($path); return filemtime($path);
} }
/**
* Move an uploaded file to permanenet storage.
*
* @param string $key
* @param string $path
* @param array $files
* @return bool
*/
public function upload($key, $path, $files)
{
return move_uploaded_file($files[$key]['tmp_name'], $path);
}
/** /**
* Get a file MIME type by extension. * Get a file MIME type by extension.
* *
* If the MIME type can't be determined, "application/octet-stream" will be returned.
*
* <code>
* // Returns 'application/x-tar'
* $mime = File::mime('path/to/file.tar');
* </code>
*
* @param string $extension * @param string $extension
* @param string $default * @param string $default
* @return string * @return string
...@@ -140,20 +160,28 @@ class File { ...@@ -140,20 +160,28 @@ class File {
* *
* The Fileinfo PHP extension will be used to determine the MIME type of the file. * The Fileinfo PHP extension will be used to determine the MIME type of the file.
* *
* @param string $extension * <code>
* @param string $path * // Determine if a file is a JPG image
* $image = File::is('jpg', 'path/to/image.jpg');
*
* // Determine if a file is any one of an array of types
* $image = File::is(array('jpg', 'png', 'gif'), 'path/to/image.jpg');
* </code>
*
* @param array|string $extension
* @param string $path
* @return bool * @return bool
*/ */
public function is($extension, $path) public function is($extensions, $path)
{ {
if ( ! array_key_exists($extension, $this->mimes)) foreach ((array) $extensions as $extension)
{ {
throw new \Exception("File extension [$extension] is unknown. Cannot determine file type."); $mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path);
}
$mime = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $path); if (isset($this->mimes[$extension]) and in_array((array) $this->mimes[$extension])) return true;
}
return (is_array($this->mimes[$extension])) ? in_array($mime, $this->mimes[$extension]) : $mime === $this->mimes[$extension]; return false;
} }
} }
\ No newline at end of file
...@@ -7,21 +7,21 @@ class Form { ...@@ -7,21 +7,21 @@ class Form {
* *
* @var Request * @var Request
*/ */
private $request; protected $request;
/** /**
* The HTML writer instance. * The HTML writer instance.
* *
* @var HTML * @var HTML
*/ */
private $html; protected $html;
/** /**
* The URL generator instance. * The URL generator instance.
* *
* @var URL * @var URL
*/ */
private $url; protected $url;
/** /**
* All of the label names that have been created. * All of the label names that have been created.
...@@ -31,7 +31,7 @@ class Form { ...@@ -31,7 +31,7 @@ class Form {
* *
* @var array * @var array
*/ */
private $labels = array(); protected $labels = array();
/** /**
* Create a new form writer instance. * Create a new form writer instance.
...@@ -55,6 +55,17 @@ class Form { ...@@ -55,6 +55,17 @@ class Form {
* containing the request method. PUT and DELETE are not supported by HTML forms, so the * containing the request method. PUT and DELETE are not supported by HTML forms, so the
* hidden field will allow us to "spoof" PUT and DELETE requests. * hidden field will allow us to "spoof" PUT and DELETE requests.
* *
* <code>
* // Open a POST form to the current URI
* echo Form::open();
*
* // Open a POST form to a given URI
* echo Form::open('user/profile');
*
* // Open a PUT form to a given URI and add form attributes
* echo Form::open('user/profile', 'put', array('class' => 'profile'));
* </code>
*
* @param string $action * @param string $action
* @param string $method * @param string $method
* @param array $attributes * @param array $attributes
...@@ -84,7 +95,7 @@ class Form { ...@@ -84,7 +95,7 @@ class Form {
* @param string $method * @param string $method
* @return string * @return string
*/ */
private function method($method) protected function method($method)
{ {
return strtoupper(($method == 'PUT' or $method == 'DELETE') ? 'POST' : $method); return strtoupper(($method == 'PUT' or $method == 'DELETE') ? 'POST' : $method);
} }
...@@ -98,7 +109,7 @@ class Form { ...@@ -98,7 +109,7 @@ class Form {
* @param bool $https * @param bool $https
* @return string * @return string
*/ */
private function action($action, $https) protected function action($action, $https)
{ {
return $this->html->entities($this->url->to(((is_null($action)) ? $this->request->uri() : $action), $https)); return $this->html->entities($this->url->to(((is_null($action)) ? $this->request->uri() : $action), $https));
} }
...@@ -172,12 +183,25 @@ class Form { ...@@ -172,12 +183,25 @@ class Form {
*/ */
public function raw_token() public function raw_token()
{ {
if (IoC::container()->resolve('laravel.config')->get('session.driver') == '')
{
throw new \Exception("A session driver must be specified before using CSRF tokens.");
}
return IoC::container()->resolve('laravel.session')->get('csrf_token'); return IoC::container()->resolve('laravel.session')->get('csrf_token');
} }
/** /**
* Create a HTML label element. * Create a HTML label element.
* *
* <code>
* // Create a form label
* echo Form::label('email', 'E-Mail Address');
*
* // Create a form label with attributes
* echo Form::label('email', 'E-Mail Address', array('class' => 'login'));
* </code>
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param array $attributes * @param array $attributes
...@@ -196,6 +220,17 @@ class Form { ...@@ -196,6 +220,17 @@ class Form {
* If an ID attribute is not specified and a label has been generated matching the input * If an ID attribute is not specified and a label has been generated matching the input
* element name, the label name will be used as the element ID. * element name, the label name will be used as the element ID.
* *
* <code>
* // Create a "text" type input element
* echo Form::input('text', 'email');
*
* // Create an input element with a specified value
* echo Form::input('text', 'email', 'example@gmail.com');
*
* // Create an input element with attributes
* echo Form::input('text', 'email', 'example@gmail.com', array('class' => 'login'));
* </code>
*
* @param string $name * @param string $name
* @param mixed $value * @param mixed $value
* @param array $attributes * @param array $attributes
...@@ -203,6 +238,8 @@ class Form { ...@@ -203,6 +238,8 @@ class Form {
*/ */
public function input($type, $name, $value = null, $attributes = array()) public function input($type, $name, $value = null, $attributes = array())
{ {
$name = (isset($attributes['name'])) ? $attributes['name'] : $name;
$id = $this->id($name, $attributes); $id = $this->id($name, $attributes);
return '<input'.$this->html->attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.PHP_EOL; return '<input'.$this->html->attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.PHP_EOL;
...@@ -326,6 +363,14 @@ class Form { ...@@ -326,6 +363,14 @@ class Form {
/** /**
* Create a HTML textarea element. * Create a HTML textarea element.
* *
* <code>
* // Create a textarea element
* echo Form::textarea('comment');
*
* // Create a textarea with specified rows and columns
* echo Form::textarea('comment', '', array('rows' => 10, 'columns' => 50));
* </code>
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param array $attributes * @param array $attributes
...@@ -345,6 +390,14 @@ class Form { ...@@ -345,6 +390,14 @@ class Form {
/** /**
* Create a HTML select element. * Create a HTML select element.
* *
* <code>
* // Create a selection element
* echo Form::select('sizes', array('S' => 'Small', 'L' => 'Large'));
*
* // Create a selection element with a given option pre-selected
* echo Form::select('sizes', array('S' => 'Small', 'L' => 'Large'), 'L');
* </code>
*
* @param string $name * @param string $name
* @param array $options * @param array $options
* @param string $selected * @param string $selected
...@@ -370,13 +423,21 @@ class Form { ...@@ -370,13 +423,21 @@ class Form {
/** /**
* Create a HTML checkbox input element. * Create a HTML checkbox input element.
* *
* <code>
* // Create a checkbox element
* echo Form::checkbox('terms');
*
* // Create a checkbox element that is checked by default
* echo Form::checkbox('terms', 'yes', true);
* </code>
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param bool $checked * @param bool $checked
* @param array $attributes * @param array $attributes
* @return string * @return string
*/ */
public function checkbox($name, $value = null, $checked = false, $attributes = array()) public function checkbox($name, $value = 1, $checked = false, $attributes = array())
{ {
return $this->checkable('checkbox', $name, $value, $checked, $attributes); return $this->checkable('checkbox', $name, $value, $checked, $attributes);
} }
...@@ -384,6 +445,14 @@ class Form { ...@@ -384,6 +445,14 @@ class Form {
/** /**
* Create a HTML radio button input element. * Create a HTML radio button input element.
* *
* <code>
* // Create a radio button element
* echo Form::radio('apple');
*
* // Create a radio button element that is selected by default
* echo Form::radio('microsoft', 'pc', true);
* </code>
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param bool $checked * @param bool $checked
...@@ -392,6 +461,8 @@ class Form { ...@@ -392,6 +461,8 @@ class Form {
*/ */
public function radio($name, $value = null, $checked = false, $attributes = array()) public function radio($name, $value = null, $checked = false, $attributes = array())
{ {
if (is_null($value)) $value = $name;
return $this->checkable('radio', $name, $value, $checked, $attributes); return $this->checkable('radio', $name, $value, $checked, $attributes);
} }
...@@ -405,7 +476,7 @@ class Form { ...@@ -405,7 +476,7 @@ class Form {
* @param array $attributes * @param array $attributes
* @return string * @return string
*/ */
private function checkable($type, $name, $value, $checked, $attributes) protected 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' => $this->id($name, $attributes), 'checked' => ($checked) ? 'checked' : null));
...@@ -415,6 +486,14 @@ class Form { ...@@ -415,6 +486,14 @@ class Form {
/** /**
* Create a HTML submit input element. * Create a HTML submit input element.
* *
* <code>
* // Create a submit input element
* echo Form::submit('Login!');
*
* // Create a submit input element with attributes
* echo Form::submit('Login!', array('class' => 'login'));
* </code>
*
* @param string $value * @param string $value
* @param array $attributes * @param array $attributes
* @return string * @return string
...@@ -439,6 +518,11 @@ class Form { ...@@ -439,6 +518,11 @@ class Form {
/** /**
* Create a HTML image input element. * Create a HTML image input element.
* *
* <code>
* // Create an image input element
* echo Form::image('img/login.jpg');
* </code>
*
* @param string $url * @param string $url
* @param array $attributes * @param array $attributes
* @return string * @return string
...@@ -453,6 +537,14 @@ class Form { ...@@ -453,6 +537,14 @@ class Form {
/** /**
* Create a HTML button element. * Create a HTML button element.
* *
* <code>
* // Create a button input element
* echo Form::button('Login!');
*
* // Create a button input element with attributes
* echo Form::button('Login!', array('class' => 'login'));
* </code>
*
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param array $attributes * @param array $attributes
...@@ -473,7 +565,7 @@ class Form { ...@@ -473,7 +565,7 @@ class Form {
* @param array $attributes * @param array $attributes
* @return mixed * @return mixed
*/ */
private function id($name, $attributes) protected function id($name, $attributes)
{ {
if (array_key_exists('id', $attributes)) return $attributes['id']; if (array_key_exists('id', $attributes)) return $attributes['id'];
......
...@@ -44,6 +44,14 @@ class HTML { ...@@ -44,6 +44,14 @@ class HTML {
/** /**
* Generate a JavaScript reference. * Generate a JavaScript reference.
* *
* <code>
* // Generate a link to a JavaScript file
* echo HTML::script('js/jquery.js');
*
* // Generate a link to a JavaScript file with attributes
* echo HTML::script('js/jquery.js', array('defer'));
* </code>
*
* @param string $url * @param string $url
* @param array $attributes * @param array $attributes
* @return string * @return string
...@@ -58,6 +66,16 @@ class HTML { ...@@ -58,6 +66,16 @@ class HTML {
/** /**
* Generate a CSS reference. * Generate a CSS reference.
* *
* If no media type is selected, "all" will be used.
*
* <code>
* // Generate a link to a CSS file
* echo HTML::style('css/common.css');
*
* // Generate a link to a CSS file with attributes
* echo HTML::style('css/common.css', array('media' => 'print'));
* </code>
*
* @param string $url * @param string $url
* @param array $attributes * @param array $attributes
* @return string * @return string
...@@ -74,6 +92,14 @@ class HTML { ...@@ -74,6 +92,14 @@ class HTML {
/** /**
* Generate a HTML span. * Generate a HTML span.
* *
* <code>
* // Generate a HTML span element
* echo HTML::span('This is inside a span element.');
*
* // Generate a HTML span element with attributes
* echo HTML::span('This is inside a span.', array('class' => 'text'));
* </code>
*
* @param string $value * @param string $value
* @param array $attributes * @param array $attributes
* @return string * @return string
...@@ -86,6 +112,14 @@ class HTML { ...@@ -86,6 +112,14 @@ class HTML {
/** /**
* Generate a HTML link. * Generate a HTML link.
* *
* <code>
* // Generate a HTML link element
* echo HTML::link('user/profile', 'User Profile');
*
* // Generate a HTML link element with attributes
* echo HTML::link('user/profile', 'User Profile', array('class' => 'profile'));
* </code>
*
* @param string $url * @param string $url
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
...@@ -116,6 +150,8 @@ class HTML { ...@@ -116,6 +150,8 @@ class HTML {
/** /**
* Generate an HTML link to an asset. * Generate an HTML link to an asset.
* *
* The application index page will not be added to asset links.
*
* @param string $url * @param string $url
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
...@@ -144,6 +180,15 @@ class HTML { ...@@ -144,6 +180,15 @@ class HTML {
* *
* An array of parameters may be specified to fill in URI segment wildcards. * An array of parameters may be specified to fill in URI segment wildcards.
* *
* <code>
* // Generate a link to the "profile" route
* echo HTML::link_to_route('profile', 'User Profile');
*
* // Generate a link to a route that has wildcard segments
* // Example: /user/profile/(:any)
* echo HTML::link_to_route('profile', 'User Profile', array($username));
* </code>
*
* @param string $name * @param string $name
* @param string $title * @param string $title
* @param array $parameters * @param array $parameters
...@@ -174,6 +219,17 @@ class HTML { ...@@ -174,6 +219,17 @@ class HTML {
* *
* The E-Mail address will be obfuscated to protect it from spam bots. * The E-Mail address will be obfuscated to protect it from spam bots.
* *
* <code>
* // Generate a HTML mailto link
* echo HTML::mailto('example@gmail.com');
*
* // Generate a HTML mailto link with a title
* echo HTML::mailto('example@gmail.com', 'E-Mail Me!');
*
* // Generate a HTML mailto link with attributes
* echo HTML::mailto('example@gmail.com', 'E-Mail Me', array('class' => 'email'));
* </code>
*
* @param string $email * @param string $email
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
...@@ -202,7 +258,18 @@ class HTML { ...@@ -202,7 +258,18 @@ class HTML {
} }
/** /**
* Generate an HTML image. * Generate an HTML image element.
*
* <code>
* // Generate a HTML image element
* echo HTML::image('img/profile.jpg');
*
* // Generate a HTML image element with Alt text
* echo HTML::image('img/profile.jpg', 'Profile Photo');
*
* // Generate a HTML image element with attributes
* echo HTML::image('img/profile.jpg', 'Profile Photo', array('class' => 'profile'));
* </code>
* *
* @param string $url * @param string $url
* @param string $alt * @param string $alt
...@@ -217,7 +284,15 @@ class HTML { ...@@ -217,7 +284,15 @@ class HTML {
} }
/** /**
* Generate an ordered list. * Generate an ordered list of items.
*
* <code>
* // Generate an ordered list of items
* echo HTML::ol(array('Small', 'Medium', 'Large'));
*
* // Generate an ordered list of items with attributes
* echo HTML::ol(array('Small', 'Medium', 'Large'), array('class' => 'sizes'));
* </code>
* *
* @param array $list * @param array $list
* @param array $attributes * @param array $attributes
...@@ -229,7 +304,15 @@ class HTML { ...@@ -229,7 +304,15 @@ class HTML {
} }
/** /**
* Generate an un-ordered list. * Generate an un-ordered list of items.
*
* <code>
* // Generate an un-ordered list of items
* echo HTML::ul(array('Small', 'Medium', 'Large'));
*
* // Generate an un-ordered list of items with attributes
* echo HTML::ul(array('Small', 'Medium', 'Large'), array('class' => 'sizes'));
* </code>
* *
* @param array $list * @param array $list
* @param array $attributes * @param array $attributes
...@@ -261,7 +344,12 @@ class HTML { ...@@ -261,7 +344,12 @@ class HTML {
} }
/** /**
* Build a list of HTML attributes. * Build a list of HTML attributes from an array.
*
* <code>
* // Returns: class="profile" id="picture"
* echo HTML::attributes(array('class' => 'profile', 'id' => 'picture'));
* </code>
* *
* @param array $attributes * @param array $attributes
* @return string * @return string
......
...@@ -86,14 +86,14 @@ class Inflector { ...@@ -86,14 +86,14 @@ class Inflector {
* @var array * @var array
*/ */
private static $irregular = array( private static $irregular = array(
'move' => 'moves', 'child' => 'children',
'foot' => 'feet', 'foot' => 'feet',
'goose' => 'geese', 'goose' => 'geese',
'sex' => 'sexes',
'child' => 'children',
'man' => 'men', 'man' => 'men',
'tooth' => 'teeth', 'move' => 'moves',
'person' => 'people', 'person' => 'people',
'sex' => 'sexes',
'tooth' => 'teeth',
); );
/** /**
...@@ -102,20 +102,29 @@ class Inflector { ...@@ -102,20 +102,29 @@ class Inflector {
* @var array * @var array
*/ */
private static $uncountable = array( private static $uncountable = array(
'sheep', 'equipment',
'fish', 'data',
'deer', 'deer',
'series', 'fish',
'species', 'information',
'money', 'money',
'rice', 'rice',
'information', 'series',
'equipment', 'sheep',
'species',
); );
/** /**
* Get the plural form of a word if the specified count is greater than one. * Get the plural form of a word if the specified count is greater than one.
* *
* <code>
* // Returns "friend"
* echo Inflector::plural_if('friend', 1);
*
* // Returns "friends"
* echo Inflector::plural_if('friend', 2);
* </code>
*
* @param string $value * @param string $value
* @param int $count * @param int $count
* @return string * @return string
......
...@@ -10,18 +10,18 @@ class Input { ...@@ -10,18 +10,18 @@ class Input {
protected $input; protected $input;
/** /**
* The $_GET array for the request. * The $_FILES array for the request.
* *
* @var array * @var array
*/ */
public $get; protected $files;
/** /**
* The $_POST array for the request. * The file manager instance.
* *
* @var array * @var File
*/ */
public $post; protected $file;
/** /**
* The cookie engine instance. * The cookie engine instance.
...@@ -30,23 +30,17 @@ class Input { ...@@ -30,23 +30,17 @@ class Input {
*/ */
public $cookies; public $cookies;
/**
* The $_FILES array for the request.
*
* @var array
*/
public $files;
/** /**
* Create a new Input instance. * Create a new Input instance.
* *
* @param Cookie $cookies
* @param array $input * @param array $input
* @param array $files * @param array $files
* @param Cookie $cookies
* @return void * @return void
*/ */
public function __construct($input, $files, Cookie $cookies) public function __construct(File $file, Cookie $cookies, $input, $files)
{ {
$this->file = $file;
$this->input = $input; $this->input = $input;
$this->files = $files; $this->files = $files;
$this->cookies = $cookies; $this->cookies = $cookies;
...@@ -80,6 +74,14 @@ class Input { ...@@ -80,6 +74,14 @@ class Input {
* *
* This method should be used for all request methods (GET, POST, PUT, and DELETE). * This method should be used for all request methods (GET, POST, PUT, and DELETE).
* *
* <code>
* // Get an item from the input to the application
* $value = Input::get('name');
*
* // Get an item from the input and return "Fred" if the item doesn't exist
* $value = Input::get('name', 'Fred');
* </code>
*
* @param string $key * @param string $key
* @param mixed $default * @param mixed $default
* @return mixed * @return mixed
...@@ -103,12 +105,25 @@ class Input { ...@@ -103,12 +105,25 @@ class Input {
/** /**
* Get input data from the previous request. * Get input data from the previous request.
* *
* <code>
* // Get an item from the previous request's input
* $value = Input::old('name');
*
* // Get an item from the previous request's input and return "Fred" if it doesn't exist.
* $value = Input::old('name', 'Fred');
* </code>
*
* @param string $key * @param string $key
* @param mixed $default * @param mixed $default
* @return string * @return string
*/ */
public function old($key = null, $default = null) public function old($key = null, $default = null)
{ {
if (IoC::container()->resolve('laravel.config')->get('session.driver') == '')
{
throw new \Exception('A session driver must be specified in order to access old input.');
}
$driver = IoC::container()->resolve('laravel.session'); $driver = IoC::container()->resolve('laravel.session');
return Arr::get($driver->get('laravel_old_input', array()), $key, $default); return Arr::get($driver->get('laravel_old_input', array()), $key, $default);
...@@ -119,6 +134,14 @@ class Input { ...@@ -119,6 +134,14 @@ class Input {
* *
* "Dot" syntax may be used to get a specific item from the file array. * "Dot" syntax may be used to get a specific item from the file array.
* *
* <code>
* // Get the array of information regarding an uploaded file
* $file = Input::file('picture');
*
* // Get an element from the array of information regarding an uploaded file
* $size = Input::file('picture.size');
* </code>
*
* @param string $key * @param string $key
* @param mixed $default * @param mixed $default
* @return array * @return array
...@@ -133,13 +156,18 @@ class Input { ...@@ -133,13 +156,18 @@ class Input {
* *
* This method is simply a convenient wrapper around move_uploaded_file. * This method is simply a convenient wrapper around move_uploaded_file.
* *
* <code>
* // Move the "picture" file to a permament location on disk
* Input::upload('picture', PUBLIC_PATH.'img/picture.jpg');
* </code>
*
* @param string $key * @param string $key
* @param string $path * @param string $path
* @return bool * @return bool
*/ */
public function upload($key, $path) public function upload($key, $path)
{ {
return array_key_exists($key, $this->files) ? move_uploaded_file($this->files[$key]['tmp_name'], $path) : false; return array_key_exists($key, $this->files) ? $this->file->upload($key, $path, $this->files) : false;
} }
/** /**
......
...@@ -35,6 +35,14 @@ class Lang_Factory { ...@@ -35,6 +35,14 @@ class Lang_Factory {
/** /**
* Begin retrieving a language line. * 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'));
* </code>
*
* @param string $key * @param string $key
* @param array $replacements * @param array $replacements
* @return Lang * @return Lang
...@@ -55,35 +63,35 @@ class Lang { ...@@ -55,35 +63,35 @@ class Lang {
* *
* @var array * @var array
*/ */
private static $lines = array(); protected static $lines = array();
/** /**
* The key of the language line being retrieved. * The key of the language line being retrieved.
* *
* @var string * @var string
*/ */
private $key; protected $key;
/** /**
* The replacements that should be made on the language line. * The replacements that should be made on the language line.
* *
* @var array * @var array
*/ */
private $replacements; protected $replacements;
/** /**
* The default language being used by the application. * The language in which the line should be retrieved.
* *
* @var string * @var string
*/ */
private $language; protected $language;
/** /**
* The paths containing the language files. * The paths containing the language files.
* *
* @var array * @var array
*/ */
private $paths; protected $paths;
/** /**
* Create a new Lang instance. * Create a new Lang instance.
...@@ -102,28 +110,30 @@ class Lang { ...@@ -102,28 +110,30 @@ class Lang {
$this->replacements = $replacements; $this->replacements = $replacements;
} }
/**
* Create a new Lang instance.
*
* @param string $key
* @param array $replacements
* @return Lang
*/
public static function line($key, $replacements = array())
{
return IoC::container()->resolve('laravel.lang')->line($key, $replacements);
}
/** /**
* Get the language line. * Get the language line.
* *
* A default value may also be specified, which will be returned in the language line doesn't exist. * A default value may also be specified, which will be returned in the language line doesn't exist.
* *
* <code>
* // Retrieve a language line in the default language
* echo Lang::line('validation.required')->get();
*
* // Retrieve a language line for a given language
* echo Lang::line('validation.required')->get('sp');
*
* // Retrieve a language line and return "Fred" if it doesn't exist
* echo Lang::line('validation.required')->get('en', 'Fred');
* </code>
*
* @param string $language * @param string $language
* @param string $default
* @return string * @return string
*/ */
public function get($default = null) public function get($language = null, $default = null)
{ {
if ( ! is_null($language)) $this->language = $language;
list($file, $line) = $this->parse($this->key); list($file, $line) = $this->parse($this->key);
if ( ! $this->load($file)) if ( ! $this->load($file))
...@@ -151,7 +161,7 @@ class Lang { ...@@ -151,7 +161,7 @@ class Lang {
* @param string $key * @param string $key
* @return array * @return array
*/ */
private function parse($key) protected function parse($key)
{ {
if (count($segments = explode('.', $key)) > 1) if (count($segments = explode('.', $key)) > 1)
{ {
...@@ -169,7 +179,7 @@ class Lang { ...@@ -169,7 +179,7 @@ class Lang {
* @param string $file * @param string $file
* @return bool * @return bool
*/ */
private function load($file) protected function load($file)
{ {
if (isset(static::$lines[$this->language.$file])) return; if (isset(static::$lines[$this->language.$file])) return;
...@@ -188,20 +198,6 @@ class Lang { ...@@ -188,20 +198,6 @@ class Lang {
return isset(static::$lines[$this->language.$file]); return isset(static::$lines[$this->language.$file]);
} }
/**
* Set the language the line should be returned in.
*
* The language specified in this method should correspond to a language directory in your application.
*
* @param string $language
* @return Lang
*/
public function in($language)
{
$this->language = $language;
return $this;
}
/** /**
* Get the string content of the language line. * Get the string content of the language line.
*/ */
......
...@@ -6,63 +6,53 @@ ...@@ -6,63 +6,53 @@
require 'bootstrap.php'; require 'bootstrap.php';
// -------------------------------------------------------------- // --------------------------------------------------------------
// Set the error reporting and display levels. // Get an instance of the configuration manager.
// -------------------------------------------------------------- // --------------------------------------------------------------
error_reporting(-1); $config = $container->resolve('laravel.config');
ini_set('display_errors', 'Off');
// -------------------------------------------------------------- set_exception_handler(function($e) use ($config)
// Register the error / exception handlers.
// --------------------------------------------------------------
set_exception_handler(function($e) use ($container)
{ {
call_user_func($container->config->get('error.handler'), $e); call_user_func($config->get('error.handler'), $e);
}); });
set_error_handler(function($number, $error, $file, $line) use ($container) set_error_handler(function($number, $error, $file, $line) use ($config)
{ {
$exception = new \ErrorException($error, $number, 0, $file, $line); $exception = new \ErrorException($error, $number, 0, $file, $line);
call_user_func($container->config->get('error.handler'), $exception); call_user_func($config->get('error.handler'), $exception);
}); });
register_shutdown_function(function() use ($container) register_shutdown_function(function() use ($config)
{ {
if ( ! is_null($error = error_get_last())) if ( ! is_null($error = error_get_last()))
{ {
$exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']); $exception = new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']);
call_user_func($container->config->get('error.handler'), $exception); call_user_func($config->get('error.handler'), $exception);
} }
}); });
// -------------------------------------------------------------- // --------------------------------------------------------------
// Set the default timezone. // Set the error reporting and display levels.
// -------------------------------------------------------------- // --------------------------------------------------------------
date_default_timezone_set($container->config->get('application.timezone')); error_reporting(-1);
ini_set('display_errors', 'Off');
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the session and session manager. // Set the default timezone.
// -------------------------------------------------------------- // --------------------------------------------------------------
if ($container->config->get('session.driver') !== '') date_default_timezone_set($config->get('application.timezone'));
{
$cookie = $container->input->cookies->get('laravel_session');
$container->session->start($cookie, $container->config->get('session.lifetime'));
}
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the packages that are in the auto-loaded packages array. // Load the session and session manager.
// -------------------------------------------------------------- // --------------------------------------------------------------
$packages = $container->config->get('application.packages'); if ($config->get('session.driver') !== '')
if (count($packages) > 0)
{ {
$container->package->load($packages); $cookie = $container->resolve('laravel.input')->cookies->get('laravel_session');
}
unset($packages); $container->resolve('laravel.session')->start($cookie, $config->get('session'));
}
// -------------------------------------------------------------- // --------------------------------------------------------------
// Route the request and get the response from the route. // Route the request and get the response from the route.
...@@ -71,13 +61,11 @@ $route = $container->resolve('laravel.routing.router')->route(); ...@@ -71,13 +61,11 @@ $route = $container->resolve('laravel.routing.router')->route();
if ( ! is_null($route)) if ( ! is_null($route))
{ {
$route->filters = require APP_PATH.'filters'.EXT;
$response = $container->resolve('laravel.routing.caller')->call($route); $response = $container->resolve('laravel.routing.caller')->call($route);
} }
else else
{ {
$response = $container->response->error('404'); $response = $container->resolve('laravel.response')->error('404');
} }
// -------------------------------------------------------------- // --------------------------------------------------------------
...@@ -88,9 +76,9 @@ $response->content = $response->render(); ...@@ -88,9 +76,9 @@ $response->content = $response->render();
// -------------------------------------------------------------- // --------------------------------------------------------------
// Close the session. // Close the session.
// -------------------------------------------------------------- // --------------------------------------------------------------
if ($container->config->get('session.driver') !== '') if ($config->get('session.driver') !== '')
{ {
$container->session->close($container->input, $container->config->get('session')); $container->resolve('laravel.session')->close($container->resolve('laravel.input'));
} }
// -------------------------------------------------------------- // --------------------------------------------------------------
......
...@@ -3,35 +3,34 @@ ...@@ -3,35 +3,34 @@
class Loader { class Loader {
/** /**
* The paths to be searched by the loader. * The paths that will be searched by the loader.
* *
* @var array * @var array
*/ */
protected $paths; public $paths;
/** /**
* All of the class aliases. * The class aliases defined for the application.
* *
* @var array * @var array
*/ */
protected $aliases; public $aliases;
/** /**
* Bootstrap the auto-loader. * Create a new class loader instance.
* *
* @param array $paths
* @param array $aliases
* @return void * @return void
*/ */
public function __construct($aliases, $paths) public function __construct($paths, $aliases)
{ {
$this->paths = $paths; $this->paths = $paths;
$this->aliases = $aliases; $this->aliases = $aliases;
} }
/** /**
* Load a class file for a given class name. * Load the file for a given class.
*
* This function is registered on the SPL auto-loader stack by the front controller during each request.
* All Laravel class names follow a namespace to directory convention.
* *
* @param string $class * @param string $class
* @return void * @return void
...@@ -45,9 +44,9 @@ class Loader { ...@@ -45,9 +44,9 @@ class Loader {
return class_alias($this->aliases[$class], $class); return class_alias($this->aliases[$class], $class);
} }
foreach ($this->paths as $directory) foreach ($this->paths as $path)
{ {
if (file_exists($path = $directory.$file.EXT)) if (file_exists($path = $path.$file.EXT))
{ {
require_once $path; require_once $path;
...@@ -56,39 +55,4 @@ class Loader { ...@@ -56,39 +55,4 @@ class Loader {
} }
} }
/**
* Register a path with the auto-loader.
*
* After registering the path, it will be checked similarly to the models and libraries directories.
*
* @param string $path
* @return void
*/
public function register_path($path)
{
$this->paths[] = rtrim($path, '/').'/';
}
/**
* Register an alias with the auto-loader.
*
* @param array $alias
* @return void
*/
public function register_alias($alias)
{
$this->aliases = array_merge($this->aliases, $alias);
}
/**
* Remove an alias from the auto-loader's list of aliases.
*
* @param string $alias
* @return void
*/
public function forget_alias($alias)
{
unset($this->aliases[$alias]);
}
} }
\ No newline at end of file
<?php namespace Laravel;
class Package {
/**
* All of the loaded packages.
*
* @var array
*/
private $loaded = array();
/**
* Load a package or set of packages.
*
* The package name should correspond to a package directory for your application.
*
* @param string|array $packages
* @param string $path
* @return void
*/
public function load($packages, $path)
{
foreach ((array) $packages as $package)
{
if ( ! $this->loaded($package) and file_exists($bootstrap = $path.$package.'/bootstrap'.EXT))
{
require $bootstrap;
}
$this->loaded[] = $package;
}
}
/**
* Determine if a given package has been loaded.
*
* @param string $package
* @return bool
*/
public function loaded($package)
{
return array_key_exists($package, $this->loaded);
}
}
\ No newline at end of file
...@@ -12,7 +12,7 @@ class Redirect extends Response { ...@@ -12,7 +12,7 @@ class Redirect extends Response {
/** /**
* Create a new redirect generator instance. * Create a new redirect generator instance.
* *
* @param URL $url * @param URL $url
* @return void * @return void
*/ */
public function __construct(URL $url) public function __construct(URL $url)
...@@ -23,39 +23,41 @@ class Redirect extends Response { ...@@ -23,39 +23,41 @@ class Redirect extends Response {
/** /**
* Create a redirect response. * Create a redirect response.
* *
* <code>
* // Create a redirect response to a given URL
* return Redirect::to('user/profile');
*
* // Create a redirect with a given status code
* return Redirect::to('user/profile', 301);
* </code>
*
* @param string $url * @param string $url
* @param int $status * @param int $status
* @param string $method
* @param bool $https * @param bool $https
* @return Redirect * @return Redirect
*/ */
public function to($url, $status = 302, $method = 'location', $https = false) public function to($url, $status = 302, $https = false)
{ {
$url = $this->url->to($url, $https);
parent::__construct('', $status); parent::__construct('', $status);
if ($method == 'location') return $this->header('Location', $this->url->to($url, $https));
{
return $this->header('Refresh', '0;url='.$url);
}
else
{
return $this->header('Location', $url);
}
} }
/** /**
* Create a redirect response to a HTTPS URL. * Create a redirect response to a HTTPS URL.
* *
* <code>
* // Create a redirect response to a HTTPS URL
* return Redirect::to_secure('user/profile');
* </code>
*
* @param string $url * @param string $url
* @param int $status * @param int $status
* @param string $method
* @return Response * @return Response
*/ */
public function to_secure($url, $status = 302, $method = 'location') public function to_secure($url, $status = 302)
{ {
return $this->to($url, $status, $method, true); return $this->to($url, $status, true);
} }
/** /**
...@@ -69,6 +71,11 @@ class Redirect extends Response { ...@@ -69,6 +71,11 @@ class Redirect extends Response {
*/ */
public function with($key, $value) public function with($key, $value)
{ {
if (IoC::container()->resolve('laravel.config')->get('session.driver') == '')
{
throw new \Exception('A session driver must be set before setting flash data.');
}
IoC::container()->resolve('laravel.session')->flash($key, $value); IoC::container()->resolve('laravel.session')->flash($key, $value);
return $this; return $this;
......
...@@ -21,14 +21,14 @@ class Request { ...@@ -21,14 +21,14 @@ class Request {
* *
* @var array * @var array
*/ */
private $post; protected $post;
/** /**
* The base URL of the application. * The base URL of the application.
* *
* @var string * @var string
*/ */
private $url; protected $url;
/** /**
* The request URI. * The request URI.
...@@ -38,7 +38,7 @@ class Request { ...@@ -38,7 +38,7 @@ class Request {
* *
* @var string * @var string
*/ */
private $uri; protected $uri;
/** /**
* Create a new request instance. * Create a new request instance.
......
...@@ -7,17 +7,26 @@ class Response_Factory { ...@@ -7,17 +7,26 @@ class Response_Factory {
* *
* @var View_Factory * @var View_Factory
*/ */
private $view; protected $view;
/**
* The file manager instance.
*
* @var File
*/
protected $file;
/** /**
* Create a new response factory instance. * Create a new response factory instance.
* *
* @param File $file * @param View_Factory $view
* @param File $file
* @return void * @return void
*/ */
public function __construct(View_Factory $view) public function __construct(View_Factory $view, File $file)
{ {
$this->view = $view; $this->view = $view;
$this->file = $file;
} }
/** /**
...@@ -54,13 +63,39 @@ class Response_Factory { ...@@ -54,13 +63,39 @@ class Response_Factory {
* *
* @param int $code * @param int $code
* @param array $data * @param array $data
* @return void * @return Response
*/ */
public function error($code, $data = array()) public function error($code, $data = array())
{ {
return new Response($this->view->make('error/'.$code, $data), $code); return new Response($this->view->make('error/'.$code, $data), $code);
} }
/**
* Create a new download response instance.
*
* @param string $path
* @param string $name
* @param array $headers
* @return Response
*/
public function download($path, $name = null, $headers = array())
{
if (is_null($name)) $name = basename($path);
$headers = array_merge(array(
'Content-Description' => 'File Transfer',
'Content-Type' => $this->file->mime($this->file->extension($path)),
'Content-Disposition' => 'attachment; filename="'.$name.'"',
'Content-Transfer-Encoding' => 'binary',
'Expires' => 0,
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0',
'Pragma' => 'public',
'Content-Length' => $this->file-size($path),
), $headers);
return new Response($this->file->get($path), 200, $headers);
}
} }
class Response { class Response {
...@@ -224,12 +259,4 @@ class Response { ...@@ -224,12 +259,4 @@ class Response {
return $this; return $this;
} }
/**
* Magic Method for calling methods on the response factory instance.
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(IoC::container()->resolve('laravel.response'), $method), $parameters);
}
} }
\ No newline at end of file
...@@ -67,7 +67,7 @@ class Caller { ...@@ -67,7 +67,7 @@ class Caller {
return $this->finish($route, $response); return $this->finish($route, $response);
} }
return $this->finish($route, $this->container->response->error('404')); return $this->finish($route, $this->container->resolve('laravel.response')->error('404'));
} }
/** /**
......
...@@ -49,7 +49,7 @@ class Delegator { ...@@ -49,7 +49,7 @@ class Delegator {
// an underscore are not publicly available. // an underscore are not publicly available.
if (is_null($controller) or ($method == 'before' or strncmp($method, '_', 1) === 0)) if (is_null($controller) or ($method == 'before' or strncmp($method, '_', 1) === 0))
{ {
return $this->container->response->error('404'); return $this->container->resolve('laravel.response')->error('404');
} }
$controller->container = $this->container; $controller->container = $this->container;
......
...@@ -13,6 +13,13 @@ abstract class Driver { ...@@ -13,6 +13,13 @@ abstract class Driver {
*/ */
public $session = array(); public $session = array();
/**
* The application session configuration.
*
* @var array
*/
public $config = array();
/** /**
* Load the session for a given session ID. * Load the session for a given session ID.
* *
...@@ -22,14 +29,16 @@ abstract class Driver { ...@@ -22,14 +29,16 @@ abstract class Driver {
* If the session has expired, a new, empty session will be generated. * If the session has expired, a new, empty session will be generated.
* *
* @param string $id * @param string $id
* @param int $lifetime * @param array $config
* @return void * @return void
*/ */
public function start($id, $lifetime) public function start($id, $config)
{ {
$this->config = $config;
$this->session = ( ! is_null($id)) ? $this->load($id) : null; $this->session = ( ! is_null($id)) ? $this->load($id) : null;
if (is_null($this->session) or (time() - $this->session['last_activity']) > ($lifetime * 60)) if (is_null($this->session) or (time() - $this->session['last_activity']) > ($this->config['lifetime'] * 60))
{ {
$this->session = array('id' => Str::random(40), 'data' => array()); $this->session = array('id' => Str::random(40), 'data' => array());
} }
...@@ -169,20 +178,19 @@ abstract class Driver { ...@@ -169,20 +178,19 @@ abstract class Driver {
* available for the next request via the "old" method on the input class. * available for the next request via the "old" method on the input class.
* *
* @param Laravel\Input $input * @param Laravel\Input $input
* @param array $config
* @return void * @return void
*/ */
public function close(Input $input, $config) public function close(Input $input)
{ {
$this->flash('laravel_old_input', $input->get())->age(); $this->flash('laravel_old_input', $input->get())->age();
$this->save(); $this->save();
$this->write_cookie($input->cookies, $config); $this->write_cookie($input->cookies, $this->config);
if ($this instanceof Sweeper and mt_rand(1, 100) <= 2) if ($this instanceof Sweeper and mt_rand(1, 100) <= 2)
{ {
$this->sweep(time() - ($config['lifetime'] * 60)); $this->sweep(time() - ($this->config['lifetime'] * 60));
} }
} }
...@@ -214,7 +222,7 @@ abstract class Driver { ...@@ -214,7 +222,7 @@ abstract class Driver {
* already been sent to the browser. * already been sent to the browser.
* *
* @param Laravel\Cookie $cookie * @param Laravel\Cookie $cookie
* @param array $config * @param array $config
* @return void * @return void
*/ */
protected function write_cookie(Cookie $cookies, $config) protected function write_cookie(Cookie $cookies, $config)
......
...@@ -10,7 +10,12 @@ class Str { ...@@ -10,7 +10,12 @@ class Str {
*/ */
public static function lower($value) public static function lower($value)
{ {
return function_exists('mb_strtolower') ? mb_strtolower($value, static::encoding()) : strtolower($value); if (function_exists('mb_strtolower'))
{
return mb_strtolower($value, static::encoding());
}
return strtolower($value);
} }
/** /**
...@@ -21,7 +26,12 @@ class Str { ...@@ -21,7 +26,12 @@ class Str {
*/ */
public static function upper($value) public static function upper($value)
{ {
return function_exists('mb_strtoupper') ? mb_strtoupper($value, static::encoding()) : strtoupper($value); if (function_exists('mb_strtoupper'))
{
return mb_strtoupper($value, static::encoding());
}
return strtoupper($value);
} }
/** /**
...@@ -32,7 +42,12 @@ class Str { ...@@ -32,7 +42,12 @@ class Str {
*/ */
public static function title($value) public static function title($value)
{ {
return (function_exists('mb_convert_case')) ? mb_convert_case($value, MB_CASE_TITLE, static::encoding()) : ucwords(strtolower($value)); if (function_exists('mb_convert_case'))
{
return mb_convert_case($value, MB_CASE_TITLE, static::encoding());
}
return ucwords(strtolower($value));
} }
/** /**
...@@ -43,7 +58,12 @@ class Str { ...@@ -43,7 +58,12 @@ class Str {
*/ */
public static function length($value) public static function length($value)
{ {
return function_exists('mb_strlen') ? mb_strlen($value, static::encoding()) : strlen($value); if (function_exists('mb_strlen'))
{
return mb_strlen($value, static::encoding());
}
return strlen($value);
} }
/** /**
...@@ -72,34 +92,11 @@ class Str { ...@@ -72,34 +92,11 @@ class Str {
*/ */
public static function random($length = 16, $type = 'alpha_num') public static function random($length = 16, $type = 'alpha_num')
{ {
$value = ''; $alpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$pool_length = strlen($pool = static::pool($type)) - 1; $pool = ($type == 'alpha_num') ? '0123456789'.$alpha : $alpha;
for ($i = 0; $i < $length; $i++) return implode('', array_map(function() use ($pool) { return $pool[mt_rand(0, strlen($pool) - 1)]; }, range(0, $length)));
{
$value .= $pool[mt_rand(0, $pool_length)];
}
return $value;
}
/**
* Get a chracter pool.
*
* @param string $type
* @return string
*/
private static function pool($type = 'alpha_num')
{
switch ($type)
{
case 'alpha_num':
return '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
default:
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
}
} }
/** /**
...@@ -107,7 +104,7 @@ class Str { ...@@ -107,7 +104,7 @@ class Str {
* *
* @return string * @return string
*/ */
public static function encoding() protected static function encoding()
{ {
return IoC::container()->resolve('laravel.config')->get('application.encoding'); return IoC::container()->resolve('laravel.config')->get('application.encoding');
} }
......
...@@ -2,13 +2,41 @@ ...@@ -2,13 +2,41 @@
class URL { 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. * Create a new URL writer instance.
* *
* @param Router $router * @param Routing\Router $router
* @param string $base * @param string $base
* @param string $index * @param string $index
* @param bool $https * @param bool $https
* @return void * @return void
*/ */
public function __construct(Routing\Router $router, $base, $index, $https) public function __construct(Routing\Router $router, $base, $index, $https)
...@@ -24,6 +52,14 @@ class URL { ...@@ -24,6 +52,14 @@ class URL {
* *
* If the given URL is already well-formed, it will be returned unchanged. * If the given URL is already well-formed, it will be returned unchanged.
* *
* <code>
* // Generate an application URL from a given URI
* echo URL::to('user/profile');
*
* // Generate an application URL with HTTPS
* echo URL::to('user/profile', true);
* </code>
*
* @param string $url * @param string $url
* @param bool $https * @param bool $https
* @return string * @return string
...@@ -36,12 +72,17 @@ class URL { ...@@ -36,12 +72,17 @@ class URL {
if ($https) $base = preg_replace('~http://~', 'https://', $base, 1); if ($https) $base = preg_replace('~http://~', 'https://', $base, 1);
return rtrim($base, '/').'/'.trim($url, '/'); return rtrim($base, '/').'/'.ltrim($url, '/');
} }
/** /**
* Generate an application URL with HTTPS. * Generate an application URL with HTTPS.
* *
* <code>
* // Generate an application URL with HTTPS
* echo URL::to_secure('user/profile');
* </code>
*
* @param string $url * @param string $url
* @return string * @return string
*/ */
...@@ -56,6 +97,14 @@ class URL { ...@@ -56,6 +97,14 @@ class URL {
* The index file will not be added to asset URLs. If the HTTPS option is not * The index file will not be added to asset URLs. If the HTTPS option is not
* specified, HTTPS will be used when the active request is also using HTTPS. * specified, HTTPS will be used when the active request is also using HTTPS.
* *
* <code>
* // Generate a URL to an asset
* echo URL::to_asset('img/picture.jpg');
*
* // Generate a URL to a an asset with HTTPS
* echo URL::to_asset('img/picture.jpg', true);
* </code>
*
* @param string $url * @param string $url
* @param bool $https * @param bool $https
* @return string * @return string
...@@ -76,6 +125,14 @@ class URL { ...@@ -76,6 +125,14 @@ class URL {
* *
* Optional parameters will be convereted to spaces if no parameter values are specified. * Optional parameters will be convereted to spaces if no parameter values are specified.
* *
* <code>
* // Generate the URL for a given route
* echo URL::to_route('profile');
*
* // Generate the URL for a given route with wildcard segments
* echo URL::to_route('profile', array($username));
* </code>
*
* @param string $name * @param string $name
* @param array $parameters * @param array $parameters
* @param bool $https * @param bool $https
...@@ -103,6 +160,14 @@ class URL { ...@@ -103,6 +160,14 @@ class URL {
/** /**
* Generate a HTTPS URL from a route name. * Generate a HTTPS URL from a route name.
* *
* <code>
* // Generate the URL for a route with HTTPS
* echo URL::to_secure_route('profile');
*
* // Generate the URL for a route with HTTPS and wildcard segments
* echo URL::to_secure_route('profile', array($username));
* </code>
*
* @param string $name * @param string $name
* @param array $parameters * @param array $parameters
* @return string * @return string
...@@ -134,6 +199,17 @@ class URL { ...@@ -134,6 +199,17 @@ class URL {
/** /**
* Magic Method for dynamically creating URLs to named routes. * Magic Method for dynamically creating URLs to named routes.
*
* <code>
* // Generate the URL for the "profile" named route
* echo URL::to_profile();
*
* // Generate the URL for the "profile" named route with wildcard segments
* echo URL::to_profile(array($username));
*
* // Generate the URL for the "profile" named route with HTTPS
* echo URL::to_secure_profile();
* </code>
*/ */
public function __call($method, $parameters) public function __call($method, $parameters)
{ {
......
...@@ -37,6 +37,18 @@ class View_Factory { ...@@ -37,6 +37,18 @@ class View_Factory {
/** /**
* Create a new view instance. * 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 string $view
* @param array $data * @param array $data
* @return View * @return View
...@@ -49,6 +61,16 @@ class View_Factory { ...@@ -49,6 +61,16 @@ class View_Factory {
/** /**
* Create a new view instance from a view name. * Create a new view instance from a view name.
* *
* View names are defined in the application composers file.
*
* <code>
* // Create a new named view instance
* $view = View::of('layout');
*
* // Create a new named view instance with bound data
* $view = View::of('layout', array('name' => 'Fred'));
* </code>
*
* @param string $name * @param string $name
* @param array $data * @param array $data
* @return View * @return View
...@@ -71,11 +93,30 @@ class View_Factory { ...@@ -71,11 +93,30 @@ class View_Factory {
*/ */
protected function path($view) protected function path($view)
{ {
return $this->path.str_replace('.', '/', $view).EXT; $view = str_replace('.', '/', $view);
if (file_exists($path = $this->path.$view.'.blade'.EXT))
{
return $path;
}
elseif (file_exists($path = $this->path.$view.EXT))
{
return $path;
}
throw new \Exception('View ['.$view.'] does not exist.');
} }
/** /**
* Magic Method for handling the dynamic creation of named views. * 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) public function __call($method, $parameters)
{ {
...@@ -95,13 +136,6 @@ class View_Factory { ...@@ -95,13 +136,6 @@ class View_Factory {
*/ */
class View_Composer { class View_Composer {
/**
* The IoC container instance.
*
* @var Container
*/
protected $container;
/** /**
* The view composers. * The view composers.
* *
...@@ -112,13 +146,11 @@ class View_Composer { ...@@ -112,13 +146,11 @@ class View_Composer {
/** /**
* Create a new view composer instance. * Create a new view composer instance.
* *
* @param Container $container
* @param array $composers * @param array $composers
* @return void * @return void
*/ */
public function __construct(Container $container, $composers) public function __construct($composers)
{ {
$this->container = $container;
$this->composers = $composers; $this->composers = $composers;
} }
...@@ -144,13 +176,13 @@ class View_Composer { ...@@ -144,13 +176,13 @@ class View_Composer {
*/ */
public function compose(View $view) public function compose(View $view)
{ {
if (isset($this->composers['shared'])) call_user_func($this->composers['shared'], $view, $this->container); if (isset($this->composers['shared'])) call_user_func($this->composers['shared'], $view);
if (isset($this->composers[$view->view])) if (isset($this->composers[$view->view]))
{ {
foreach ((array) $this->composers[$view->view] as $key => $value) foreach ((array) $this->composers[$view->view] as $key => $value)
{ {
if ($value instanceof \Closure) return call_user_func($value, $view, $this->container); if ($value instanceof \Closure) return call_user_func($value, $view);
} }
} }
} }
...@@ -216,23 +248,6 @@ class View { ...@@ -216,23 +248,6 @@ class View {
$this->path = $path; $this->path = $path;
$this->factory = $factory; $this->factory = $factory;
$this->composer = $composer; $this->composer = $composer;
if ( ! file_exists($this->path))
{
throw new \Exception('View ['.$this->path.'] does not exist.');
}
}
/**
* Create a new view instance.
*
* @param string $view
* @param array $data
* @return View
*/
public static function make($view, $data = array())
{
return IoC::container()->resolve('laravel.view')->make($view, $data);
} }
/** /**
...@@ -254,14 +269,34 @@ class View { ...@@ -254,14 +269,34 @@ class View {
ob_start() and extract($this->data, EXTR_SKIP); ob_start() and extract($this->data, EXTR_SKIP);
try { include $this->path; } catch (\Exception $e) { ob_get_clean(); throw $e; } $content = ($this->bladed()) ? Blade::parse($this->path) : file_get_contents($this->path);
eval('?>'.$content);
return ob_get_clean(); return ob_get_clean();
} }
/**
* Determine if the view is using the blade view engine.
*
* @return bool
*/
protected function bladed()
{
return (strpos($this->path, '.blade'.EXT) !== false);
}
/** /**
* Add a view instance to the view data. * Add a view instance to the view data.
* *
* <code>
* // Bind a partial view to the view data
* $view->partial('footer', 'partials/footer');
*
* // Bind a partial view to the view data with it's own bound data
* $view->partial('footer', 'partials/footer', array('name' => 'Fred'));
* </code>
*
* @param string $key * @param string $key
* @param string $view * @param string $view
* @param array $data * @param array $data
...@@ -277,6 +312,11 @@ class View { ...@@ -277,6 +312,11 @@ class View {
* *
* Bound data will be available to the view as variables. * Bound data will be available to the view as variables.
* *
* <code>
* // Bind a piece of data to a view instance
* $view->with('name', 'Fred');
* </code>
*
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @return View * @return View
......
...@@ -10,7 +10,14 @@ ...@@ -10,7 +10,14 @@
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| Installation Paths | Tick... Tock... Tick... Tock
|--------------------------------------------------------------------------
*/
define('START_TIME', microtime(true));
/*
|--------------------------------------------------------------------------
| Where Am I?
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| Here you may specify the location of the various Laravel framework | Here you may specify the location of the various Laravel framework
...@@ -36,4 +43,6 @@ $public = __DIR__; ...@@ -36,4 +43,6 @@ $public = __DIR__;
| 3... 2... 1... Lift-off! | 3... 2... 1... Lift-off!
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
*/ */
require $laravel.'/laravel.php'; require $laravel.'/laravel.php';
\ No newline at end of file
echo (microtime(true) - START_TIME) * 1000;
\ 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