Commit 61eced25 authored by Taylor Otwell's avatar Taylor Otwell

Merge branch 'feature/ioc' into develop

parents 501953f2 c7ddbbb0
......@@ -81,7 +81,7 @@
<h2><?php echo $apology; ?></h2>
<p>We couldn't find the resource you requested. Would you like go to our <a href="<?php echo $homepage; ?>">home page</a> instead?</p>
<p>We couldn't find the resource you requested. Would you like go to our <a href="<?php echo Laravel\Config::get('application.url'); ?>">home page</a> instead?</p>
</div>
</body>
</html>
\ No newline at end of file
<?php namespace Laravel;
class Application {
abstract class Resolver {
/**
* The active request instance.
* Magic Method for resolving classes out of the IoC container.
*
* @var Request
*/
public $request;
/**
* The application configuration manager.
*
* @var Config
*/
public $config;
/**
* The application session driver.
*
* @var Session\Driver
*/
public $session;
/**
* The application IoC container.
*
* @var Container
*/
public $container;
/**
* Magic Method for resolving core classes out of the IoC container.
* This allows the derived class to provide access to all of the Laravel libraries
* registered in the container. Currently, this class is derived by the Application
* and Controller classes.
*/
public function __get($key)
{
if ($this->container->registered('laravel.'.$key))
if (IoC::container()->registered('laravel.'.$key))
{
return $this->container->resolve('laravel.'.$key);
return IoC::container()->resolve('laravel.'.$key);
}
elseif ($this->container->registered($key))
elseif (IoC::container()->registered($key))
{
return $this->container->resolve($key);
return IoC::container()->resolve($key);
}
throw new \Exception("Attempting to access undefined property [$key] on application instance.");
throw new \Exception("Attempting to access undefined property [$key].");
}
}
class Application extends Resolver {
/**
* The IoC container instance for the application.
*
* @var Container
*/
public $container;
}
\ No newline at end of file
......@@ -18,14 +18,6 @@ class Asset {
* Containers provide a convenient method of grouping assets while maintaining
* expressive code and a clean API.
*
* <code>
* // Get the default asset container
* $container = Asset::container();
*
* // Get the "footer" asset container
* $container = Asset::container('footer');
* </code>
*
* @param string $container
* @return Asset_Container
*/
......@@ -44,14 +36,6 @@ class Asset {
*
* This provides a convenient API, allowing the develop to skip the "container"
* method when using the default container.
*
* <code>
* // Add an asset to the default container
* Asset::add('jquery', 'js/jquery.js');
*
* // Equivalent statement using the container method
* Asset::container()->add('jquery', 'js/jquery.js');
* </code>
*/
public static function __callStatic($method, $parameters)
{
......@@ -101,14 +85,6 @@ class Asset_Container {
* only link to the registered asset after its dependencies have been linked.
* For example, you may wish to make jQuery UI dependent on jQuery.
*
* <code>
* // Add an asset to the container
* Asset::container()->add('jquery', 'js/jquery.js');
*
* // Add an asset that is dependent on another asset
* Asset::container()->add('jquery-ui', 'js/jquery-ui.js', array('jquery'));
* </code>
*
* @param string $name
* @param string $source
* @param array $dependencies
......@@ -177,10 +153,6 @@ class Asset_Container {
/**
* Get the links to all of the registered CSS assets.
*
* <code>
* echo Asset::container()->styles();
* </code>
*
* @return string
*/
public function styles()
......@@ -191,10 +163,6 @@ class Asset_Container {
/**
* Get the links to all of the registered JavaScript assets.
*
* <code>
* echo Asset::container()->scripts();
* </code>
*
* @return string
*/
public function scripts()
......@@ -225,10 +193,6 @@ class Asset_Container {
/**
* Get the link to a single registered CSS asset.
*
* <code>
* echo Asset::container()->get_style('common');
* </code>
*
* @param string $name
* @return string
*/
......@@ -240,10 +204,6 @@ class Asset_Container {
/**
* Get the link to a single registered JavaScript asset.
*
* <code>
* echo Asset::container()->get_script('jquery');
* </code>
*
* @param string $name
* @return string
*/
......
......@@ -40,39 +40,39 @@ require SYS_PATH.'application'.EXT;
$application = new Application;
// --------------------------------------------------------------
// Load the configuration manager and auto-loader.
// Load the configuration manager.
// --------------------------------------------------------------
require SYS_PATH.'loader'.EXT;
require SYS_PATH.'config'.EXT;
require SYS_PATH.'arr'.EXT;
$application->config = new Config;
$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/');
$application->loader = new Loader($application->config->get('aliases'), $paths);
spl_autoload_register(array($application->loader, 'load'));
unset($paths);
// --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
require SYS_PATH.'container'.EXT;
$application->container = new Container($application->config->get('container'));
$dependencies = require SYS_CONFIG_PATH.'container'.EXT;
// --------------------------------------------------------------
// Register the core application components in the container.
// --------------------------------------------------------------
$application->container->instance('laravel.application', $application);
if (file_exists($path = CONFIG_PATH.'container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
$application->container = new Container($dependencies);
$application->container->instance('laravel.config', $application->config);
IoC::$container = $application->container;
$application->container->instance('laravel.loader', $application->loader);
// --------------------------------------------------------------
// Load the auto-loader.
// --------------------------------------------------------------
spl_autoload_register(array($application->loader, 'load'));
// --------------------------------------------------------------
// Set the IoC container instance for use as a service locator.
// Register the application in the container.
// --------------------------------------------------------------
IoC::$container = $application->container;
\ No newline at end of file
IoC::container()->instance('laravel.application', $application);
\ No newline at end of file
......@@ -75,11 +75,6 @@ class APC extends Driver {
/**
* Determine if an item exists in the cache.
*
* <code>
* // Determine if the "name" item exists in the cache
* $exists = Cache::driver()->has('name');
* </code>
*
* @param string $key
* @return bool
*/
......@@ -102,11 +97,6 @@ class APC extends Driver {
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Write the "name" item to the cache for 30 minutes
* Cache::driver()->put('name', 'Fred', 30);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
......
......@@ -5,11 +5,6 @@ abstract class Driver {
/**
* Determine if an item exists in the cache.
*
* <code>
* // Determine if the "name" item exists in the cache
* $exists = Cache::driver()->has('name');
* </code>
*
* @param string $key
* @return bool
*/
......@@ -21,14 +16,6 @@ abstract class Driver {
* A default value may also be specified, and will be returned in the requested
* item does not exist in the cache.
*
* <code>
* // Get the "name" item from the cache
* $name = Cache::driver()->get('name');
*
* // Get the "name" item from the cache or return "Fred"
* $name = Cache::driver()->get('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $default
* @param string $driver
......@@ -52,11 +39,6 @@ abstract class Driver {
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Write the "name" item to the cache for 30 minutes
* Cache::driver()->put('name', 'Fred', 30);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
......@@ -68,11 +50,6 @@ abstract class Driver {
* Get an item from the cache. If the item doesn't exist in the cache, store
* the default value in the cache and return it.
*
* <code>
* // Get the "name" item from the cache or store "Fred" for 30 minutes
* $name = Cache::driver()->remember('name', 'Fred', 30);
* </code>
*
* @param string $key
* @param mixed $default
* @param int $minutes
......
......@@ -3,7 +3,7 @@
class File extends Driver {
/**
* The file manager instance.
* The file engine instance.
*
* @var Laravel\File
*/
......@@ -32,11 +32,6 @@ class File extends Driver {
/**
* Determine if an item exists in the cache.
*
* <code>
* // Determine if the "name" item exists in the cache
* $exists = Cache::driver()->has('name');
* </code>
*
* @param string $key
* @return bool
*/
......@@ -66,11 +61,6 @@ class File extends Driver {
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Write the "name" item to the cache for 30 minutes
* Cache::driver()->put('name', 'Fred', 30);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
......
......@@ -43,14 +43,6 @@ class Manager {
* If no driver name is specified, the default cache driver will be returned
* as defined in the cache configuration file.
*
* <code>
* // Get the default cache driver
* $driver = $application->cache->driver();
*
* // Get the APC cache driver
* $apc = $application->cache->driver('apc');
* </code>
*
* @param string $driver
* @return Cache\Driver
*/
......@@ -76,11 +68,6 @@ class Manager {
*
* Passing method calls to the driver instance provides a convenient API for the developer
* when always using the default cache driver.
*
* <code>
* // Get an item from the default cache driver
* $name = $application->cache->get('name');
* </code>
*/
public function __call($method, $parameters)
{
......
......@@ -34,11 +34,6 @@ class Memcached extends Driver {
/**
* Determine if an item exists in the cache.
*
* <code>
* // Determine if the "name" item exists in the cache
* $exists = Cache::driver()->has('name');
* </code>
*
* @param string $key
* @return bool
*/
......@@ -61,11 +56,6 @@ class Memcached extends Driver {
/**
* Write an item to the cache for a given number of minutes.
*
* <code>
* // Write the "name" item to the cache for 30 minutes
* Cache::driver()->put('name', 'Fred', 30);
* </code>
*
* @param string $key
* @param mixed $value
* @param int $minutes
......
......@@ -11,6 +11,24 @@ class Config {
*/
public $items = array();
/**
* The paths containing the configuration files.
*
* @var array
*/
public $paths = array();
/**
* Create a new configuration manager instance.
*
* @param array $paths
* @return void
*/
public function __construct($paths)
{
$this->paths = $paths;
}
/**
* Determine if a configuration item or file exists.
*
......@@ -101,7 +119,7 @@ class Config {
$config = array();
foreach ($this->paths() as $directory)
foreach ($this->paths as $directory)
{
$config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config;
}
......@@ -114,27 +132,4 @@ class Config {
return isset($this->items[$file]);
}
/**
* Get the path hierarchy for a given configuration file and module.
*
* The paths returned by this method paths will be searched by the load method when merging
* configuration files, meaning the configuration files will cascade in this order.
*
* The system configuration directory will be searched first, followed by the application
* directory, and finally the environment directory.
*
* @return array
*/
private function paths()
{
$paths = array(SYS_CONFIG_PATH, CONFIG_PATH);
if (isset($_SERVER['LARAVEL_ENV']))
{
$paths[] = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/';
}
return $paths;
}
}
\ No newline at end of file
......@@ -8,6 +8,25 @@ return array(
|--------------------------------------------------------------------------
*/
'laravel.config' => array('singleton' => true, 'resolver' => function($container)
{
$paths = array(SYS_CONFIG_PATH, CONFIG_PATH);
if (isset($_SERVER['LARAVEL_ENV']))
{
$paths[] = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/';
}
return new Config($paths);
}),
'laravel.cookie' => array('singleton' => true, 'resolver' => function()
{
return new Cookie($_COOKIE);
}),
'laravel.database' => array('singleton' => true, 'resolver' => function($container)
{
$config = $container->resolve('laravel.config');
......@@ -28,26 +47,44 @@ return array(
}),
'laravel.form' => array('resolver' => function($container)
{
list($request, $html, $url) = array(
$container->resolve('laravel.request'),
$container->resolve('laravel.html'),
$container->resolve('laravel.url'),
);
return new Form($request, $html, $url);
}),
'laravel.html' => array('resolver' => function($container)
{
return new HTML($container->resolve('laravel.url'), $container->resolve('laravel.config')->get('application.encoding'));
}),
'laravel.input' => array('singleton' => true, 'resolver' => function($container)
{
$application = $container->resolve('laravel.application');
$request = $container->resolve('laravel.request');
$input = array();
if ($application->request->method == 'GET')
if ($request->method() == 'GET')
{
$input = $_GET;
}
elseif ($application->request->method == 'POST')
elseif ($request->method() == 'POST')
{
$input = $_POST;
}
elseif ($application->request->method == 'PUT' or $application->request->method == 'DELETE')
elseif ($request->method() == 'PUT' or $request->method == 'DELETE')
{
($application->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, new Cookie($_COOKIE));
return new Input($input, $_FILES, $container->resolve('laravel.cookie'));
}),
......@@ -57,15 +94,29 @@ return array(
}),
'laravel.loader' => array('singleton' => true, 'resolver' => function($container)
{
$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/');
return new Loader($container->resolve('laravel.config')->get('aliases'), $paths);
}),
'laravel.package' => array('singleton' => true, 'resolver' => function()
{
return new Package;
return new Package(PACKAGE_PATH);
}),
'laravel.redirect' => array('singleton' => true, 'resolver' => function($container)
{
return new Redirect($container->resolve('laravel.session.driver'), $container->resolve('laravel.url'));
return new Redirect($container->resolve('laravel.url'));
}),
'laravel.request' => array('singleton' => true, 'resolver' => function($container)
{
return new Request($_SERVER, $_POST, $container->resolve('laravel.config')->get('application.url'));
}),
......@@ -83,15 +134,27 @@ return array(
}),
'laravel.url' => array('singleton' => true, 'resolver' => function($container)
'laravel.session' => array('singleton' => true, 'resolver' => function($container)
{
$request = $container->resolve('laravel.request');
return $container->resolve('laravel.session.manager')->driver($container->resolve('laravel.config')->get('session.driver'));
}),
'laravel.session.manager' => array('singleton' => true, 'resolver' => function($container)
{
return new Session\Manager($container);
}),
$base = $container->resolve('laravel.config')->get('application.url');
$index = $container->resolve('laravel.config')->get('application.index');
'laravel.url' => array('singleton' => true, 'resolver' => function($container)
{
list($request, $base, $index) = array(
$container->resolve('laravel.request'),
$container->resolve('laravel.config')->get('application.url'),
$container->resolve('laravel.config')->get('application.index'),
);
return new URL($container->resolve('laravel.router'), $base, $index, $request->secure);
return new URL($container->resolve('laravel.router'), $base, $index, $request->secure());
}),
......@@ -220,7 +283,7 @@ return array(
}),
'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function()
'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($container)
{
if ( ! class_exists('Memcache'))
{
......@@ -229,7 +292,7 @@ return array(
$memcache = new \Memcache;
foreach (Config::get('cache.servers') as $server)
foreach ($container->resolve('laravel.config')->get('cache.servers') as $server)
{
$memcache->addServer($server['host'], $server['port'], true, $server['weight']);
}
......
......@@ -12,6 +12,9 @@ class IoC {
/**
* Get the active container instance.
*
* The container is set early in the request cycle and can be access here for
* use as a service locator if dependency injection is not practical.
*
* @return Container
*/
public static function container()
......
<?php namespace Laravel;
abstract class Controller {
abstract class Controller extends Resolver {
/**
* A stub method that will be called before every request to the controller.
*
* If a value is returned by the method, it will be halt the request process
* If a value is returned by the method, it will be halt the request cycle
* and will be considered the response to the request.
*
* @return mixed
*/
public function before() {}
/**
* Magic Method for getting items from the application instance.
*/
public function __get($key)
{
return IoC::resolve('laravel.application')->$key;
}
/**
* Magic Method to handle calls to undefined functions on the controller.
*/
public function __call($method, $parameters)
{
return IoC::resolve('laravel.application')->responder->error('404');
}
public function __call($method, $parameters) { return $this->response->error('404'); }
}
\ No newline at end of file
......@@ -3,14 +3,14 @@
class Download extends Response {
/**
* The file manager instance.
* The file engine instance.
*
* @var File
*/
protected $file;
/**
* Create a new download generator instance.
* Create a new download engine instance.
*
* @param File $file
* @return void
......@@ -25,22 +25,25 @@ class Download extends Response {
*
* @param string $path
* @param string $name
* @param array $headers
* @return Response
*/
public function of($path, $name = null)
public function of($path, $name = null, $headers = array())
{
if (is_null($name)) $name = basename($path);
$response = parent::__construct($this->file->get($path));
$response->header('Content-Description', 'File Transfer');
$response->header('Content-Type', $this->file->mime($this->file->extension($path)));
$response->header('Content-Disposition', 'attachment; filename="'.$name.'"');
$response->header('Content-Transfer-Encoding', 'binary');
$response->header('Expires', 0);
$response->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
$response->header('Pragma', 'public');
$response->header('Content-Length', $this->file->size($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;
}
......
......@@ -10,7 +10,7 @@ class File {
private $mimes;
/**
* Create a new file manager instance.
* Create a new file engine instance.
*
* @param array $mimes
* @return void
......
......@@ -23,13 +23,6 @@ class Form {
*/
private $url;
/**
* The CSRF token for the session.
*
* @var string
*/
public $token;
/**
* All of the label names that have been created.
*
......@@ -44,31 +37,20 @@ class Form {
* Create a new form writer instance.
*
* @param Request $request
* @param string $token
* @param HTML $html
* @param URL $url
* @return void
*/
public function __construct(Request $request, HTML $html, URL $url, $token)
public function __construct(Request $request, HTML $html, URL $url)
{
$this->url = $url;
$this->html = $html;
$this->token = $token;
$this->request = $request;
}
/**
* Open a HTML form.
*
* <code>
* // Open a POST form for the current URI
* echo Form::open();
*
* // Open a POST form to a specified URI
* echo Form::open('user/login');
*
* // Open a PUT form to a specified URI
* echo Form::open('user/profile', 'put');
* </code>
*
* Note: If PUT or DELETE is specified as the form method, a hidden input field will be generated
* 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.
......@@ -118,7 +100,7 @@ class Form {
*/
private 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));
}
/**
......@@ -180,15 +162,21 @@ class Form {
*/
public function token()
{
return $this->input('hidden', 'csrf_token', $this->token);
return $this->input('hidden', 'csrf_token', $this->raw_token());
}
/**
* Create a HTML label element.
* Get the CSRF token for the current session.
*
* <code>
* echo Form::label('email', 'E-Mail Address');
* </code>
* @return string
*/
public function raw_token()
{
return IoC::container()->resolve('laravel.session')->get('csrf_token');
}
/**
* Create a HTML label element.
*
* @param string $name
* @param string $value
......@@ -208,14 +196,6 @@ class Form {
* 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.
*
* <code>
* // Generate a text type input element
* echo Form::input('text', 'email');
*
* // Generate a hidden type input element with a specified value
* echo Form::input('hidden', 'secret', 'This is a secret.');
* </code>
*
* @param string $name
* @param mixed $value
* @param array $attributes
......@@ -365,11 +345,6 @@ class Form {
/**
* Create a HTML select element.
*
* <code>
* // Generate a drop-down with the "S" item selected
* echo Form::select('sizes', array('L' => 'Large', 'S' => 'Small'), 'S');
* </code>
*
* @param string $name
* @param array $options
* @param string $selected
......
......@@ -144,14 +144,6 @@ class HTML {
*
* An array of parameters may be specified to fill in URI segment wildcards.
*
* <code>
* // Link to the "login" route
* echo HTML::link_to_route('login', 'Login');
*
* // Link to the "profile" route, which has a URI of "/profile/(:any)"
* echo HTML::link_to_route('profile', 'Profile', array('taylor'));
* </code>
*
* @param string $name
* @param string $title
* @param array $parameters
......@@ -330,14 +322,6 @@ class HTML {
* Magic Method for handling dynamic static methods.
*
* This method primarily handles dynamic calls to create links to named routes.
*
* <code>
* // Link to the "login" route
* echo HTML::link_to_login('Login');
*
* // Link to the "profile" route, which has a URI of "/profile/(:any)"
* echo HTML::link_to_profile('Profile', array('taylor'));
* </code>
*/
public function __call($method, $parameters)
{
......
......@@ -116,16 +116,8 @@ class Inflector {
/**
* Get the plural form of a word if the specified count is greater than one.
*
* <code>
* // Returns "friend"
* Inflector::plural_if('friend', 1);
*
* // Returns "friends"
* Inflector::plural_if('friend', 2);
* </code>
*
* @param string $value
* @param int $count
* @param int $count
* @return string
*/
public static function plural_if($value, $count)
......@@ -136,14 +128,6 @@ class Inflector {
/**
* Convert a word to its plural form.
*
* <code>
* // Returns "friends"
* Inflector::plural('friend');
*
* // Returns "children"
* Inflector::plural('child');
* </code>
*
* @param string $value
* @return string
*/
......@@ -157,14 +141,6 @@ class Inflector {
/**
* Convert a word to its singular form.
*
* <code>
* // Returns "friend"
* Inflector::singular('friends');
*
* // Returns "child"
* Inflector::singular('children');
* </code>
*
* @param string $value
* @return string
*/
......
......@@ -24,7 +24,7 @@ class Input {
public $post;
/**
* The cookie manager instance.
* The cookie engine instance.
*
* @var Cookie
*/
......@@ -82,7 +82,7 @@ class Input {
*
* @param string $key
* @param mixed $default
* @return string
* @return mixed
*/
public function get($key = null, $default = null)
{
......@@ -109,7 +109,7 @@ class Input {
*/
public function old($key = null, $default = null)
{
$driver = IoC::container()->resolve('laravel.session.driver');
$driver = IoC::container()->resolve('laravel.session');
return Arr::get($driver->get('laravel_old_input', array()), $key, $default);
}
......
......@@ -9,7 +9,7 @@ class Lang {
*
* @var array
*/
private static $lines = array();
private $lines = array();
/**
* The default language being used by the application.
......@@ -98,7 +98,7 @@ class Lang {
return ($default instanceof \Closure) ? call_user_func($default) : $default;
}
$line = Arr::get(static::$lines[$this->line_language.$file], $line, $default);
$line = Arr::get($this->lines[$this->line_language.$file], $line, $default);
foreach ($this->replacements as $key => $value)
{
......@@ -138,7 +138,7 @@ class Lang {
*/
private function load($file)
{
if (isset(static::$lines[$this->line_language.$file])) return;
if (isset($this->lines[$this->line_language.$file])) return;
$language = array();
......@@ -152,10 +152,10 @@ class Lang {
if (count($language) > 0)
{
static::$lines[$this->line_language.$file] = $language;
$this->lines[$this->line_language.$file] = $language;
}
return isset(static::$lines[$this->line_language.$file]);
return isset($this->lines[$this->line_language.$file]);
}
/**
......
......@@ -42,23 +42,14 @@ register_shutdown_function(function() use ($application)
// --------------------------------------------------------------
date_default_timezone_set($application->config->get('application.timezone'));
// --------------------------------------------------------------
// Initialize the request instance for the request.
// --------------------------------------------------------------
$application->request = new Request($_SERVER, $application->config->get('application.url'));
$application->container->instance('laravel.request', $application->request);
// --------------------------------------------------------------
// Load the session and session manager.
// --------------------------------------------------------------
if ($application->config->get('session.driver') !== '')
{
$application->session = Session\Manager::driver($application->container, $application->config->get('session.driver'));
$application->container->instance('laravel.session.driver', $application->session);
$cookie = $application->input->cookies->get('laravel_session');
$application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime'));
$application->session->start($cookie, $application->config->get('session.lifetime'));
}
// --------------------------------------------------------------
......@@ -76,7 +67,7 @@ unset($packages);
// --------------------------------------------------------------
// Route the request and get the response from the route.
// --------------------------------------------------------------
$route = $application->container->resolve('laravel.router')->route();
$route = $application->router->route();
if ( ! is_null($route))
{
......@@ -86,7 +77,7 @@ if ( ! is_null($route))
}
else
{
$response = new Error('404');
$response = $application->response->error('404');
}
// --------------------------------------------------------------
......@@ -97,7 +88,7 @@ $response->content = $response->render();
// --------------------------------------------------------------
// Close the session.
// --------------------------------------------------------------
if ( ! is_null($application->session))
if ($application->config->get('session.driver') !== '')
{
$application->session->close($application->input, $application->config->get('session'));
}
......
......@@ -7,14 +7,14 @@ class Loader {
*
* @var array
*/
public $paths;
private $paths;
/**
* All of the class aliases.
*
* @var array
*/
public $aliases;
private $aliases;
/**
* Bootstrap the auto-loader.
......@@ -49,7 +49,7 @@ class Loader {
{
if (file_exists($path = $directory.$file.EXT))
{
require $path;
require_once $path;
return;
}
......
......@@ -7,26 +7,18 @@ class Package {
*
* @var array
*/
public $loaded = array();
private $loaded = array();
/**
* Load a package or set of packages.
*
* The package name should correspond to a package directory for your application.
*
* <code>
* // Load the "swift-mailer" package
* Package::load('swift-mailer');
*
* // Load the "swift-mailer" and "facebook" package
* Package::load(array('swift-mailer', 'facebook'));
* </code>
*
* @param string|array $packages
* @param string $path
* @return void
*/
public function load($packages, $path = PACKAGE_PATH)
public function load($packages, $path)
{
foreach ((array) $packages as $package)
{
......@@ -42,11 +34,6 @@ class Package {
/**
* Determine if a given package has been loaded.
*
* <code>
* // Determine if the "swift-mailer" package has been loaded
* $loaded = Package::loaded('swift-mailer');
* </code>
*
* @param string $package
* @return bool
*/
......
......@@ -9,13 +9,6 @@ class Redirect extends Response {
*/
private $url;
/**
* The active session driver instance.
*
* @var Session\Driver
*/
private $session;
/**
* Create a new redirect generator instance.
*
......@@ -23,10 +16,9 @@ class Redirect extends Response {
* @param URL $url
* @return void
*/
public function __construct(Session\Driver $session, URL $url)
public function __construct(URL $url)
{
$this->url = $url;
$this->session = $session;
}
/**
......@@ -78,7 +70,7 @@ class Redirect extends Response {
*/
public function with($key, $value)
{
$this->session->flash($key, $value);
IoC::container()->resolve('laravel.session')->flash($key, $value);
return $this;
}
......
......@@ -3,85 +3,46 @@
class Request {
/**
* The request URI.
* The $_SERVER array for the request.
*
* @var string
* @var array
*/
public $uri;
public $server;
/**
* The request method (GET, POST, PUT, or DELETE).
* The $_POST array for the request.
*
* @var string
* @var array
*/
public $method;
private $post;
/**
* Indicates if the request method is being spoofed by a hidden form element.
* The route handling the current request.
*
* @var bool
* @var Routing\Route
*/
public $spoofed;
public $route;
/**
* The requestor's IP address.
* The base URL of the application.
*
* @var string
*/
public $ip;
/**
* Indicates if the request is using HTTPS.
*
* @var bool
*/
public $secure;
/**
* Indicates if the request is an AJAX request.
*
* @var bool
*/
public $ajax;
/**
* The input instance for the request.
*
* @var Input
*/
public $input;
/**
* The $_SERVER array for the request.
*
* @var array
*/
public $server;
/**
* The route handling the current request.
*
* @var Routing\Route
*/
public $route;
private $url;
/**
* Create a new request instance.
*
* @param array $server
* @param array $post
* @param string $url
* @return void
*/
public function __construct($server, $url)
public function __construct($server, $post, $url)
{
$this->url = $url;
$this->post = $post;
$this->server = $server;
$this->uri = $this->uri($url);
foreach (array('method', 'spoofed', 'ip', 'secure', 'ajax') as $item)
{
$this->$item = $this->$item();
}
}
/**
......@@ -94,10 +55,9 @@ class Request {
* to determine the URI using the REQUEST_URI variable. If neither are available, an exception
* will be thrown by the method.
*
* @param string $url
* @return string
*/
private function uri($url)
public function uri()
{
if (isset($this->server['PATH_INFO']))
{
......@@ -114,7 +74,7 @@ class Request {
if ($uri === false) throw new \Exception('Malformed request URI. Request terminated.');
foreach (array(parse_url($url, PHP_URL_PATH), '/index.php') as $value)
foreach (array(parse_url($this->url, PHP_URL_PATH), '/index.php') as $value)
{
$uri = (strpos($uri, $value) === 0) ? substr($uri, strlen($value)) : $uri;
}
......@@ -131,9 +91,9 @@ class Request {
*
* @return string
*/
private function method()
public function method()
{
return ($this->spoofed()) ? $_POST['REQUEST_METHOD'] : $this->server['REQUEST_METHOD'];
return ($this->spoofed()) ? $this->post['REQUEST_METHOD'] : $this->server['REQUEST_METHOD'];
}
/**
......@@ -143,9 +103,9 @@ class Request {
*
* @return bool
*/
private function spoofed()
public function spoofed()
{
return is_array($_POST) and array_key_exists('REQUEST_METHOD', $_POST);
return is_array($this->post) and array_key_exists('REQUEST_METHOD', $this->post);
}
/**
......@@ -153,7 +113,7 @@ class Request {
*
* @return string
*/
private function ip()
public function ip()
{
if (isset($this->server['HTTP_X_FORWARDED_FOR']))
{
......@@ -174,7 +134,7 @@ class Request {
*
* @return string
*/
private function protocol()
public function protocol()
{
return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http';
}
......@@ -184,7 +144,7 @@ class Request {
*
* @return bool
*/
private function secure()
public function secure()
{
return ($this->protocol() == 'https');
}
......@@ -194,7 +154,7 @@ class Request {
*
* @return bool
*/
private function ajax()
public function ajax()
{
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
......
......@@ -25,11 +25,12 @@ class Response_Factory {
*
* @param mixed $content
* @param int $status
* @param array $headers
* @return Response
*/
public function make($content, $status = 200)
public function make($content, $status = 200, $headers = array())
{
return new Response($content, $status);
return new Response($content, $status, $headers);
}
/**
......@@ -57,8 +58,6 @@ class Response_Factory {
*/
public function error($code, $data = array())
{
$data['homepage'] = IoC::resolve('laravel.config')->get('application.url');
return new Response($this->view->make('error/'.$code, $data), $code);
}
......@@ -146,14 +145,44 @@ class Response {
*
* @param mixed $content
* @param int $status
* @param array $headers
* @return void
*/
public function __construct($content, $status = 200)
public function __construct($content, $status = 200, $headers = array())
{
$this->content = $content;
$this->headers = $headers;
$this->status = $status;
}
/**
* Create a new response instance.
*
* @param mixed $content
* @param int $status
* @return Response
*/
public static function make($content, $status = 200)
{
return IoC::container()->resolve('laravel.response')->make($content, $status);
}
/**
* Create a new error response instance.
*
* The response status code will be set using the specified code.
*
* Note: The specified error code should correspond to a view in your views/error directory.
*
* @param int $code
* @param array $data
* @return Response
*/
public static function error($code, $data = array())
{
return IoC::container()->resolve('laravel.response')->error($code, $data);
}
/**
* Get the evaluated string contents of the response.
*
......
......@@ -51,14 +51,6 @@ class Router {
*
* The returned array will be identical the array defined in the routes.php file.
*
* <code>
* // Find the "login" named route
* $route = $router->find('login');
*
* // Find the "login" named route through the IoC container
* $route = IoC::resolve('laravel.routing.router')->find('login');
* </code>
*
* @param string $name
* @return array
*/
......@@ -92,7 +84,7 @@ class Router {
{
// Put the request method and URI in route form. Routes begin with
// the request method and a forward slash.
$destination = $this->request->method.' /'.trim($this->request->uri, '/');
$destination = $this->request->method().' /'.trim($this->request->uri(), '/');
// Check for a literal route match first. If we find one, there is
// no need to spin through all of the routes.
......@@ -129,7 +121,7 @@ class Router {
*/
protected function route_to_controller()
{
$segments = explode('/', trim($this->request->uri, '/'));
$segments = explode('/', trim($this->request->uri(), '/'));
if ( ! is_null($key = $this->controller_key($segments)))
{
......
......@@ -7,7 +7,7 @@ class Cookie extends Driver {
/**
* The cookie engine instance.
*
* @var Cookie_Engine
* @var Cookie
*/
private $cookie;
......
......@@ -67,11 +67,6 @@ abstract class Driver {
/**
* Determine if the session or flash data contains an item.
*
* <code>
* // Determine if "name" item exists in the session
* $exists = Session::driver()->has('name');
* </code>
*
* @param string $key
* @return bool
*/
......@@ -86,14 +81,6 @@ abstract class Driver {
* A default value may also be specified, and will be returned in the requested
* item does not exist in the session.
*
* <code>
* // Get the "name" item from the session
* $name = Session::driver()->get('name');
*
* // Get the "name" item from the session or return "Fred"
* $name = Session::driver()->get('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $default
* @return mixed
......@@ -111,11 +98,6 @@ abstract class Driver {
/**
* Write an item to the session.
*
* <code>
* // Write the "name" item to the session
* Session::driver()->put('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $value
* @return Driver
......@@ -133,11 +115,6 @@ abstract class Driver {
* Flash data only exists for the next request. After that, it will be removed from
* the session. Flash data is useful for temporary status or welcome messages.
*
* <code>
* // Write the "name" item to the session flash data
* Session::driver()->flash('name', 'Fred');
* </code>
*
* @param string $key
* @param mixed $value
* @return Driver
......@@ -152,11 +129,6 @@ abstract class Driver {
/**
* Remove an item from the session.
*
* <code>
* // Remove the "name" item from the session
* Session::driver()->forget('name');
* </code>
*
* @param string $key
* @return Driver
*/
......@@ -242,7 +214,7 @@ abstract class Driver {
* already been sent to the browser.
*
* @param Laravel\Cookie $cookie
* @param array $config
* @param array $config
* @return void
*/
protected function write_cookie(Cookie $cookies, $config)
......@@ -259,11 +231,6 @@ abstract class Driver {
/**
* Magic Method for retrieving items from the session.
*
* <code>
* // Get the "name" item from the session
* $name = $application->session->name;
* </code>
*/
public function __get($key)
{
......@@ -272,11 +239,6 @@ abstract class Driver {
/**
* Magic Method for writings items to the session.
*
* <code>
* // Write "Fred" to the session "name" item
* $application->session->name = 'Fred';
* </code>
*/
public function __set($key, $value)
{
......
......@@ -3,7 +3,7 @@
class File extends Driver implements Sweeper {
/**
* The file manager instance.
* The file engine instance.
*
* @var Laravel\File
*/
......
<?php namespace Laravel\Session;
use Laravel\Config;
use Laravel\Container;
class Manager {
/**
* The container instance.
*
* @var Container
*/
private $container;
/**
* Create a new session manager instance.
*
* @param Container $container
* @return void
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Get the session driver.
*
......@@ -12,15 +29,14 @@ class Manager {
* file. Only one session driver may be active for a given request, so the driver will
* be managed as a singleton.
*
* @param Container $container
* @param string $driver
* @return Session\Driver
*/
public static function driver(Container $container, $driver)
public function driver($driver)
{
if (in_array($driver, array('cookie', 'file', 'database', 'apc', 'memcached')))
{
return $container->resolve('laravel.session.'.$driver);
return $this->container->resolve('laravel.session.'.$driver);
}
throw new \Exception("Session driver [$driver] is not supported.");
......
......@@ -107,7 +107,7 @@ class Str {
*
* @return string
*/
private static function encoding()
public static function encoding()
{
return IoC::container()->resolve('laravel.config')->get('application.encoding');
}
......
......@@ -212,6 +212,18 @@ class View {
}
}
/**
* 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);
}
/**
* Get the evaluated string content of the view.
*
......
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