From 0ef96fb8d0c634c41aad1990e14d63d5a87cd2eb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 30 Aug 2011 22:09:47 -0500 Subject: [PATCH 1/3] added facades and made other ioc improvements. --- application/config/aliases.php | 2 +- application/views/error/404.php | 2 +- laravel/application.php | 21 --------- laravel/asset.php | 40 ---------------- laravel/bootstrap.php | 38 ++++++++------- laravel/cache/file.php | 10 ++-- laravel/config.php | 43 ++++++++--------- laravel/config/container.php | 83 +++++++++++++++++++++++++++------ laravel/download.php | 6 ++- laravel/facade.php | 17 +++++++ laravel/file.php | 2 + laravel/form.php | 2 +- laravel/input.php | 10 ++-- laravel/lang.php | 14 +++--- laravel/laravel.php | 17 ++----- laravel/loader.php | 4 +- laravel/package.php | 19 ++------ laravel/redirect.php | 16 ++----- laravel/request.php | 83 +++++++-------------------------- laravel/response.php | 30 +++++++++++- laravel/routing/router.php | 22 +++------ laravel/session/cookie.php | 6 +-- laravel/session/driver.php | 10 ++-- laravel/session/file.php | 10 ++-- laravel/session/manager.php | 24 ++++++++-- laravel/url.php | 4 +- laravel/view.php | 12 +++++ 27 files changed, 271 insertions(+), 276 deletions(-) create mode 100644 laravel/facade.php diff --git a/application/config/aliases.php b/application/config/aliases.php index 6442e1b3..7338cf1b 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -29,7 +29,7 @@ 'Download' => 'Laravel\\Download', 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', 'Error' => 'Laravel\\Error', - 'File' => 'Laravel\\File', + 'File' => 'Laravel\\File_Facade', 'Form' => 'Laravel\\Form', 'Hasher' => 'Laravel\\Security\\Hasher', 'HTML' => 'Laravel\\HTML', diff --git a/application/views/error/404.php b/application/views/error/404.php index 0b5a5a59..3d497472 100644 --- a/application/views/error/404.php +++ b/application/views/error/404.php @@ -81,7 +81,7 @@

-

We couldn't find the resource you requested. Would you like go to our home page instead?

+

We couldn't find the resource you requested. Would you like go to our home page instead?

\ No newline at end of file diff --git a/laravel/application.php b/laravel/application.php index cedd7f60..c272e6c1 100644 --- a/laravel/application.php +++ b/laravel/application.php @@ -2,27 +2,6 @@ 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. * diff --git a/laravel/asset.php b/laravel/asset.php index eaf5c0b1..7400a9b7 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -18,14 +18,6 @@ class Asset { * Containers provide a convenient method of grouping assets while maintaining * expressive code and a clean API. * - * - * // Get the default asset container - * $container = Asset::container(); - * - * // Get the "footer" asset container - * $container = Asset::container('footer'); - * - * * @param string $container * @return Asset_Container */ @@ -44,14 +36,6 @@ public static function container($container = 'default') * * This provides a convenient API, allowing the develop to skip the "container" * method when using the default container. - * - * - * // 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'); - * */ public static function __callStatic($method, $parameters) { @@ -101,14 +85,6 @@ public function __construct($name) * only link to the registered asset after its dependencies have been linked. * For example, you may wish to make jQuery UI dependent on jQuery. * - * - * // 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')); - * - * * @param string $name * @param string $source * @param array $dependencies @@ -177,10 +153,6 @@ private function register($type, $name, $source, $dependencies, $attributes) /** * Get the links to all of the registered CSS assets. * - * - * echo Asset::container()->styles(); - * - * * @return string */ public function styles() @@ -191,10 +163,6 @@ public function styles() /** * Get the links to all of the registered JavaScript assets. * - * - * echo Asset::container()->scripts(); - * - * * @return string */ public function scripts() @@ -225,10 +193,6 @@ private function get_group($group) /** * Get the link to a single registered CSS asset. * - * - * echo Asset::container()->get_style('common'); - * - * * @param string $name * @return string */ @@ -240,10 +204,6 @@ public function get_style($name) /** * Get the link to a single registered JavaScript asset. * - * - * echo Asset::container()->get_script('jquery'); - * - * * @param string $name * @return string */ diff --git a/laravel/bootstrap.php b/laravel/bootstrap.php index d9940bc4..78dd34eb 100644 --- a/laravel/bootstrap.php +++ b/laravel/bootstrap.php @@ -40,38 +40,42 @@ $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.'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; + +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); // -------------------------------------------------------------- -// Register the core application components in the container. +// Load the auto-loader. +// -------------------------------------------------------------- +spl_autoload_register(array($application->loader, 'load')); + +// -------------------------------------------------------------- +// Register the application in the container. // -------------------------------------------------------------- $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. // -------------------------------------------------------------- diff --git a/laravel/cache/file.php b/laravel/cache/file.php index 8dcb0971..05e49137 100644 --- a/laravel/cache/file.php +++ b/laravel/cache/file.php @@ -3,9 +3,9 @@ class File extends Driver { /** - * The file manager instance. + * The file engine instance. * - * @var Laravel\File + * @var Laravel\File_Engine */ private $file; @@ -19,11 +19,11 @@ class File extends Driver { /** * Create a new File cache driver instance. * - * @param Laravel\File $file - * @param string $path + * @param Laravel\File_Engine $file + * @param string $path * @return void */ - public function __construct(\Laravel\File $file, $path) + public function __construct(\Laravel\File_Engine $file, $path) { $this->file = $file; $this->path = $path; diff --git a/laravel/config.php b/laravel/config.php index 8afd84e7..3a7d78c7 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -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 @@ private function load($file) $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 @@ private function load($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 diff --git a/laravel/config/container.php b/laravel/config/container.php index 334675f3..7cd8cb49 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -8,6 +8,25 @@ |-------------------------------------------------------------------------- */ + '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'); @@ -24,48 +43,72 @@ 'laravel.file' => array('singleton' => true, 'resolver' => function($container) { + require_once SYS_PATH.'file'.EXT; + return new File($container->resolve('laravel.config')->get('mimes')); }), 'laravel.input' => array('singleton' => true, 'resolver' => function($container) { + require_once SYS_PATH.'input'.EXT; + $application = $container->resolve('laravel.application'); $input = array(); - if ($application->request->method == 'GET') + if ($application->request->method() == 'GET') { $input = $_GET; } - elseif ($application->request->method == 'POST') + elseif ($application->request->method() == '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) { - 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() { - return new Package; + return new Package_Engine(PACKAGE_PATH); }), '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 @@ }), + 'laravel.session' => array('singleton' => true, 'resolver' => function($container) + { + 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); + }), + + 'laravel.url' => array('singleton' => true, 'resolver' => function($container) { - $request = $container->resolve('laravel.request'); + require_once SYS_PATH.'url'.EXT; - $base = $container->resolve('laravel.config')->get('application.url'); + list($request, $base, $index) = array( + $container->resolve('laravel.request'), + $container->resolve('laravel.config')->get('application.url'), + $container->resolve('laravel.config')->get('application.index'), + ); - $index = $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()); }), diff --git a/laravel/download.php b/laravel/download.php index 3edf1f22..076afbab 100644 --- a/laravel/download.php +++ b/laravel/download.php @@ -1,16 +1,18 @@ resolve('laravel.'.static::$resolve), $method), $parameters); + } + +} \ No newline at end of file diff --git a/laravel/file.php b/laravel/file.php index 1b678810..41a084b9 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -1,5 +1,7 @@ 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)); } /** diff --git a/laravel/input.php b/laravel/input.php index ff5a229f..36a6cb4c 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -1,6 +1,8 @@ resolve('laravel.session.driver'); + $driver = IoC::container()->resolve('laravel.session'); return Arr::get($driver->get('laravel_old_input', array()), $key, $default); } diff --git a/laravel/lang.php b/laravel/lang.php index 0cb9dc32..a358ffcb 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -1,6 +1,8 @@ line_language.$file], $line, $default); + $line = Arr::get($this->lines[$this->line_language.$file], $line, $default); foreach ($this->replacements as $key => $value) { @@ -138,7 +140,7 @@ private function parse($key) */ 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 +154,10 @@ private function load($file) 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]); } /** diff --git a/laravel/laravel.php b/laravel/laravel.php index 09617eee..d4d52ea1 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -42,22 +42,11 @@ // -------------------------------------------------------------- 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); - $application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime')); } @@ -76,7 +65,7 @@ // -------------------------------------------------------------- // 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 +75,7 @@ } else { - $response = new Error('404'); + $response = $application->response->error('404'); } // -------------------------------------------------------------- @@ -97,7 +86,7 @@ // -------------------------------------------------------------- // Close the session. // -------------------------------------------------------------- -if ( ! is_null($application->session)) +if ($application->config->get('session.driver') !== '') { $application->session->close($application->input, $application->config->get('session')); } diff --git a/laravel/loader.php b/laravel/loader.php index ebc4f6c2..2a7a4a7f 100644 --- a/laravel/loader.php +++ b/laravel/loader.php @@ -40,6 +40,8 @@ public function load($class) { $file = strtolower(str_replace('\\', '/', $class)); + if (strpos($file, 'laravel') !== false) $file = str_replace('_facade', '', $file); + if (array_key_exists($class, $this->aliases)) { return class_alias($this->aliases[$class], $class); @@ -49,7 +51,7 @@ public function load($class) { if (file_exists($path = $directory.$file.EXT)) { - require $path; + require_once $path; return; } diff --git a/laravel/package.php b/laravel/package.php index f77beb81..1a502d5b 100644 --- a/laravel/package.php +++ b/laravel/package.php @@ -1,6 +1,8 @@ - * // Load the "swift-mailer" package - * Package::load('swift-mailer'); - * - * // Load the "swift-mailer" and "facebook" package - * Package::load(array('swift-mailer', 'facebook')); - * - * * @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 +36,6 @@ public function load($packages, $path = PACKAGE_PATH) /** * Determine if a given package has been loaded. * - * - * // Determine if the "swift-mailer" package has been loaded - * $loaded = Package::loaded('swift-mailer'); - * - * * @param string $package * @return bool */ diff --git a/laravel/redirect.php b/laravel/redirect.php index dd335fa9..a8bfcac8 100644 --- a/laravel/redirect.php +++ b/laravel/redirect.php @@ -1,6 +1,8 @@ url = $url; - $this->session = $session; } /** @@ -78,7 +72,7 @@ public function to_secure($url, $status = 302, $method = 'location') */ public function with($key, $value) { - $this->session->flash($key, $value); + IoC::container()->resolve('laravel.session')->flash($key, $value); return $this; } diff --git a/laravel/request.php b/laravel/request.php index 3dfcb6d4..7da5736f 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -1,55 +1,8 @@ url = $url; $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 @@ public function __construct($server, $url) * 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 +67,7 @@ private function uri($url) 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,7 +84,7 @@ private function uri($url) * * @return string */ - private function method() + public function method() { return ($this->spoofed()) ? $_POST['REQUEST_METHOD'] : $this->server['REQUEST_METHOD']; } @@ -143,7 +96,7 @@ private function method() * * @return bool */ - private function spoofed() + public function spoofed() { return is_array($_POST) and array_key_exists('REQUEST_METHOD', $_POST); } @@ -153,7 +106,7 @@ private function spoofed() * * @return string */ - private function ip() + public function ip() { if (isset($this->server['HTTP_X_FORWARDED_FOR'])) { @@ -174,7 +127,7 @@ private function ip() * * @return string */ - private function protocol() + public function protocol() { return (isset($this->server['HTTPS']) and $this->server['HTTPS'] !== 'off') ? 'https' : 'http'; } @@ -184,7 +137,7 @@ private function protocol() * * @return bool */ - private function secure() + public function secure() { return ($this->protocol() == 'https'); } @@ -194,7 +147,7 @@ private function secure() * * @return bool */ - private function ajax() + public function ajax() { if ( ! isset($this->server['HTTP_X_REQUESTED_WITH'])) return false; diff --git a/laravel/response.php b/laravel/response.php index fcbc7996..d542d1ca 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -57,8 +57,6 @@ public function view($view, $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); } @@ -154,6 +152,34 @@ public function __construct($content, $status = 200) $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. * diff --git a/laravel/routing/router.php b/laravel/routing/router.php index 715d2007..ce2148e2 100644 --- a/laravel/routing/router.php +++ b/laravel/routing/router.php @@ -1,6 +1,6 @@ routes = $routes; $this->request = $request; @@ -51,14 +51,6 @@ public function __construct(Request $request, $routes, $controller_path) * * The returned array will be identical the array defined in the routes.php file. * - * - * // 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'); - * - * * @param string $name * @return array */ @@ -92,7 +84,7 @@ public function route() { // 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 @@ public function route() */ 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))) { diff --git a/laravel/session/cookie.php b/laravel/session/cookie.php index e576a2c4..9e8dc735 100644 --- a/laravel/session/cookie.php +++ b/laravel/session/cookie.php @@ -7,7 +7,7 @@ class Cookie extends Driver { /** * The cookie engine instance. * - * @var Cookie_Engine + * @var Cookie */ private $cookie; @@ -28,9 +28,9 @@ class Cookie extends Driver { /** * Create a new Cookie session driver instance. * - * @param Crypter $crypter + * @param Crypter $crypter * @param Laravel\Cookie $cookie - * @param array $config + * @param array $config * @return void */ public function __construct(Crypter $crypter, \Laravel\Cookie $cookie, $config) diff --git a/laravel/session/driver.php b/laravel/session/driver.php index 3025dbcf..ac8b3943 100644 --- a/laravel/session/driver.php +++ b/laravel/session/driver.php @@ -1,7 +1,7 @@ flash('laravel_old_input', $input->get())->age(); @@ -242,7 +242,7 @@ protected function age() * 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) diff --git a/laravel/session/file.php b/laravel/session/file.php index c027b16b..4f8eb9c4 100644 --- a/laravel/session/file.php +++ b/laravel/session/file.php @@ -3,9 +3,9 @@ class File extends Driver implements Sweeper { /** - * The file manager instance. + * The file engine instance. * - * @var Laravel\File + * @var Laravel\File_Engine */ private $file; @@ -19,11 +19,11 @@ class File extends Driver implements Sweeper { /** * Create a new File session driver instance. * - * @param Laravel\File $file - * @param string $path + * @param Laravel\File_Engine $file + * @param string $path * @return void */ - public function __construct(\Laravel\File $file, $path) + public function __construct(\Laravel\File_Engine $file, $path) { $this->file = $file; $this->path = $path; diff --git a/laravel/session/manager.php b/laravel/session/manager.php index df126cd4..688410b3 100644 --- a/laravel/session/manager.php +++ b/laravel/session/manager.php @@ -1,10 +1,27 @@ 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 static 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."); diff --git a/laravel/url.php b/laravel/url.php index 76fd08d7..b9e80751 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -1,6 +1,8 @@ resolve('laravel.view')->make($view, $data); + } + /** * Get the evaluated string content of the view. * From c200f3eb1e966b6653c4d48acc4ec805e044cd3f Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 30 Aug 2011 22:35:32 -0500 Subject: [PATCH 2/3] more ioc refactoring. --- application/config/aliases.php | 2 +- laravel/bootstrap.php | 1 - laravel/cache/file.php | 18 ++++-------------- laravel/config/container.php | 24 ++++++------------------ laravel/download.php | 2 -- laravel/facade.php | 17 ----------------- laravel/file.php | 4 +--- laravel/inflector.php | 26 +------------------------- laravel/input.php | 4 +--- laravel/lang.php | 4 +--- laravel/laravel.php | 4 +++- laravel/loader.php | 2 -- laravel/package.php | 4 +--- laravel/redirect.php | 4 +--- laravel/request.php | 4 +--- laravel/routing/router.php | 10 +++++----- laravel/session/file.php | 8 ++++---- laravel/url.php | 4 +--- 18 files changed, 31 insertions(+), 111 deletions(-) delete mode 100644 laravel/facade.php diff --git a/application/config/aliases.php b/application/config/aliases.php index 7338cf1b..6442e1b3 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -29,7 +29,7 @@ 'Download' => 'Laravel\\Download', 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', 'Error' => 'Laravel\\Error', - 'File' => 'Laravel\\File_Facade', + 'File' => 'Laravel\\File', 'Form' => 'Laravel\\Form', 'Hasher' => 'Laravel\\Security\\Hasher', 'HTML' => 'Laravel\\HTML', diff --git a/laravel/bootstrap.php b/laravel/bootstrap.php index 78dd34eb..20ec4d6c 100644 --- a/laravel/bootstrap.php +++ b/laravel/bootstrap.php @@ -42,7 +42,6 @@ // -------------------------------------------------------------- // Load the configuration manager. // -------------------------------------------------------------- -require SYS_PATH.'facade'.EXT; require SYS_PATH.'loader'.EXT; require SYS_PATH.'config'.EXT; require SYS_PATH.'arr'.EXT; diff --git a/laravel/cache/file.php b/laravel/cache/file.php index 05e49137..8c7c98ed 100644 --- a/laravel/cache/file.php +++ b/laravel/cache/file.php @@ -5,7 +5,7 @@ class File extends Driver { /** * The file engine instance. * - * @var Laravel\File_Engine + * @var Laravel\File */ private $file; @@ -19,11 +19,11 @@ class File extends Driver { /** * Create a new File cache driver instance. * - * @param Laravel\File_Engine $file - * @param string $path + * @param Laravel\File $file + * @param string $path * @return void */ - public function __construct(\Laravel\File_Engine $file, $path) + public function __construct(\Laravel\File $file, $path) { $this->file = $file; $this->path = $path; @@ -32,11 +32,6 @@ public function __construct(\Laravel\File_Engine $file, $path) /** * Determine if an item exists in the cache. * - * - * // Determine if the "name" item exists in the cache - * $exists = Cache::driver()->has('name'); - * - * * @param string $key * @return bool */ @@ -66,11 +61,6 @@ protected function retrieve($key) /** * Write an item to the cache for a given number of minutes. * - * - * // Write the "name" item to the cache for 30 minutes - * Cache::driver()->put('name', 'Fred', 30); - * - * * @param string $key * @param mixed $value * @param int $minutes diff --git a/laravel/config/container.php b/laravel/config/container.php index 7cd8cb49..7d7d5064 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -43,16 +43,12 @@ 'laravel.file' => array('singleton' => true, 'resolver' => function($container) { - require_once SYS_PATH.'file'.EXT; - return new File($container->resolve('laravel.config')->get('mimes')); }), 'laravel.input' => array('singleton' => true, 'resolver' => function($container) { - require_once SYS_PATH.'input'.EXT; - $application = $container->resolve('laravel.application'); $input = array(); @@ -70,15 +66,13 @@ ($application->request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input); } - return new Input_Engine($input, $_FILES, $container->resolve('laravel.cookie')); + return new Input($input, $_FILES, $container->resolve('laravel.cookie')); }), 'laravel.lang' => array('singleton' => true, 'resolver' => function($container) { - require_once SYS_PATH.'lang'.EXT; - - return new Lang_Engine($container->resolve('laravel.config')->get('application.language'), array(SYS_LANG_PATH, LANG_PATH)); + return new Lang($container->resolve('laravel.config')->get('application.language'), array(SYS_LANG_PATH, LANG_PATH)); }), @@ -92,23 +86,19 @@ 'laravel.package' => array('singleton' => true, 'resolver' => function() { - return new Package_Engine(PACKAGE_PATH); + return new Package(PACKAGE_PATH); }), 'laravel.redirect' => array('singleton' => true, 'resolver' => function($container) { - require_once SYS_PATH.'redirect'.EXT; - - return new Redirect_Engine($container->resolve('laravel.url')); + return new Redirect($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')); + return new Request($_SERVER, $container->resolve('laravel.config')->get('application.url')); }), @@ -140,15 +130,13 @@ 'laravel.url' => array('singleton' => true, 'resolver' => function($container) { - require_once SYS_PATH.'url'.EXT; - 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_Engine($container->resolve('laravel.router'), $base, $index, $request->secure()); + return new URL($container->resolve('laravel.router'), $base, $index, $request->secure()); }), diff --git a/laravel/download.php b/laravel/download.php index 076afbab..f059326f 100644 --- a/laravel/download.php +++ b/laravel/download.php @@ -1,7 +1,5 @@ resolve('laravel.'.static::$resolve), $method), $parameters); - } - -} \ No newline at end of file diff --git a/laravel/file.php b/laravel/file.php index 41a084b9..2f39e81a 100644 --- a/laravel/file.php +++ b/laravel/file.php @@ -1,7 +1,5 @@ - * // Returns "friend" - * Inflector::plural_if('friend', 1); - * - * // Returns "friends" - * Inflector::plural_if('friend', 2); - * - * * @param string $value - * @param int $count + * @param int $count * @return string */ public static function plural_if($value, $count) @@ -136,14 +128,6 @@ public static function plural_if($value, $count) /** * Convert a word to its plural form. * - * - * // Returns "friends" - * Inflector::plural('friend'); - * - * // Returns "children" - * Inflector::plural('child'); - * - * * @param string $value * @return string */ @@ -157,14 +141,6 @@ public static function plural($value) /** * Convert a word to its singular form. * - * - * // Returns "friend" - * Inflector::singular('friends'); - * - * // Returns "child" - * Inflector::singular('children'); - * - * * @param string $value * @return string */ diff --git a/laravel/input.php b/laravel/input.php index 36a6cb4c..981c4af9 100644 --- a/laravel/input.php +++ b/laravel/input.php @@ -1,8 +1,6 @@ config->get('session.driver') !== '') { - $application->session->start($application->input->cookies->get('laravel_session'), $application->config->get('session.lifetime')); + $cookie = $application->input->cookies->get('laravel_session'); + + $application->session->start($cookie, $application->config->get('session.lifetime')); } // -------------------------------------------------------------- diff --git a/laravel/loader.php b/laravel/loader.php index 2a7a4a7f..895f1213 100644 --- a/laravel/loader.php +++ b/laravel/loader.php @@ -40,8 +40,6 @@ public function load($class) { $file = strtolower(str_replace('\\', '/', $class)); - if (strpos($file, 'laravel') !== false) $file = str_replace('_facade', '', $file); - if (array_key_exists($class, $this->aliases)) { return class_alias($this->aliases[$class], $class); diff --git a/laravel/package.php b/laravel/package.php index 1a502d5b..042a678a 100644 --- a/laravel/package.php +++ b/laravel/package.php @@ -1,8 +1,6 @@ routes = $routes; $this->request = $request; diff --git a/laravel/session/file.php b/laravel/session/file.php index 4f8eb9c4..b9cd2723 100644 --- a/laravel/session/file.php +++ b/laravel/session/file.php @@ -5,7 +5,7 @@ class File extends Driver implements Sweeper { /** * The file engine instance. * - * @var Laravel\File_Engine + * @var Laravel\File */ private $file; @@ -19,11 +19,11 @@ class File extends Driver implements Sweeper { /** * Create a new File session driver instance. * - * @param Laravel\File_Engine $file - * @param string $path + * @param Laravel\File $file + * @param string $path * @return void */ - public function __construct(\Laravel\File_Engine $file, $path) + public function __construct(\Laravel\File $file, $path) { $this->file = $file; $this->path = $path; diff --git a/laravel/url.php b/laravel/url.php index b9e80751..76fd08d7 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -1,8 +1,6 @@ Date: Wed, 31 Aug 2011 00:07:45 -0500 Subject: [PATCH 3/3] more dependency injection! --- laravel/application.php | 46 ++++++++++++++++++------------- laravel/bootstrap.php | 9 ++---- laravel/cache/apc.php | 10 ------- laravel/cache/driver.php | 23 ---------------- laravel/cache/manager.php | 13 --------- laravel/cache/memcached.php | 10 ------- laravel/config/container.php | 34 +++++++++++++++++------ laravel/container.php | 3 ++ laravel/controller.php | 17 ++---------- laravel/download.php | 23 +++++++++------- laravel/form.php | 53 ++++++++++-------------------------- laravel/html.php | 16 ----------- laravel/loader.php | 4 +-- laravel/package.php | 2 +- laravel/request.php | 15 ++++++++-- laravel/response.php | 9 ++++-- laravel/session/cookie.php | 4 +-- laravel/session/driver.php | 46 +++---------------------------- laravel/session/manager.php | 2 +- laravel/str.php | 2 +- 20 files changed, 118 insertions(+), 223 deletions(-) diff --git a/laravel/application.php b/laravel/application.php index c272e6c1..cf7f07b5 100644 --- a/laravel/application.php +++ b/laravel/application.php @@ -1,29 +1,37 @@ registered('laravel.'.$key)) + { + return IoC::container()->resolve('laravel.'.$key); + } + elseif (IoC::container()->registered($key)) + { + return IoC::container()->resolve($key); + } + + throw new \Exception("Attempting to access undefined property [$key]."); + } + +} + +class Application extends Resolver { + + /** + * The IoC container instance for the application. * * @var Container */ public $container; - /** - * Magic Method for resolving core classes out of the IoC container. - */ - public function __get($key) - { - if ($this->container->registered('laravel.'.$key)) - { - return $this->container->resolve('laravel.'.$key); - } - elseif ($this->container->registered($key)) - { - return $this->container->resolve($key); - } - - throw new \Exception("Attempting to access undefined property [$key] on application instance."); - } - } \ No newline at end of file diff --git a/laravel/bootstrap.php b/laravel/bootstrap.php index 20ec4d6c..e9f650ad 100644 --- a/laravel/bootstrap.php +++ b/laravel/bootstrap.php @@ -65,6 +65,8 @@ $application->container = new Container($dependencies); +IoC::$container = $application->container; + // -------------------------------------------------------------- // Load the auto-loader. // -------------------------------------------------------------- @@ -73,9 +75,4 @@ // -------------------------------------------------------------- // Register the application in the container. // -------------------------------------------------------------- -$application->container->instance('laravel.application', $application); - -// -------------------------------------------------------------- -// Set the IoC container instance for use as a service locator. -// -------------------------------------------------------------- -IoC::$container = $application->container; \ No newline at end of file +IoC::container()->instance('laravel.application', $application); \ No newline at end of file diff --git a/laravel/cache/apc.php b/laravel/cache/apc.php index f6e34d17..eba53725 100644 --- a/laravel/cache/apc.php +++ b/laravel/cache/apc.php @@ -75,11 +75,6 @@ public function __construct(APC_Engine $apc, $key) /** * Determine if an item exists in the cache. * - * - * // Determine if the "name" item exists in the cache - * $exists = Cache::driver()->has('name'); - * - * * @param string $key * @return bool */ @@ -102,11 +97,6 @@ protected function retrieve($key) /** * Write an item to the cache for a given number of minutes. * - * - * // Write the "name" item to the cache for 30 minutes - * Cache::driver()->put('name', 'Fred', 30); - * - * * @param string $key * @param mixed $value * @param int $minutes diff --git a/laravel/cache/driver.php b/laravel/cache/driver.php index 267a2eda..9e4c4def 100644 --- a/laravel/cache/driver.php +++ b/laravel/cache/driver.php @@ -5,11 +5,6 @@ abstract class Driver { /** * Determine if an item exists in the cache. * - * - * // Determine if the "name" item exists in the cache - * $exists = Cache::driver()->has('name'); - * - * * @param string $key * @return bool */ @@ -21,14 +16,6 @@ abstract public function has($key); * A default value may also be specified, and will be returned in the requested * item does not exist in the cache. * - * - * // 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'); - * - * * @param string $key * @param mixed $default * @param string $driver @@ -52,11 +39,6 @@ abstract protected function retrieve($key); /** * Write an item to the cache for a given number of minutes. * - * - * // Write the "name" item to the cache for 30 minutes - * Cache::driver()->put('name', 'Fred', 30); - * - * * @param string $key * @param mixed $value * @param int $minutes @@ -68,11 +50,6 @@ abstract public function put($key, $value, $minutes); * 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. * - * - * // Get the "name" item from the cache or store "Fred" for 30 minutes - * $name = Cache::driver()->remember('name', 'Fred', 30); - * - * * @param string $key * @param mixed $default * @param int $minutes diff --git a/laravel/cache/manager.php b/laravel/cache/manager.php index 665bdccc..3581dfef 100644 --- a/laravel/cache/manager.php +++ b/laravel/cache/manager.php @@ -43,14 +43,6 @@ public function __construct(Container $container, $default) * If no driver name is specified, the default cache driver will be returned * as defined in the cache configuration file. * - * - * // Get the default cache driver - * $driver = $application->cache->driver(); - * - * // Get the APC cache driver - * $apc = $application->cache->driver('apc'); - * - * * @param string $driver * @return Cache\Driver */ @@ -76,11 +68,6 @@ public function driver($driver = null) * * Passing method calls to the driver instance provides a convenient API for the developer * when always using the default cache driver. - * - * - * // Get an item from the default cache driver - * $name = $application->cache->get('name'); - * */ public function __call($method, $parameters) { diff --git a/laravel/cache/memcached.php b/laravel/cache/memcached.php index f06c2042..158ca886 100644 --- a/laravel/cache/memcached.php +++ b/laravel/cache/memcached.php @@ -34,11 +34,6 @@ public function __construct(Memcache $memcache, $key) /** * Determine if an item exists in the cache. * - * - * // Determine if the "name" item exists in the cache - * $exists = Cache::driver()->has('name'); - * - * * @param string $key * @return bool */ @@ -61,11 +56,6 @@ protected function retrieve($key) /** * Write an item to the cache for a given number of minutes. * - * - * // Write the "name" item to the cache for 30 minutes - * Cache::driver()->put('name', 'Fred', 30); - * - * * @param string $key * @param mixed $value * @param int $minutes diff --git a/laravel/config/container.php b/laravel/config/container.php index 7d7d5064..55530ce7 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -47,23 +47,41 @@ }), + '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, $container->resolve('laravel.cookie')); @@ -98,7 +116,7 @@ 'laravel.request' => array('singleton' => true, 'resolver' => function($container) { - return new Request($_SERVER, $container->resolve('laravel.config')->get('application.url')); + return new Request($_SERVER, $_POST, $container->resolve('laravel.config')->get('application.url')); }), @@ -265,7 +283,7 @@ }), - 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function() + 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($container) { if ( ! class_exists('Memcache')) { @@ -274,7 +292,7 @@ $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']); } diff --git a/laravel/container.php b/laravel/container.php index 594bb873..eb8505ec 100644 --- a/laravel/container.php +++ b/laravel/container.php @@ -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() diff --git a/laravel/controller.php b/laravel/controller.php index 30bf2716..4412b345 100644 --- a/laravel/controller.php +++ b/laravel/controller.php @@ -1,31 +1,20 @@ $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 diff --git a/laravel/download.php b/laravel/download.php index f059326f..23042828 100644 --- a/laravel/download.php +++ b/laravel/download.php @@ -25,22 +25,25 @@ public function __construct(File $file) * * @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)); + $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->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)); + $response = parent::__construct($this->file->get($path), 200, $headers); return $response; } diff --git a/laravel/form.php b/laravel/form.php index 8828be30..e9e7c98e 100644 --- a/laravel/form.php +++ b/laravel/form.php @@ -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. * - * - * // 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'); - * - * * 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. @@ -180,16 +162,22 @@ public function close() */ public function token() { - return $this->input('hidden', 'csrf_token', $this->token); + return $this->input('hidden', 'csrf_token', $this->raw_token()); + } + + /** + * Get the CSRF token for the current session. + * + * @return string + */ + public function raw_token() + { + return IoC::container()->resolve('laravel.session')->get('csrf_token'); } /** * Create a HTML label element. * - * - * echo Form::label('email', 'E-Mail Address'); - * - * * @param string $name * @param string $value * @param array $attributes @@ -208,14 +196,6 @@ public function label($name, $value, $attributes = array()) * 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. * - * - * // 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.'); - * - * * @param string $name * @param mixed $value * @param array $attributes @@ -365,11 +345,6 @@ public function textarea($name, $value = '', $attributes = array()) /** * Create a HTML select element. * - * - * // Generate a drop-down with the "S" item selected - * echo Form::select('sizes', array('L' => 'Large', 'S' => 'Small'), 'S'); - * - * * @param string $name * @param array $options * @param string $selected diff --git a/laravel/html.php b/laravel/html.php index ca40e78e..966daeff 100644 --- a/laravel/html.php +++ b/laravel/html.php @@ -144,14 +144,6 @@ public function link_to_secure_asset($url, $title, $attributes = array()) * * An array of parameters may be specified to fill in URI segment wildcards. * - * - * // 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')); - * - * * @param string $name * @param string $title * @param array $parameters @@ -330,14 +322,6 @@ public function obfuscate($value) * Magic Method for handling dynamic static methods. * * This method primarily handles dynamic calls to create links to named routes. - * - * - * // 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')); - * */ public function __call($method, $parameters) { diff --git a/laravel/loader.php b/laravel/loader.php index 895f1213..9e7481bb 100644 --- a/laravel/loader.php +++ b/laravel/loader.php @@ -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. diff --git a/laravel/package.php b/laravel/package.php index 042a678a..9839b2f6 100644 --- a/laravel/package.php +++ b/laravel/package.php @@ -7,7 +7,7 @@ class Package { * * @var array */ - public $loaded = array(); + private $loaded = array(); /** * Load a package or set of packages. diff --git a/laravel/request.php b/laravel/request.php index a5aedf5c..65daec37 100644 --- a/laravel/request.php +++ b/laravel/request.php @@ -9,6 +9,13 @@ class Request { */ public $server; + /** + * The $_POST array for the request. + * + * @var array + */ + private $post; + /** * The route handling the current request. * @@ -27,12 +34,14 @@ class Request { * 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; } @@ -84,7 +93,7 @@ public function uri() */ public function method() { - return ($this->spoofed()) ? $_POST['REQUEST_METHOD'] : $this->server['REQUEST_METHOD']; + return ($this->spoofed()) ? $this->post['REQUEST_METHOD'] : $this->server['REQUEST_METHOD']; } /** @@ -96,7 +105,7 @@ public function method() */ 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); } /** diff --git a/laravel/response.php b/laravel/response.php index d542d1ca..46ade53f 100644 --- a/laravel/response.php +++ b/laravel/response.php @@ -25,11 +25,12 @@ public function __construct(View_Factory $view) * * @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); } /** @@ -144,11 +145,13 @@ 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; } diff --git a/laravel/session/cookie.php b/laravel/session/cookie.php index 9e8dc735..dc7cc17a 100644 --- a/laravel/session/cookie.php +++ b/laravel/session/cookie.php @@ -28,9 +28,9 @@ class Cookie extends Driver { /** * Create a new Cookie session driver instance. * - * @param Crypter $crypter + * @param Crypter $crypter * @param Laravel\Cookie $cookie - * @param array $config + * @param array $config * @return void */ public function __construct(Crypter $crypter, \Laravel\Cookie $cookie, $config) diff --git a/laravel/session/driver.php b/laravel/session/driver.php index ac8b3943..20d19b0c 100644 --- a/laravel/session/driver.php +++ b/laravel/session/driver.php @@ -1,7 +1,7 @@ - * // Determine if "name" item exists in the session - * $exists = Session::driver()->has('name'); - * - * * @param string $key * @return bool */ @@ -86,14 +81,6 @@ public function has($key) * A default value may also be specified, and will be returned in the requested * item does not exist in the session. * - * - * // 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'); - * - * * @param string $key * @param mixed $default * @return mixed @@ -111,11 +98,6 @@ public function get($key, $default = null) /** * Write an item to the session. * - * - * // Write the "name" item to the session - * Session::driver()->put('name', 'Fred'); - * - * * @param string $key * @param mixed $value * @return Driver @@ -133,11 +115,6 @@ public function put($key, $value) * 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. * - * - * // Write the "name" item to the session flash data - * Session::driver()->flash('name', 'Fred'); - * - * * @param string $key * @param mixed $value * @return Driver @@ -152,11 +129,6 @@ public function flash($key, $value) /** * Remove an item from the session. * - * - * // Remove the "name" item from the session - * Session::driver()->forget('name'); - * - * * @param string $key * @return Driver */ @@ -196,11 +168,11 @@ public function regenerate() * 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. * - * @param Laravel\Input_Engine $input - * @param array $config + * @param Laravel\Input $input + * @param array $config * @return void */ - public function close(Input_Engine $input, $config) + public function close(Input $input, $config) { $this->flash('laravel_old_input', $input->get())->age(); @@ -259,11 +231,6 @@ protected function write_cookie(Cookie $cookies, $config) /** * Magic Method for retrieving items from the session. - * - * - * // Get the "name" item from the session - * $name = $application->session->name; - * */ public function __get($key) { @@ -272,11 +239,6 @@ public function __get($key) /** * Magic Method for writings items to the session. - * - * - * // Write "Fred" to the session "name" item - * $application->session->name = 'Fred'; - * */ public function __set($key, $value) { diff --git a/laravel/session/manager.php b/laravel/session/manager.php index 688410b3..1faaf9ab 100644 --- a/laravel/session/manager.php +++ b/laravel/session/manager.php @@ -32,7 +32,7 @@ public function __construct(Container $container) * @param string $driver * @return Session\Driver */ - public static function driver($driver) + public function driver($driver) { if (in_array($driver, array('cookie', 'file', 'database', 'apc', 'memcached'))) { diff --git a/laravel/str.php b/laravel/str.php index 9ef75ee9..1d682611 100644 --- a/laravel/str.php +++ b/laravel/str.php @@ -107,7 +107,7 @@ private static function pool($type = 'alpha_num') * * @return string */ - private static function encoding() + public static function encoding() { return IoC::container()->resolve('laravel.config')->get('application.encoding'); }