Commit 0ef96fb8 authored by Taylor Otwell's avatar Taylor Otwell

added facades and made other ioc improvements.

parent 501953f2
...@@ -29,7 +29,7 @@ return array( ...@@ -29,7 +29,7 @@ return array(
'Download' => 'Laravel\\Download', 'Download' => 'Laravel\\Download',
'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model',
'Error' => 'Laravel\\Error', 'Error' => 'Laravel\\Error',
'File' => 'Laravel\\File', 'File' => 'Laravel\\File_Facade',
'Form' => 'Laravel\\Form', 'Form' => 'Laravel\\Form',
'Hasher' => 'Laravel\\Security\\Hasher', 'Hasher' => 'Laravel\\Security\\Hasher',
'HTML' => 'Laravel\\HTML', 'HTML' => 'Laravel\\HTML',
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<h2><?php echo $apology; ?></h2> <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> </div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -2,27 +2,6 @@ ...@@ -2,27 +2,6 @@
class Application { class Application {
/**
* The active request instance.
*
* @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. * The application IoC container.
* *
......
...@@ -18,14 +18,6 @@ class Asset { ...@@ -18,14 +18,6 @@ class Asset {
* Containers provide a convenient method of grouping assets while maintaining * Containers provide a convenient method of grouping assets while maintaining
* expressive code and a clean API. * 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 * @param string $container
* @return Asset_Container * @return Asset_Container
*/ */
...@@ -44,14 +36,6 @@ class Asset { ...@@ -44,14 +36,6 @@ class Asset {
* *
* This provides a convenient API, allowing the develop to skip the "container" * This provides a convenient API, allowing the develop to skip the "container"
* method when using the default 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) public static function __callStatic($method, $parameters)
{ {
...@@ -101,14 +85,6 @@ class Asset_Container { ...@@ -101,14 +85,6 @@ class Asset_Container {
* only link to the registered asset after its dependencies have been linked. * only link to the registered asset after its dependencies have been linked.
* For example, you may wish to make jQuery UI dependent on jQuery. * 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 $name
* @param string $source * @param string $source
* @param array $dependencies * @param array $dependencies
...@@ -177,10 +153,6 @@ class Asset_Container { ...@@ -177,10 +153,6 @@ class Asset_Container {
/** /**
* Get the links to all of the registered CSS assets. * Get the links to all of the registered CSS assets.
* *
* <code>
* echo Asset::container()->styles();
* </code>
*
* @return string * @return string
*/ */
public function styles() public function styles()
...@@ -191,10 +163,6 @@ class Asset_Container { ...@@ -191,10 +163,6 @@ class Asset_Container {
/** /**
* Get the links to all of the registered JavaScript assets. * Get the links to all of the registered JavaScript assets.
* *
* <code>
* echo Asset::container()->scripts();
* </code>
*
* @return string * @return string
*/ */
public function scripts() public function scripts()
...@@ -225,10 +193,6 @@ class Asset_Container { ...@@ -225,10 +193,6 @@ class Asset_Container {
/** /**
* Get the link to a single registered CSS asset. * Get the link to a single registered CSS asset.
* *
* <code>
* echo Asset::container()->get_style('common');
* </code>
*
* @param string $name * @param string $name
* @return string * @return string
*/ */
...@@ -240,10 +204,6 @@ class Asset_Container { ...@@ -240,10 +204,6 @@ class Asset_Container {
/** /**
* Get the link to a single registered JavaScript asset. * Get the link to a single registered JavaScript asset.
* *
* <code>
* echo Asset::container()->get_script('jquery');
* </code>
*
* @param string $name * @param string $name
* @return string * @return string
*/ */
......
...@@ -40,38 +40,42 @@ require SYS_PATH.'application'.EXT; ...@@ -40,38 +40,42 @@ require SYS_PATH.'application'.EXT;
$application = new Application; $application = new Application;
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the configuration manager and auto-loader. // Load the configuration manager.
// -------------------------------------------------------------- // --------------------------------------------------------------
require SYS_PATH.'facade'.EXT;
require SYS_PATH.'loader'.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;
$application->config = new Config; // --------------------------------------------------------------
// Bootstrap the IoC container.
// --------------------------------------------------------------
require SYS_PATH.'container'.EXT;
$paths = array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'); $dependencies = require SYS_CONFIG_PATH.'container'.EXT;
$application->loader = new Loader($application->config->get('aliases'), $paths); if (file_exists($path = CONFIG_PATH.'container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
spl_autoload_register(array($application->loader, 'load')); if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = CONFIG_PATH.$_SERVER['LARAVEL_ENV'].'/container'.EXT))
{
$dependencies = array_merge($dependencies, require $path);
}
unset($paths); $application->container = new Container($dependencies);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Bootstrap the IoC container. // Load the auto-loader.
// -------------------------------------------------------------- // --------------------------------------------------------------
require SYS_PATH.'container'.EXT; spl_autoload_register(array($application->loader, 'load'));
$application->container = new Container($application->config->get('container'));
// -------------------------------------------------------------- // --------------------------------------------------------------
// Register the core application components in the container. // Register the application in the container.
// -------------------------------------------------------------- // --------------------------------------------------------------
$application->container->instance('laravel.application', $application); $application->container->instance('laravel.application', $application);
$application->container->instance('laravel.config', $application->config);
$application->container->instance('laravel.loader', $application->loader);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Set the IoC container instance for use as a service locator. // Set the IoC container instance for use as a service locator.
// -------------------------------------------------------------- // --------------------------------------------------------------
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
class File extends Driver { class File extends Driver {
/** /**
* The file manager instance. * The file engine instance.
* *
* @var Laravel\File * @var Laravel\File_Engine
*/ */
private $file; private $file;
...@@ -19,11 +19,11 @@ class File extends Driver { ...@@ -19,11 +19,11 @@ class File extends Driver {
/** /**
* Create a new File cache driver instance. * Create a new File cache driver instance.
* *
* @param Laravel\File $file * @param Laravel\File_Engine $file
* @param string $path * @param string $path
* @return void * @return void
*/ */
public function __construct(\Laravel\File $file, $path) public function __construct(\Laravel\File_Engine $file, $path)
{ {
$this->file = $file; $this->file = $file;
$this->path = $path; $this->path = $path;
......
...@@ -11,6 +11,24 @@ class Config { ...@@ -11,6 +11,24 @@ class Config {
*/ */
public $items = array(); 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. * Determine if a configuration item or file exists.
* *
...@@ -101,7 +119,7 @@ class Config { ...@@ -101,7 +119,7 @@ class Config {
$config = array(); $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; $config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config;
} }
...@@ -114,27 +132,4 @@ class Config { ...@@ -114,27 +132,4 @@ class Config {
return isset($this->items[$file]); 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( ...@@ -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) 'laravel.database' => array('singleton' => true, 'resolver' => function($container)
{ {
$config = $container->resolve('laravel.config'); $config = $container->resolve('laravel.config');
...@@ -24,48 +43,72 @@ return array( ...@@ -24,48 +43,72 @@ return array(
'laravel.file' => array('singleton' => true, 'resolver' => function($container) 'laravel.file' => array('singleton' => true, 'resolver' => function($container)
{ {
require_once SYS_PATH.'file'.EXT;
return new File($container->resolve('laravel.config')->get('mimes')); return new File($container->resolve('laravel.config')->get('mimes'));
}), }),
'laravel.input' => array('singleton' => true, 'resolver' => function($container) 'laravel.input' => array('singleton' => true, 'resolver' => function($container)
{ {
require_once SYS_PATH.'input'.EXT;
$application = $container->resolve('laravel.application'); $application = $container->resolve('laravel.application');
$input = array(); $input = array();
if ($application->request->method == 'GET') if ($application->request->method() == 'GET')
{ {
$input = $_GET; $input = $_GET;
} }
elseif ($application->request->method == 'POST') elseif ($application->request->method() == 'POST')
{ {
$input = $_POST; $input = $_POST;
} }
elseif ($application->request->method == 'PUT' or $application->request->method == 'DELETE') elseif ($application->request->method() == 'PUT' or $application->request->method == 'DELETE')
{ {
($application->request->spoofed) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input); ($application->request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input);
} }
return new Input($input, $_FILES, new Cookie($_COOKIE)); return new Input_Engine($input, $_FILES, $container->resolve('laravel.cookie'));
}), }),
'laravel.lang' => array('singleton' => true, 'resolver' => function($container) 'laravel.lang' => array('singleton' => true, 'resolver' => function($container)
{ {
return new Lang($container->resolve('laravel.config')->get('application.language'), array(SYS_LANG_PATH, LANG_PATH)); require_once SYS_PATH.'lang'.EXT;
return new Lang_Engine($container->resolve('laravel.config')->get('application.language'), array(SYS_LANG_PATH, LANG_PATH));
}),
'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() 'laravel.package' => array('singleton' => true, 'resolver' => function()
{ {
return new Package; return new Package_Engine(PACKAGE_PATH);
}), }),
'laravel.redirect' => array('singleton' => true, 'resolver' => function($container) 'laravel.redirect' => array('singleton' => true, 'resolver' => function($container)
{ {
return new Redirect($container->resolve('laravel.session.driver'), $container->resolve('laravel.url')); require_once SYS_PATH.'redirect'.EXT;
return new Redirect_Engine($container->resolve('laravel.url'));
}),
'laravel.request' => array('singleton' => true, 'resolver' => function($container)
{
require_once SYS_PATH.'request'.EXT;
return new Request_Engine($_SERVER, $container->resolve('laravel.config')->get('application.url'));
}), }),
...@@ -83,15 +126,29 @@ return array( ...@@ -83,15 +126,29 @@ 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'); 'laravel.url' => array('singleton' => true, 'resolver' => function($container)
{
require_once SYS_PATH.'url'.EXT;
$index = $container->resolve('laravel.config')->get('application.index'); 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_Engine($container->resolve('laravel.router'), $base, $index, $request->secure());
}), }),
......
<?php namespace Laravel; <?php namespace Laravel;
class Download_Facade extends Facade { public static $resolve = 'download'; }
class Download extends Response { class Download extends Response {
/** /**
* The file manager instance. * The file engine instance.
* *
* @var File * @var File
*/ */
protected $file; protected $file;
/** /**
* Create a new download generator instance. * Create a new download engine instance.
* *
* @param File $file * @param File $file
* @return void * @return void
......
<?php namespace Laravel;
abstract class Facade {
/**
* Magic Method that allows the calling of a class staticly. This provides a convenient API
* while still maintaining the benefits of dependency injection and testability of the class.
*
* Each facade has a "resolve" property that informs the base class of what it needs to resolve
* our of the IoC container each time an operation is called on the facade.
*/
public static function __callStatic($method, $parameters)
{
return call_user_func_array(array(IoC::container()->resolve('laravel.'.static::$resolve), $method), $parameters);
}
}
\ No newline at end of file
<?php namespace Laravel; <?php namespace Laravel;
class File_Facade extends Facade { public static $resolve = 'file'; }
class File { class File {
/** /**
......
...@@ -118,7 +118,7 @@ class Form { ...@@ -118,7 +118,7 @@ class Form {
*/ */
private function action($action, $https) 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));
} }
/** /**
......
<?php namespace Laravel; <?php namespace Laravel;
class Input { class Input extends Facade { public static $resolve = 'input'; }
class Input_Engine {
/** /**
* The applicable input for the request. * The applicable input for the request.
...@@ -24,7 +26,7 @@ class Input { ...@@ -24,7 +26,7 @@ class Input {
public $post; public $post;
/** /**
* The cookie manager instance. * The cookie engine instance.
* *
* @var Cookie * @var Cookie
*/ */
...@@ -82,7 +84,7 @@ class Input { ...@@ -82,7 +84,7 @@ class Input {
* *
* @param string $key * @param string $key
* @param mixed $default * @param mixed $default
* @return string * @return mixed
*/ */
public function get($key = null, $default = null) public function get($key = null, $default = null)
{ {
...@@ -109,7 +111,7 @@ class Input { ...@@ -109,7 +111,7 @@ class Input {
*/ */
public function old($key = null, $default = null) 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); return Arr::get($driver->get('laravel_old_input', array()), $key, $default);
} }
......
<?php namespace Laravel; <?php namespace Laravel;
class Lang { class Lang extends Facade { public static $resolve = 'lang'; }
class Lang_Engine {
/** /**
* All of the loaded language lines. * All of the loaded language lines.
...@@ -9,7 +11,7 @@ class Lang { ...@@ -9,7 +11,7 @@ class Lang {
* *
* @var array * @var array
*/ */
private static $lines = array(); private $lines = array();
/** /**
* The default language being used by the application. * The default language being used by the application.
...@@ -98,7 +100,7 @@ class Lang { ...@@ -98,7 +100,7 @@ class Lang {
return ($default instanceof \Closure) ? call_user_func($default) : $default; 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) foreach ($this->replacements as $key => $value)
{ {
...@@ -138,7 +140,7 @@ class Lang { ...@@ -138,7 +140,7 @@ class Lang {
*/ */
private function load($file) private function load($file)
{ {
if (isset(static::$lines[$this->line_language.$file])) return; if (isset($this->lines[$this->line_language.$file])) return;
$language = array(); $language = array();
...@@ -152,10 +154,10 @@ class Lang { ...@@ -152,10 +154,10 @@ class Lang {
if (count($language) > 0) 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,22 +42,11 @@ register_shutdown_function(function() use ($application) ...@@ -42,22 +42,11 @@ register_shutdown_function(function() use ($application)
// -------------------------------------------------------------- // --------------------------------------------------------------
date_default_timezone_set($application->config->get('application.timezone')); 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. // Load the session and session manager.
// -------------------------------------------------------------- // --------------------------------------------------------------
if ($application->config->get('session.driver') !== '') 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);
$application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime')); $application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime'));
} }
...@@ -76,7 +65,7 @@ unset($packages); ...@@ -76,7 +65,7 @@ unset($packages);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Route the request and get the response from the route. // 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)) if ( ! is_null($route))
{ {
...@@ -86,7 +75,7 @@ if ( ! is_null($route)) ...@@ -86,7 +75,7 @@ if ( ! is_null($route))
} }
else else
{ {
$response = new Error('404'); $response = $application->response->error('404');
} }
// -------------------------------------------------------------- // --------------------------------------------------------------
...@@ -97,7 +86,7 @@ $response->content = $response->render(); ...@@ -97,7 +86,7 @@ $response->content = $response->render();
// -------------------------------------------------------------- // --------------------------------------------------------------
// Close the session. // Close the session.
// -------------------------------------------------------------- // --------------------------------------------------------------
if ( ! is_null($application->session)) if ($application->config->get('session.driver') !== '')
{ {
$application->session->close($application->input, $application->config->get('session')); $application->session->close($application->input, $application->config->get('session'));
} }
......
...@@ -40,6 +40,8 @@ class Loader { ...@@ -40,6 +40,8 @@ class Loader {
{ {
$file = strtolower(str_replace('\\', '/', $class)); $file = strtolower(str_replace('\\', '/', $class));
if (strpos($file, 'laravel') !== false) $file = str_replace('_facade', '', $file);
if (array_key_exists($class, $this->aliases)) if (array_key_exists($class, $this->aliases))
{ {
return class_alias($this->aliases[$class], $class); return class_alias($this->aliases[$class], $class);
...@@ -49,7 +51,7 @@ class Loader { ...@@ -49,7 +51,7 @@ class Loader {
{ {
if (file_exists($path = $directory.$file.EXT)) if (file_exists($path = $directory.$file.EXT))
{ {
require $path; require_once $path;
return; return;
} }
......
<?php namespace Laravel; <?php namespace Laravel;
class Package { class Package extends Facade { public static $resolve = 'package'; }
class Package_Engine {
/** /**
* All of the loaded packages. * All of the loaded packages.
...@@ -14,19 +16,11 @@ class Package { ...@@ -14,19 +16,11 @@ class Package {
* *
* The package name should correspond to a package directory for your application. * 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|array $packages
* @param string $path * @param string $path
* @return void * @return void
*/ */
public function load($packages, $path = PACKAGE_PATH) public function load($packages, $path)
{ {
foreach ((array) $packages as $package) foreach ((array) $packages as $package)
{ {
...@@ -42,11 +36,6 @@ class Package { ...@@ -42,11 +36,6 @@ class Package {
/** /**
* Determine if a given package has been loaded. * 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 * @param string $package
* @return bool * @return bool
*/ */
......
<?php namespace Laravel; <?php namespace Laravel;
class Redirect extends Response { class Redirect extends Facade { public static $resolve = 'redirect'; }
class Redirect_Engine extends Response {
/** /**
* The URL generator instance. * The URL generator instance.
...@@ -9,13 +11,6 @@ class Redirect extends Response { ...@@ -9,13 +11,6 @@ class Redirect extends Response {
*/ */
private $url; private $url;
/**
* The active session driver instance.
*
* @var Session\Driver
*/
private $session;
/** /**
* Create a new redirect generator instance. * Create a new redirect generator instance.
* *
...@@ -23,10 +18,9 @@ class Redirect extends Response { ...@@ -23,10 +18,9 @@ class Redirect extends Response {
* @param URL $url * @param URL $url
* @return void * @return void
*/ */
public function __construct(Session\Driver $session, URL $url) public function __construct(URL $url)
{ {
$this->url = $url; $this->url = $url;
$this->session = $session;
} }
/** /**
...@@ -78,7 +72,7 @@ class Redirect extends Response { ...@@ -78,7 +72,7 @@ class Redirect extends Response {
*/ */
public function with($key, $value) public function with($key, $value)
{ {
$this->session->flash($key, $value); IoC::container()->resolve('laravel.session')->flash($key, $value);
return $this; return $this;
} }
......
<?php namespace Laravel; <?php namespace Laravel;
class Request { class Request extends Facade { public static $resolve = 'request'; }
/** class Request_Engine {
* The request URI.
*
* @var string
*/
public $uri;
/**
* The request method (GET, POST, PUT, or DELETE).
*
* @var string
*/
public $method;
/**
* Indicates if the request method is being spoofed by a hidden form element.
*
* @var bool
*/
public $spoofed;
/**
* The requestor's IP address.
*
* @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. * The $_SERVER array for the request.
...@@ -65,6 +18,13 @@ class Request { ...@@ -65,6 +18,13 @@ class Request {
*/ */
public $route; public $route;
/**
* The base URL of the application.
*
* @var string
*/
private $url;
/** /**
* Create a new request instance. * Create a new request instance.
* *
...@@ -74,14 +34,8 @@ class Request { ...@@ -74,14 +34,8 @@ class Request {
*/ */
public function __construct($server, $url) public function __construct($server, $url)
{ {
$this->url = $url;
$this->server = $server; $this->server = $server;
$this->uri = $this->uri($url);
foreach (array('method', 'spoofed', 'ip', 'secure', 'ajax') as $item)
{
$this->$item = $this->$item();
}
} }
/** /**
...@@ -94,10 +48,9 @@ class Request { ...@@ -94,10 +48,9 @@ class Request {
* to determine the URI using the REQUEST_URI variable. If neither are available, an exception * to determine the URI using the REQUEST_URI variable. If neither are available, an exception
* will be thrown by the method. * will be thrown by the method.
* *
* @param string $url
* @return string * @return string
*/ */
private function uri($url) public function uri()
{ {
if (isset($this->server['PATH_INFO'])) if (isset($this->server['PATH_INFO']))
{ {
...@@ -114,7 +67,7 @@ class Request { ...@@ -114,7 +67,7 @@ class Request {
if ($uri === false) throw new \Exception('Malformed request URI. Request terminated.'); 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; $uri = (strpos($uri, $value) === 0) ? substr($uri, strlen($value)) : $uri;
} }
...@@ -131,7 +84,7 @@ class Request { ...@@ -131,7 +84,7 @@ class Request {
* *
* @return string * @return string
*/ */
private function method() public function method()
{ {
return ($this->spoofed()) ? $_POST['REQUEST_METHOD'] : $this->server['REQUEST_METHOD']; return ($this->spoofed()) ? $_POST['REQUEST_METHOD'] : $this->server['REQUEST_METHOD'];
} }
...@@ -143,7 +96,7 @@ class Request { ...@@ -143,7 +96,7 @@ class Request {
* *
* @return bool * @return bool
*/ */
private function spoofed() public function spoofed()
{ {
return is_array($_POST) and array_key_exists('REQUEST_METHOD', $_POST); return is_array($_POST) and array_key_exists('REQUEST_METHOD', $_POST);
} }
...@@ -153,7 +106,7 @@ class Request { ...@@ -153,7 +106,7 @@ class Request {
* *
* @return string * @return string
*/ */
private function ip() public function ip()
{ {
if (isset($this->server['HTTP_X_FORWARDED_FOR'])) if (isset($this->server['HTTP_X_FORWARDED_FOR']))
{ {
...@@ -174,7 +127,7 @@ class Request { ...@@ -174,7 +127,7 @@ class Request {
* *
* @return string * @return string
*/ */
private function protocol() public function protocol()
{ {
return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http'; return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http';
} }
...@@ -184,7 +137,7 @@ class Request { ...@@ -184,7 +137,7 @@ class Request {
* *
* @return bool * @return bool
*/ */
private function secure() public function secure()
{ {
return ($this->protocol() == 'https'); return ($this->protocol() == 'https');
} }
...@@ -194,7 +147,7 @@ class Request { ...@@ -194,7 +147,7 @@ class Request {
* *
* @return bool * @return bool
*/ */
private function ajax() public function ajax()
{ {
if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false; if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false;
......
...@@ -57,8 +57,6 @@ class Response_Factory { ...@@ -57,8 +57,6 @@ class Response_Factory {
*/ */
public function error($code, $data = array()) 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); return new Response($this->view->make('error/'.$code, $data), $code);
} }
...@@ -154,6 +152,34 @@ class Response { ...@@ -154,6 +152,34 @@ class Response {
$this->status = $status; $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. * Get the evaluated string contents of the response.
* *
......
<?php namespace Laravel\Routing; <?php namespace Laravel\Routing;
use Laravel\Request; use Laravel\Request_Engine;
class Router { class Router {
...@@ -14,7 +14,7 @@ class Router { ...@@ -14,7 +14,7 @@ class Router {
/** /**
* The current request instance. * The current request instance.
* *
* @var Request * @var Request_Engine
*/ */
protected $request; protected $request;
...@@ -35,11 +35,11 @@ class Router { ...@@ -35,11 +35,11 @@ class Router {
/** /**
* Create a new router for a request method and URI. * Create a new router for a request method and URI.
* *
* @param Request $request * @param Request_Engine $request
* @param array $routes * @param array $routes
* @return void * @return void
*/ */
public function __construct(Request $request, $routes, $controller_path) public function __construct(Request_Engine $request, $routes, $controller_path)
{ {
$this->routes = $routes; $this->routes = $routes;
$this->request = $request; $this->request = $request;
...@@ -51,14 +51,6 @@ class Router { ...@@ -51,14 +51,6 @@ class Router {
* *
* The returned array will be identical the array defined in the routes.php file. * 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 * @param string $name
* @return array * @return array
*/ */
...@@ -92,7 +84,7 @@ class Router { ...@@ -92,7 +84,7 @@ class Router {
{ {
// Put the request method and URI in route form. Routes begin with // Put the request method and URI in route form. Routes begin with
// the request method and a forward slash. // 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 // Check for a literal route match first. If we find one, there is
// no need to spin through all of the routes. // no need to spin through all of the routes.
...@@ -129,7 +121,7 @@ class Router { ...@@ -129,7 +121,7 @@ class Router {
*/ */
protected function route_to_controller() 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))) if ( ! is_null($key = $this->controller_key($segments)))
{ {
......
...@@ -7,7 +7,7 @@ class Cookie extends Driver { ...@@ -7,7 +7,7 @@ class Cookie extends Driver {
/** /**
* The cookie engine instance. * The cookie engine instance.
* *
* @var Cookie_Engine * @var Cookie
*/ */
private $cookie; private $cookie;
...@@ -28,9 +28,9 @@ class Cookie extends Driver { ...@@ -28,9 +28,9 @@ class Cookie extends Driver {
/** /**
* Create a new Cookie session driver instance. * Create a new Cookie session driver instance.
* *
* @param Crypter $crypter * @param Crypter $crypter
* @param Laravel\Cookie $cookie * @param Laravel\Cookie $cookie
* @param array $config * @param array $config
* @return void * @return void
*/ */
public function __construct(Crypter $crypter, \Laravel\Cookie $cookie, $config) public function __construct(Crypter $crypter, \Laravel\Cookie $cookie, $config)
......
<?php namespace Laravel\Session; <?php namespace Laravel\Session;
use Laravel\Str; use Laravel\Str;
use Laravel\Input; use Laravel\Input_Engine;
use Laravel\Cookie; use Laravel\Cookie;
abstract class Driver { abstract class Driver {
...@@ -196,11 +196,11 @@ abstract class Driver { ...@@ -196,11 +196,11 @@ abstract class Driver {
* The input of the current request will also be flashed to the session so it is * The input of the current request will also be flashed to the session so it is
* 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_Engine $input
* @param array $config * @param array $config
* @return void * @return void
*/ */
public function close(Input $input, $config) public function close(Input_Engine $input, $config)
{ {
$this->flash('laravel_old_input', $input->get())->age(); $this->flash('laravel_old_input', $input->get())->age();
...@@ -242,7 +242,7 @@ abstract class Driver { ...@@ -242,7 +242,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)
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
class File extends Driver implements Sweeper { class File extends Driver implements Sweeper {
/** /**
* The file manager instance. * The file engine instance.
* *
* @var Laravel\File * @var Laravel\File_Engine
*/ */
private $file; private $file;
...@@ -19,11 +19,11 @@ class File extends Driver implements Sweeper { ...@@ -19,11 +19,11 @@ class File extends Driver implements Sweeper {
/** /**
* Create a new File session driver instance. * Create a new File session driver instance.
* *
* @param Laravel\File $file * @param Laravel\File_Engine $file
* @param string $path * @param string $path
* @return void * @return void
*/ */
public function __construct(\Laravel\File $file, $path) public function __construct(\Laravel\File_Engine $file, $path)
{ {
$this->file = $file; $this->file = $file;
$this->path = $path; $this->path = $path;
......
<?php namespace Laravel\Session; <?php namespace Laravel\Session;
use Laravel\Config;
use Laravel\Container; use Laravel\Container;
class Manager { 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. * Get the session driver.
* *
...@@ -12,15 +29,14 @@ class Manager { ...@@ -12,15 +29,14 @@ class Manager {
* file. Only one session driver may be active for a given request, so the driver will * file. Only one session driver may be active for a given request, so the driver will
* be managed as a singleton. * be managed as a singleton.
* *
* @param Container $container
* @param string $driver * @param string $driver
* @return Session\Driver * @return Session\Driver
*/ */
public static function driver(Container $container, $driver) public static function driver($driver)
{ {
if (in_array($driver, array('cookie', 'file', 'database', 'apc', 'memcached'))) 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."); throw new \Exception("Session driver [$driver] is not supported.");
......
<?php namespace Laravel; <?php namespace Laravel;
class URL { class URL extends Facade { public static $resolve = 'url'; }
class URL_Engine {
/** /**
* Create a new URL writer instance. * Create a new URL writer instance.
......
...@@ -212,6 +212,18 @@ class View { ...@@ -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. * 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