From 220c359eee5d73b279fe540e2148c7618ad881ac Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 16 Sep 2011 20:01:10 -0500 Subject: [PATCH] fixed changes. --- application/config/aliases.php | 102 ++--- application/config/application.php | 194 ++++---- application/config/auth.php | 126 +++--- application/config/cache.php | 102 ++--- application/config/database.php | 162 +++---- application/config/error.php | 60 +-- application/config/session.php | 186 ++++---- laravel/bootstrap.php | 140 +++--- laravel/config.php | 287 ++++++++---- laravel/config/container.php | 696 ++++++++++++++--------------- 10 files changed, 1072 insertions(+), 983 deletions(-) diff --git a/application/config/aliases.php b/application/config/aliases.php index cebb431c..707ff07b 100644 --- a/application/config/aliases.php +++ b/application/config/aliases.php @@ -1,52 +1,52 @@ - 'Laravel\\Arr', - 'Asset' => 'Laravel\\Facades\\Asset', - 'Auth' => 'Laravel\\Facades\\Auth', - 'Benchmark' => 'Laravel\\Benchmark', - 'Cache' => 'Laravel\\Facades\\Cache', - 'Config' => 'Laravel\\Facades\\Config', - 'Controller' => 'Laravel\\Controller', - 'Cookie' => 'Laravel\\Facades\\Cookie', - 'Crypter' => 'Laravel\\Facades\\Crypter', - 'DB' => 'Laravel\\Facades\\DB', - 'Download' => 'Laravel\\Facades\\Download', - 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', - 'File' => 'Laravel\\Facades\\File', - 'Form' => 'Laravel\\Facades\\Form', - 'Hasher' => 'Laravel\\Facades\\Hasher', - 'HTML' => 'Laravel\\Facades\\HTML', - 'Inflector' => 'Laravel\\Inflector', - 'Input' => 'Laravel\\Facades\\Input', - 'IoC' => 'Laravel\\IoC', - 'Lang' => 'Laravel\\Facades\\Lang', - 'Loader' => 'Laravel\\Facades\\Loader', - 'Package' => 'Laravel\\Facades\\Package', - 'URL' => 'Laravel\\Facades\\URL', - 'Redirect' => 'Laravel\\Facades\\Redirect', - 'Request' => 'Laravel\\Facades\\Request', - 'Response' => 'Laravel\\Facades\\Response', - 'Session' => 'Laravel\\Facades\\Session', - 'Str' => 'Laravel\\Str', - 'Validator' => 'Laravel\\Facades\\Validator', - 'View' => 'Laravel\\Facades\\View', - + 'Laravel\\Arr', + 'Asset' => 'Laravel\\Facades\\Asset', + 'Auth' => 'Laravel\\Facades\\Auth', + 'Benchmark' => 'Laravel\\Benchmark', + 'Cache' => 'Laravel\\Facades\\Cache', + 'Config' => 'Laravel\\Facades\\Config', + 'Controller' => 'Laravel\\Controller', + 'Cookie' => 'Laravel\\Facades\\Cookie', + 'Crypter' => 'Laravel\\Facades\\Crypter', + 'DB' => 'Laravel\\Facades\\DB', + 'Download' => 'Laravel\\Facades\\Download', + 'Eloquent' => 'Laravel\\Database\\Eloquent\\Model', + 'File' => 'Laravel\\Facades\\File', + 'Form' => 'Laravel\\Facades\\Form', + 'Hasher' => 'Laravel\\Facades\\Hasher', + 'HTML' => 'Laravel\\Facades\\HTML', + 'Inflector' => 'Laravel\\Inflector', + 'Input' => 'Laravel\\Facades\\Input', + 'IoC' => 'Laravel\\IoC', + 'Lang' => 'Laravel\\Facades\\Lang', + 'Loader' => 'Laravel\\Facades\\Loader', + 'Package' => 'Laravel\\Facades\\Package', + 'URL' => 'Laravel\\Facades\\URL', + 'Redirect' => 'Laravel\\Facades\\Redirect', + 'Request' => 'Laravel\\Facades\\Request', + 'Response' => 'Laravel\\Facades\\Response', + 'Session' => 'Laravel\\Facades\\Session', + 'Str' => 'Laravel\\Str', + 'Validator' => 'Laravel\\Facades\\Validator', + 'View' => 'Laravel\\Facades\\View', + ); \ No newline at end of file diff --git a/application/config/application.php b/application/config/application.php index 2c0028a4..8dadc03a 100644 --- a/application/config/application.php +++ b/application/config/application.php @@ -1,98 +1,98 @@ - 'http://localhost', - - /* - |-------------------------------------------------------------------------- - | Application Index - |-------------------------------------------------------------------------- - | - | If you are including the "index.php" in your URLs, you can ignore this. - | - | However, if you are using mod_rewrite or something similar to get - | cleaner URLs, set this option to an empty string. - | - */ - - 'index' => 'index.php', - - /* - |-------------------------------------------------------------------------- - | Application Language - |-------------------------------------------------------------------------- - | - | The default language of your application. This language will be used by - | Lang library as the default language when doing string localization. - | - */ - - 'language' => 'en', - - /* - |-------------------------------------------------------------------------- - | Application Character Encoding - |-------------------------------------------------------------------------- - | - | The default character encoding used by your application. This is the - | character encoding that will be used by the Str, Text, and Form classes. - | - */ - - 'encoding' => 'UTF-8', - - /* - |-------------------------------------------------------------------------- - | Application Timezone - |-------------------------------------------------------------------------- - | - | The default timezone of your application. This timezone will be used when - | Laravel needs a date, such as when writing to a log file. - | - */ - - 'timezone' => 'UTC', - - /* - |-------------------------------------------------------------------------- - | Auto-Loaded Packages - |-------------------------------------------------------------------------- - | - | The packages that should be auto-loaded each time Laravel handles - | a request. These should generally be packages that you use on almost - | every request to your application. - | - | Each package specified here will be bootstrapped and can be conveniently - | used by your application's routes, models, and libraries. - | - | Note: The package names in this array should correspond to a package - | directory in application/packages. - | - */ - - 'packages' => array(), - - /* - |-------------------------------------------------------------------------- - | Application Key - |-------------------------------------------------------------------------- - | - | Your application key should be a 32 character string that is totally - | random and secret. This key is used by the encryption class to generate - | secure, encrypted strings. - | - */ - - 'key' => '', - + 'http://localhost', + + /* + |-------------------------------------------------------------------------- + | Application Index + |-------------------------------------------------------------------------- + | + | If you are including the "index.php" in your URLs, you can ignore this. + | + | However, if you are using mod_rewrite or something similar to get + | cleaner URLs, set this option to an empty string. + | + */ + + 'index' => 'index.php', + + /* + |-------------------------------------------------------------------------- + | Application Language + |-------------------------------------------------------------------------- + | + | The default language of your application. This language will be used by + | Lang library as the default language when doing string localization. + | + */ + + 'language' => 'en', + + /* + |-------------------------------------------------------------------------- + | Application Character Encoding + |-------------------------------------------------------------------------- + | + | The default character encoding used by your application. This is the + | character encoding that will be used by the Str, Text, and Form classes. + | + */ + + 'encoding' => 'UTF-8', + + /* + |-------------------------------------------------------------------------- + | Application Timezone + |-------------------------------------------------------------------------- + | + | The default timezone of your application. This timezone will be used when + | Laravel needs a date, such as when writing to a log file. + | + */ + + 'timezone' => 'UTC', + + /* + |-------------------------------------------------------------------------- + | Auto-Loaded Packages + |-------------------------------------------------------------------------- + | + | The packages that should be auto-loaded each time Laravel handles + | a request. These should generally be packages that you use on almost + | every request to your application. + | + | Each package specified here will be bootstrapped and can be conveniently + | used by your application's routes, models, and libraries. + | + | Note: The package names in this array should correspond to a package + | directory in application/packages. + | + */ + + 'packages' => array(), + + /* + |-------------------------------------------------------------------------- + | Application Key + |-------------------------------------------------------------------------- + | + | Your application key should be a 32 character string that is totally + | random and secret. This key is used by the encryption class to generate + | secure, encrypted strings. + | + */ + + 'key' => '', + ); \ No newline at end of file diff --git a/application/config/auth.php b/application/config/auth.php index ae84efbc..252c6723 100644 --- a/application/config/auth.php +++ b/application/config/auth.php @@ -1,64 +1,64 @@ - function($id) - { - if ( ! is_null($id)) return User::find($id); - }, - - /* - |-------------------------------------------------------------------------- - | Authenticate User Credentials - |-------------------------------------------------------------------------- - | - | This closure is called by the Auth::attempt() method when attempting to - | authenticate a user that is logging into your application. - | - | If the provided credentials are correct, simply return an object that - | represents the user being authenticated. If the credentials are not - | valid, don't return anything. - | - | Note: If a user object is returned, it must have an "id" property. - | - */ - - 'attempt' => function($username, $password) - { - if ( ! is_null($user = User::where('email', '=', $username)->first())) - { - if (Hasher::check($password, $user->password)) return $user; - } - }, - - /* - |-------------------------------------------------------------------------- - | Logout - |-------------------------------------------------------------------------- - | - | Here you may do anything that needs to be done when a user logs out of - | your application, such as call the logout method on a third-party API - | you are using for authentication, or anything else you desire. - | - */ - - 'logout' => function($id) {} - + function($id) + { + if ( ! is_null($id)) return User::find($id); + }, + + /* + |-------------------------------------------------------------------------- + | Authenticate User Credentials + |-------------------------------------------------------------------------- + | + | This closure is called by the Auth::attempt() method when attempting to + | authenticate a user that is logging into your application. + | + | If the provided credentials are correct, simply return an object that + | represents the user being authenticated. If the credentials are not + | valid, don't return anything. + | + | Note: If a user object is returned, it must have an "id" property. + | + */ + + 'attempt' => function($username, $password) + { + if ( ! is_null($user = User::where('email', '=', $username)->first())) + { + if (Hasher::check($password, $user->password)) return $user; + } + }, + + /* + |-------------------------------------------------------------------------- + | Logout + |-------------------------------------------------------------------------- + | + | Here you may do anything that needs to be done when a user logs out of + | your application, such as call the logout method on a third-party API + | you are using for authentication, or anything else you desire. + | + */ + + 'logout' => function($id) {} + ); \ No newline at end of file diff --git a/application/config/cache.php b/application/config/cache.php index 7c6bf32e..a36c50e1 100644 --- a/application/config/cache.php +++ b/application/config/cache.php @@ -1,52 +1,52 @@ - 'file', - - /* - |-------------------------------------------------------------------------- - | Cache Key - |-------------------------------------------------------------------------- - | - | This key will be prepended to item keys stored using Memcached and APC to - | prevent collisions with other applications on the server. - | - */ - - 'key' => 'laravel', - - /* - |-------------------------------------------------------------------------- - | Memcached Servers - |-------------------------------------------------------------------------- - | - | The Memcached servers used by your application. - | - | Memcached is a free and open source, high-performance, distributed memory - | object caching system, generic in nature, but intended for use in speeding - | up dynamic web applications by alleviating database load. - | - | For more information about Memcached, check out: http://memcached.org - | - */ - - 'servers' => array( - array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), - ), - + 'file', + + /* + |-------------------------------------------------------------------------- + | Cache Key + |-------------------------------------------------------------------------- + | + | This key will be prepended to item keys stored using Memcached and APC to + | prevent collisions with other applications on the server. + | + */ + + 'key' => 'laravel', + + /* + |-------------------------------------------------------------------------- + | Memcached Servers + |-------------------------------------------------------------------------- + | + | The Memcached servers used by your application. + | + | Memcached is a free and open source, high-performance, distributed memory + | object caching system, generic in nature, but intended for use in speeding + | up dynamic web applications by alleviating database load. + | + | For more information about Memcached, check out: http://memcached.org + | + */ + + 'servers' => array( + array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100), + ), + ); \ No newline at end of file diff --git a/application/config/database.php b/application/config/database.php index f46d67fb..510c3d1e 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -1,82 +1,82 @@ - 'sqlite', - - /* - |-------------------------------------------------------------------------- - | Database Connectors - |-------------------------------------------------------------------------- - | - | All of the database connectors used by your application. - | - | Each connector should return a PDO connection. You may connect to any - | database system you wish. Of course, default configurations for the - | systems supported by Laravel are provided for you. - | - | The entire database configuration array is passed to the connector - | closure, so you may convenient use it when connecting to your database. - | - | Note: When using an unsupported database, Eloquent and the fluent query - | builder may not work as expected. Currently, MySQL, Postgres, and - | SQLite are fully supported by Laravel. - | - */ - - 'connectors' => array( - - 'sqlite' => function($config) - { - return new PDO('sqlite:'.DATABASE_PATH.'application.sqlite', null, null, $config['options']); - }, - - 'mysql' => function($config) - { - return new PDO('mysql:host=localhost;dbname=database', 'root', 'password', $config['options']); - }, - - 'pgsql' => function($config) - { - return new PDO('pgsql:host=localhost;dbname=database', 'root', 'password', $config['options']); - }, - - ), - - /* - |-------------------------------------------------------------------------- - | Database PDO Options - |-------------------------------------------------------------------------- - | - | Here you may specify the PDO options that should be used when connecting - | to a database. The entire database configuration array is passed to the - | database connector closures, so may convenient access these options from - | your connectors. - | - | For a list of options, visit: http://php.net/manual/en/pdo.setattribute.php - | - */ - - 'options' => array( - PDO::ATTR_CASE => PDO::CASE_LOWER, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, - PDO::ATTR_STRINGIFY_FETCHES => false, - PDO::ATTR_EMULATE_PREPARES => false, - ), - + 'sqlite', + + /* + |-------------------------------------------------------------------------- + | Database Connectors + |-------------------------------------------------------------------------- + | + | All of the database connectors used by your application. + | + | Each connector should return a PDO connection. You may connect to any + | database system you wish. Of course, default configurations for the + | systems supported by Laravel are provided for you. + | + | The entire database configuration array is passed to the connector + | closure, so you may convenient use it when connecting to your database. + | + | Note: When using an unsupported database, Eloquent and the fluent query + | builder may not work as expected. Currently, MySQL, Postgres, and + | SQLite are fully supported by Laravel. + | + */ + + 'connectors' => array( + + 'sqlite' => function($config) + { + return new PDO('sqlite:'.DATABASE_PATH.'application.sqlite', null, null, $config['options']); + }, + + 'mysql' => function($config) + { + return new PDO('mysql:host=localhost;dbname=database', 'root', 'password', $config['options']); + }, + + 'pgsql' => function($config) + { + return new PDO('pgsql:host=localhost;dbname=database', 'root', 'password', $config['options']); + }, + + ), + + /* + |-------------------------------------------------------------------------- + | Database PDO Options + |-------------------------------------------------------------------------- + | + | Here you may specify the PDO options that should be used when connecting + | to a database. The entire database configuration array is passed to the + | database connector closures, so may convenient access these options from + | your connectors. + | + | For a list of options, visit: http://php.net/manual/en/pdo.setattribute.php + | + */ + + 'options' => array( + PDO::ATTR_CASE => PDO::CASE_LOWER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::ATTR_EMULATE_PREPARES => false, + ), + ); \ No newline at end of file diff --git a/application/config/error.php b/application/config/error.php index 32d82e93..721b4064 100644 --- a/application/config/error.php +++ b/application/config/error.php @@ -1,31 +1,31 @@ - function($exception) - { - var_dump($exception); - - exit(1); - }, - + function($exception) + { + var_dump($exception); + + exit(1); + }, + ); \ No newline at end of file diff --git a/application/config/session.php b/application/config/session.php index ed7f3825..1c167143 100644 --- a/application/config/session.php +++ b/application/config/session.php @@ -1,94 +1,94 @@ - '', - - /* - |-------------------------------------------------------------------------- - | Session Database - |-------------------------------------------------------------------------- - | - | The database table on which the session should be stored. - | - | This option is only relevant when using the "database" session driver. - | - */ - - 'table' => 'sessions', - - /* - |-------------------------------------------------------------------------- - | Session Garbage Collection Probability - |-------------------------------------------------------------------------- - | - | Some session drivers require the manual clean-up of expired sessions. - | This option specifies the probability of session garbage collection - | occuring for any given request. - | - | For example, the default value states that garbage collection has about - | a 2% (2 / 100) chance of occuring for any given request. - | - */ - - 'sweepage' => array(2, 100), - - /* - |-------------------------------------------------------------------------- - | Session Lifetime - |-------------------------------------------------------------------------- - | - | The number of minutes a session can be idle before expiring. - | - */ - - 'lifetime' => 60, - - /* - |-------------------------------------------------------------------------- - | Session Expiration On Close - |-------------------------------------------------------------------------- - | - | Determines if the session should expire when the user's web browser closes. - | - */ - - 'expire_on_close' => false, - - /* - |-------------------------------------------------------------------------- - | Session Cookie Path - |-------------------------------------------------------------------------- - | - | The path for which the session cookie is available. - | - */ - - 'path' => '/', - - /* - |-------------------------------------------------------------------------- - | Session Cookie Domain - |-------------------------------------------------------------------------- - | - | The domain for which the session cookie is available. - | - */ - - 'domain' => null, - + '', + + /* + |-------------------------------------------------------------------------- + | Session Database + |-------------------------------------------------------------------------- + | + | The database table on which the session should be stored. + | + | This option is only relevant when using the "database" session driver. + | + */ + + 'table' => 'sessions', + + /* + |-------------------------------------------------------------------------- + | Session Garbage Collection Probability + |-------------------------------------------------------------------------- + | + | Some session drivers require the manual clean-up of expired sessions. + | This option specifies the probability of session garbage collection + | occuring for any given request. + | + | For example, the default value states that garbage collection has about + | a 2% (2 / 100) chance of occuring for any given request. + | + */ + + 'sweepage' => array(2, 100), + + /* + |-------------------------------------------------------------------------- + | Session Lifetime + |-------------------------------------------------------------------------- + | + | The number of minutes a session can be idle before expiring. + | + */ + + 'lifetime' => 60, + + /* + |-------------------------------------------------------------------------- + | Session Expiration On Close + |-------------------------------------------------------------------------- + | + | Determines if the session should expire when the user's web browser closes. + | + */ + + 'expire_on_close' => false, + + /* + |-------------------------------------------------------------------------- + | Session Cookie Path + |-------------------------------------------------------------------------- + | + | The path for which the session cookie is available. + | + */ + + 'path' => '/', + + /* + |-------------------------------------------------------------------------- + | Session Cookie Domain + |-------------------------------------------------------------------------- + | + | The domain for which the session cookie is available. + | + */ + + 'domain' => null, + ); \ No newline at end of file diff --git a/laravel/bootstrap.php b/laravel/bootstrap.php index cb7df0d7..5dba2621 100644 --- a/laravel/bootstrap.php +++ b/laravel/bootstrap.php @@ -1,71 +1,71 @@ -resolve('laravel.loader'), 'load')); - -// -------------------------------------------------------------- -// Set the application environment configuration option. -// -------------------------------------------------------------- +resolve('laravel.loader'), 'load')); + +// -------------------------------------------------------------- +// Set the application environment configuration option. +// -------------------------------------------------------------- $container->resolve('laravel.config')->set('application.env', $env); \ No newline at end of file diff --git a/laravel/config.php b/laravel/config.php index 00ce2873..3cae3665 100644 --- a/laravel/config.php +++ b/laravel/config.php @@ -1,100 +1,189 @@ -config = $config; - } - - /** - * Determine if a configuration item or file exists. - * - * - * // Determine if the "options" configuration file exists - * $options = Config::has('options'); - * - * // Determine if a specific configuration item exists - * $timezone = Config::has('application.timezone'); - * - * - * @param string $key - * @return bool - */ - public function has($key) - { - return ! is_null($this->get($key)); - } - - /** - * Get a configuration item. - * - * Configuration items are stored in the application/config directory, and provide - * general configuration options for a wide range of Laravel facilities. - * - * The arrays may be accessed using JavaScript style "dot" notation to drill deep - * intot he configuration files. For example, asking for "database.connectors.sqlite" - * would return the connector closure for SQLite stored in the database configuration - * file. If no specific item is specfied, the entire configuration array is returned. - * - * Like most Laravel "get" functions, a default value may be provided, and it will - * be returned if the requested file or item doesn't exist. - * - * - * // Get the "timezone" option from the application config file - * $timezone = Config::get('application.timezone'); - * - * // Get an option, but return a default value if it doesn't exist - * $value = Config::get('some.option', 'Default'); - * - * - * @param string $key - * @param string $default - * @return array - */ - public function get($key, $default = null) - { - return Arr::get($this->items, $key, $default); - } - - /** - * Set a configuration item. - * - * Configuration items are stored in the application/config directory, and provide - * general configuration options for a wide range of Laravel facilities. - * - * Like the "get" method, this method uses JavaScript style "dot" notation to access - * and manipulate the arrays in the configuration files. Also, like the "get" method, - * if no specific item is specified, the entire configuration array will be set. - * - * - * // Set the "timezone" option in the "application" array - * Config::set('application.timezone', 'America/Chicago'); - * - * // Set the entire "session" configuration array - * Config::set('session', $array); - * - * - * @param string $key - * @param mixed $value - * @return void - */ - public function set($key, $value) - { - Arr::set($this->items, $key, $value); - } - +paths = $paths; + } + + /** + * Determine if a configuration item or file exists. + * + * + * // Determine if the "options" configuration file exists + * $options = Config::has('options'); + * + * // Determine if a specific configuration item exists + * $timezone = Config::has('application.timezone'); + * + * + * @param string $key + * @return bool + */ + public function has($key) + { + return ! is_null($this->get($key)); + } + + /** + * Get a configuration item. + * + * Configuration items are stored in the application/config directory, and provide + * general configuration options for a wide range of Laravel facilities. + * + * The arrays may be accessed using JavaScript style "dot" notation to drill deep + * intot he configuration files. For example, asking for "database.connectors.sqlite" + * would return the connector closure for SQLite stored in the database configuration + * file. If no specific item is specfied, the entire configuration array is returned. + * + * Like most Laravel "get" functions, a default value may be provided, and it will + * be returned if the requested file or item doesn't exist. + * + * + * // Get the "timezone" option from the application config file + * $timezone = Config::get('application.timezone'); + * + * // Get an option, but return a default value if it doesn't exist + * $value = Config::get('some.option', 'Default'); + * + * + * @param string $key + * @param string $default + * @return array + */ + public function get($key, $default = null) + { + list($file, $key) = $this->parse($key); + + if ( ! $this->load($file)) + { + return ($default instanceof \Closure) ? call_user_func($default) : $default; + } + + if (is_null($key)) + { + return $this->items[$file]; + } + + return Arr::get($this->items[$file], $key, $default); + } + + /** + * Set a configuration item. + * + * Configuration items are stored in the application/config directory, and provide + * general configuration options for a wide range of Laravel facilities. + * + * Like the "get" method, this method uses JavaScript style "dot" notation to access + * and manipulate the arrays in the configuration files. Also, like the "get" method, + * if no specific item is specified, the entire configuration array will be set. + * + * + * // Set the "timezone" option in the "application" array + * Config::set('application.timezone', 'America/Chicago'); + * + * // Set the entire "session" configuration array + * Config::set('session', $array); + * + * + * @param string $key + * @param mixed $value + * @return void + */ + public function set($key, $value) + { + list($file, $key) = $this->parse($key); + + $this->load($file); + + if (is_null($key)) + { + Arr::set($this->items, $file, $value); + } + else + { + Arr::set($this->items[$file], $key, $value); + } + } + + /** + * Parse a configuration key and return its file and key segments. + * + * Configuration keys follow a {file}.{key} convention. So, for example, the + * "session.driver" option refers to the "driver" option within the "session" + * configuration file. + * + * If no specific item is specified, such as when requested "session", null will + * be returned as the value of the key since the entire file is being requested. + * + * @param string $key + * @return array + */ + protected function parse($key) + { + $segments = explode('.', $key); + + $key = (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null; + + return array($segments[0], $key); + } + + /** + * Load all of the configuration items from a module configuration file. + * + * If the configuration file has already been loaded into the items array, there + * is no need to load it again, so "true" will be returned immediately. + * + * Configuration files cascade across directories. So, for example, if a configuration + * file is in the system directory, its options will be overriden by a matching file + * in the application directory. + * + * @param string $file + * @return bool + */ + protected function load($file) + { + if (isset($this->items[$file])) return true; + + $config = array(); + + foreach ($this->paths as $directory) + { + if (file_exists($path = $directory.$file.EXT)) + { + $config = array_merge($config, require $path); + } + } + + if (count($config) > 0) + { + $this->items[$file] = $config; + } + + return isset($this->items[$file]); + } + } \ No newline at end of file diff --git a/laravel/config/container.php b/laravel/config/container.php index b38024f9..277a3b14 100644 --- a/laravel/config/container.php +++ b/laravel/config/container.php @@ -1,349 +1,349 @@ - array('singleton' => true, 'resolver' => function($container) - { - return new Asset($container->resolve('laravel.html')); - }), - - - 'laravel.auth' => array('singleton' => true, 'resolver' => function($container) - { - return new Security\Auth($container->resolve('laravel.config'), $container->resolve('laravel.session')); - }), - - - '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.crypter' => array('resolver' => function($container) - { - $key = $container->resolve('laravel.config')->get('application.key'); - - return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', $key); - }), - - - 'laravel.cookie' => array('singleton' => true, 'resolver' => function() - { - return new Cookie($_COOKIE); - }), - - - 'laravel.database' => array('singleton' => true, 'resolver' => function($container) - { - return new Database\Manager($container->resolve('laravel.config')->get('database')); - }), - - - 'laravel.download' => array('singleton' => true, 'resolver' => function($container) - { - return new Download($container->resolve('laravel.file')); - }), - - - 'laravel.file' => array('singleton' => true, 'resolver' => function($container) - { - return new File($container->resolve('laravel.config')->get('mimes')); - }), - - - 'laravel.form' => array('singleton' => true, '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.hasher' => array('singleton' => true, 'resolver' => function($container) - { - return new Security\Hashing\Bcrypt(8); - }), - - - 'laravel.html' => array('singleton' => true, '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) - { - $request = $container->resolve('laravel.request'); - - $input = array(); - - if ($request->method() == 'GET') - { - $input = $_GET; - } - elseif ($request->method() == 'POST') - { - $input = $_POST; - } - elseif ($request->method() == 'PUT' or $request->method == 'DELETE') - { - ($request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input); - } - - unset($input['_REQUEST_METHOD_']); - - return new Input($container->resolve('laravel.file'), $container->resolve('laravel.cookie'), $input, $_FILES); - }), - - - 'laravel.lang' => array('singleton' => true, 'resolver' => function($container) - { - require_once SYS_PATH.'lang'.EXT; - - return new Lang_Factory($container->resolve('laravel.config'), array(SYS_LANG_PATH, LANG_PATH)); - }), - - - 'laravel.loader' => array('singleton' => true, 'resolver' => function($container) - { - require_once SYS_PATH.'loader'.EXT; - - $aliases = $container->resolve('laravel.config')->get('aliases'); - - return new Loader(array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'), $aliases); - }), - - - 'laravel.package' => array('singleton' => true, 'resolver' => function() - { - return new Package(PACKAGE_PATH); - }), - - - 'laravel.redirect' => array('singleton' => true, 'resolver' => function($container) - { - return new Redirect($container->resolve('laravel.url')); - }), - - - 'laravel.request' => array('singleton' => true, 'resolver' => function($container) - { - return new Request($_SERVER, $_POST, $container->resolve('laravel.config')->get('application.url')); - }), - - - 'laravel.response' => array('singleton' => true, 'resolver' => function($container) - { - require_once SYS_PATH.'response'.EXT; - - return new Response_Factory($container->resolve('laravel.view'), $container->resolve('laravel.file')); - }), - - - 'laravel.routing.router' => array('singleton' => true, 'resolver' => function($container) - { - return new Routing\Router(require APP_PATH.'routes'.EXT, CONTROLLER_PATH); - }), - - - 'laravel.routing.caller' => array('resolver' => function($container) - { - return new Routing\Caller($container, require APP_PATH.'filters'.EXT, CONTROLLER_PATH); - }), - - - 'laravel.session.manager' => array('singleton' => true, 'resolver' => function($c) - { - $config = $c->resolve('laravel.config'); - - $driver = $c->resolve('laravel.session.'.$config->get('session.driver')); - - return new Session\Manager($driver, $c->resolve('laravel.session.transporter'), $config); - }), - - - 'laravel.session.transporter' => array('resolver' => function($c) - { - return new Session\Transporters\Cookie($c->resolve('laravel.cookie')); - }), - - - 'laravel.url' => array('singleton' => true, 'resolver' => function($container) - { - list($request, $base, $index) = array( - $container->resolve('laravel.request'), - $container->resolve('laravel.config')->get('application.url'), - $container->resolve('laravel.config')->get('application.index'), - ); - - return new URL($container->resolve('laravel.routing.router'), $base, $index, $request->secure()); - }), - - - 'laravel.validator' => array('singleton' => true, 'resolver' => function($container) - { - require_once SYS_PATH.'validation/validator'.EXT; - - return new Validation\Validator_Factory($container->resolve('laravel.lang')); - }), - - - 'laravel.view' => array('singleton' => true, 'resolver' => function($container) - { - require_once SYS_PATH.'view'.EXT; - - return new View_Factory($container->resolve('laravel.view.composer'), VIEW_PATH); - }), - - - 'laravel.view.composer' => array('resolver' => function($container) - { - return new View_Composer(require APP_PATH.'composers'.EXT); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel Cookie Session Components - |-------------------------------------------------------------------------- - */ - - 'laravel.session.cookie' => array('resolver' => function($container) - { - $cookies = $container->resolve('laravel.cookie'); - - $config = $container->resolve('laravel.config')->get('session'); - - return new Session\Drivers\Cookie($container->resolve('laravel.crypter'), $cookies); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel Database Session Components - |-------------------------------------------------------------------------- - */ - - 'laravel.session.database' => array('resolver' => function($container) - { - $table = $container->resolve('laravel.config')->get('session.table'); - - return new Session\Drivers\Database($container->resolve('laravel.database')->connection()); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel Cache Manager - |-------------------------------------------------------------------------- - */ - - 'laravel.cache' => array('singleton' => true, 'resolver' => function($container) - { - return new Cache\Manager($container, $container->resolve('laravel.config')->get('cache.driver')); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel File Cache & Session Components - |-------------------------------------------------------------------------- - */ - - 'laravel.cache.file' => array('resolver' => function($container) - { - return new Cache\Drivers\File($container->resolve('laravel.file'), CACHE_PATH); - }), - - - 'laravel.session.file' => array('resolver' => function($container) - { - return new Session\Drivers\File($container->resolve('laravel.file'), SESSION_PATH); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel APC Cache & Session Components - |-------------------------------------------------------------------------- - */ - - 'laravel.cache.apc' => array('resolver' => function($container) - { - return new Cache\Drivers\APC(new Proxy, $container->resolve('laravel.config')->get('cache.key')); - }), - - - 'laravel.session.id' => array('singleton' => true, 'resolver' => function($container) - { - return $container->resolve('laravel.cookie')->get('laravel_session'); - }), - - - 'laravel.session.apc' => array('resolver' => function($container) - { - $lifetime = $container->resolve('laravel.config')->get('session.lifetime'); - - return new Session\Drivers\APC($container->resolve('laravel.cache.apc')); - }), - - /* - |-------------------------------------------------------------------------- - | Laravel Memcached Cache & Session Components - |-------------------------------------------------------------------------- - */ - - 'laravel.cache.memcached' => array('resolver' => function($container) - { - $connection = $container->resolve('laravel.cache.memcache.connection'); - - $key = $container->resolve('laravel.config')->get('cache.key'); - - return new Cache\Drivers\Memcached($connection, $key); - }), - - - 'laravel.session.memcached' => array('resolver' => function($container) - { - $lifetime = $container->resolve('laravel.config')->get('session.lifetime'); - - return new Session\Drivers\Memcached($container->resolve('laravel.cache.memcached')); - }), - - - 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($container) - { - if ( ! class_exists('Memcache')) - { - throw new \Exception('Attempting to use Memcached, but the Memcache PHP extension is not installed on this server.'); - } - - $memcache = new \Memcache; - - foreach ($container->resolve('laravel.config')->get('cache.servers') as $server) - { - $memcache->addServer($server['host'], $server['port'], true, $server['weight']); - } - - if ($memcache->getVersion() === false) - { - throw new \Exception('Memcached is configured. However, no connections could be made. Please verify your memcached configuration.'); - } - - return $memcache; - }), - + array('singleton' => true, 'resolver' => function($container) + { + return new Asset($container->resolve('laravel.html')); + }), + + + 'laravel.auth' => array('singleton' => true, 'resolver' => function($container) + { + return new Security\Auth($container->resolve('laravel.config'), $container->resolve('laravel.session')); + }), + + + '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.crypter' => array('resolver' => function($container) + { + $key = $container->resolve('laravel.config')->get('application.key'); + + return new Security\Crypter(MCRYPT_RIJNDAEL_256, 'cbc', $key); + }), + + + 'laravel.cookie' => array('singleton' => true, 'resolver' => function() + { + return new Cookie($_COOKIE); + }), + + + 'laravel.database' => array('singleton' => true, 'resolver' => function($container) + { + return new Database\Manager($container->resolve('laravel.config')->get('database')); + }), + + + 'laravel.download' => array('singleton' => true, 'resolver' => function($container) + { + return new Download($container->resolve('laravel.file')); + }), + + + 'laravel.file' => array('singleton' => true, 'resolver' => function($container) + { + return new File($container->resolve('laravel.config')->get('mimes')); + }), + + + 'laravel.form' => array('singleton' => true, '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.hasher' => array('singleton' => true, 'resolver' => function($container) + { + return new Security\Hashing\Bcrypt(8); + }), + + + 'laravel.html' => array('singleton' => true, '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) + { + $request = $container->resolve('laravel.request'); + + $input = array(); + + if ($request->method() == 'GET') + { + $input = $_GET; + } + elseif ($request->method() == 'POST') + { + $input = $_POST; + } + elseif ($request->method() == 'PUT' or $request->method == 'DELETE') + { + ($request->spoofed()) ? $input = $_POST : parse_str(file_get_contents('php://input'), $input); + } + + unset($input['_REQUEST_METHOD_']); + + return new Input($container->resolve('laravel.file'), $container->resolve('laravel.cookie'), $input, $_FILES); + }), + + + 'laravel.lang' => array('singleton' => true, 'resolver' => function($container) + { + require_once SYS_PATH.'lang'.EXT; + + return new Lang_Factory($container->resolve('laravel.config'), array(SYS_LANG_PATH, LANG_PATH)); + }), + + + 'laravel.loader' => array('singleton' => true, 'resolver' => function($container) + { + require_once SYS_PATH.'loader'.EXT; + + $aliases = $container->resolve('laravel.config')->get('aliases'); + + return new Loader(array(BASE_PATH, APP_PATH.'models/', APP_PATH.'libraries/'), $aliases); + }), + + + 'laravel.package' => array('singleton' => true, 'resolver' => function() + { + return new Package(PACKAGE_PATH); + }), + + + 'laravel.redirect' => array('singleton' => true, 'resolver' => function($container) + { + return new Redirect($container->resolve('laravel.url')); + }), + + + 'laravel.request' => array('singleton' => true, 'resolver' => function($container) + { + return new Request($_SERVER, $_POST, $container->resolve('laravel.config')->get('application.url')); + }), + + + 'laravel.response' => array('singleton' => true, 'resolver' => function($container) + { + require_once SYS_PATH.'response'.EXT; + + return new Response_Factory($container->resolve('laravel.view'), $container->resolve('laravel.file')); + }), + + + 'laravel.routing.router' => array('singleton' => true, 'resolver' => function($container) + { + return new Routing\Router(require APP_PATH.'routes'.EXT, CONTROLLER_PATH); + }), + + + 'laravel.routing.caller' => array('resolver' => function($container) + { + return new Routing\Caller($container, require APP_PATH.'filters'.EXT, CONTROLLER_PATH); + }), + + + 'laravel.session.manager' => array('singleton' => true, 'resolver' => function($c) + { + $config = $c->resolve('laravel.config'); + + $driver = $c->resolve('laravel.session.'.$config->get('session.driver')); + + return new Session\Manager($driver, $c->resolve('laravel.session.transporter'), $config); + }), + + + 'laravel.session.transporter' => array('resolver' => function($c) + { + return new Session\Transporters\Cookie($c->resolve('laravel.cookie')); + }), + + + 'laravel.url' => array('singleton' => true, 'resolver' => function($container) + { + list($request, $base, $index) = array( + $container->resolve('laravel.request'), + $container->resolve('laravel.config')->get('application.url'), + $container->resolve('laravel.config')->get('application.index'), + ); + + return new URL($container->resolve('laravel.routing.router'), $base, $index, $request->secure()); + }), + + + 'laravel.validator' => array('singleton' => true, 'resolver' => function($container) + { + require_once SYS_PATH.'validation/validator'.EXT; + + return new Validation\Validator_Factory($container->resolve('laravel.lang')); + }), + + + 'laravel.view' => array('singleton' => true, 'resolver' => function($container) + { + require_once SYS_PATH.'view'.EXT; + + return new View_Factory($container->resolve('laravel.view.composer'), VIEW_PATH); + }), + + + 'laravel.view.composer' => array('resolver' => function($container) + { + return new View_Composer(require APP_PATH.'composers'.EXT); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel Cookie Session Components + |-------------------------------------------------------------------------- + */ + + 'laravel.session.cookie' => array('resolver' => function($container) + { + $cookies = $container->resolve('laravel.cookie'); + + $config = $container->resolve('laravel.config')->get('session'); + + return new Session\Drivers\Cookie($container->resolve('laravel.crypter'), $cookies); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel Database Session Components + |-------------------------------------------------------------------------- + */ + + 'laravel.session.database' => array('resolver' => function($container) + { + $table = $container->resolve('laravel.config')->get('session.table'); + + return new Session\Drivers\Database($container->resolve('laravel.database')->connection()); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel Cache Manager + |-------------------------------------------------------------------------- + */ + + 'laravel.cache' => array('singleton' => true, 'resolver' => function($container) + { + return new Cache\Manager($container, $container->resolve('laravel.config')->get('cache.driver')); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel File Cache & Session Components + |-------------------------------------------------------------------------- + */ + + 'laravel.cache.file' => array('resolver' => function($container) + { + return new Cache\Drivers\File($container->resolve('laravel.file'), CACHE_PATH); + }), + + + 'laravel.session.file' => array('resolver' => function($container) + { + return new Session\Drivers\File($container->resolve('laravel.file'), SESSION_PATH); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel APC Cache & Session Components + |-------------------------------------------------------------------------- + */ + + 'laravel.cache.apc' => array('resolver' => function($container) + { + return new Cache\Drivers\APC(new Proxy, $container->resolve('laravel.config')->get('cache.key')); + }), + + + 'laravel.session.id' => array('singleton' => true, 'resolver' => function($container) + { + return $container->resolve('laravel.cookie')->get('laravel_session'); + }), + + + 'laravel.session.apc' => array('resolver' => function($container) + { + $lifetime = $container->resolve('laravel.config')->get('session.lifetime'); + + return new Session\Drivers\APC($container->resolve('laravel.cache.apc')); + }), + + /* + |-------------------------------------------------------------------------- + | Laravel Memcached Cache & Session Components + |-------------------------------------------------------------------------- + */ + + 'laravel.cache.memcached' => array('resolver' => function($container) + { + $connection = $container->resolve('laravel.cache.memcache.connection'); + + $key = $container->resolve('laravel.config')->get('cache.key'); + + return new Cache\Drivers\Memcached($connection, $key); + }), + + + 'laravel.session.memcached' => array('resolver' => function($container) + { + $lifetime = $container->resolve('laravel.config')->get('session.lifetime'); + + return new Session\Drivers\Memcached($container->resolve('laravel.cache.memcached')); + }), + + + 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($container) + { + if ( ! class_exists('Memcache')) + { + throw new \Exception('Attempting to use Memcached, but the Memcache PHP extension is not installed on this server.'); + } + + $memcache = new \Memcache; + + foreach ($container->resolve('laravel.config')->get('cache.servers') as $server) + { + $memcache->addServer($server['host'], $server['port'], true, $server['weight']); + } + + if ($memcache->getVersion() === false) + { + throw new \Exception('Memcached is configured. However, no connections could be made. Please verify your memcached configuration.'); + } + + return $memcache; + }), + ); \ No newline at end of file