From d9f2ba84c9ac97c9242f95b1888c68d1812e0480 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 18 Aug 2011 23:23:57 -0500 Subject: [PATCH] 2.0 modular refactoring. --- config/aliases.php | 48 --------- laravel/config/aliases.php | 48 +++++++++ {config => laravel/config}/application.php | 0 {config => laravel/config}/ascii.php | 0 {config => laravel/config}/auth.php | 0 {config => laravel/config}/cache.php | 0 {config => laravel/config}/db.php | 0 {config => laravel/config}/error.php | 0 {config => laravel/config}/mimes.php | 0 {config => laravel/config}/session.php | 0 laravel/lang.php | 18 ++-- .../lang/en/pagination.php | 0 .../lang/en/validation.php | 0 laravel/laravel.php | 25 +++-- laravel/module.php | 7 +- .../application/config}/.gitignore | 0 modules/application/config/application.php | 98 +++++++++++++++++++ public/index.php | 9 +- 18 files changed, 180 insertions(+), 73 deletions(-) delete mode 100644 config/aliases.php create mode 100644 laravel/config/aliases.php rename {config => laravel/config}/application.php (100%) rename {config => laravel/config}/ascii.php (100%) rename {config => laravel/config}/auth.php (100%) rename {config => laravel/config}/cache.php (100%) rename {config => laravel/config}/db.php (100%) rename {config => laravel/config}/error.php (100%) rename {config => laravel/config}/mimes.php (100%) rename {config => laravel/config}/session.php (100%) rename {modules/application => laravel}/lang/en/pagination.php (100%) rename {modules/application => laravel}/lang/en/validation.php (100%) rename {config => modules/application/config}/.gitignore (100%) create mode 100644 modules/application/config/application.php diff --git a/config/aliases.php b/config/aliases.php deleted file mode 100644 index 4c37e3cc..00000000 --- a/config/aliases.php +++ /dev/null @@ -1,48 +0,0 @@ - 'Laravel\\Asset', - 'Auth' => 'Laravel\\Auth', - 'Benchmark' => 'Laravel\\Benchmark', - 'Cache' => 'Laravel\\Cache', - 'Config' => 'Laravel\\Config', - 'Cookie' => 'Laravel\\Cookie', - 'Crypter' => 'Laravel\\Crypter', - 'DB' => 'Laravel\\DB', - 'Eloquent' => 'Laravel\\DB\\Eloquent\\Model', - 'File' => 'Laravel\\File', - 'Form' => 'Laravel\\Form', - 'Hash' => 'Laravel\\Hash', - 'HTML' => 'Laravel\\HTML', - 'Inflector' => 'Laravel\\Inflector', - 'Input' => 'Laravel\\Input', - 'Lang' => 'Laravel\\Lang', - 'Loader' => 'Laravel\\Loader', - 'Package' => 'Laravel\\Package', - 'URL' => 'Laravel\\URL', - 'Redirect' => 'Laravel\\Redirect', - 'Request' => 'Laravel\\Request', - 'Response' => 'Laravel\\Response', - 'Session' => 'Laravel\\Session', - 'Str' => 'Laravel\\Str', - 'Validator' => 'Laravel\\Validator', - 'View' => 'Laravel\\View', - -); \ No newline at end of file diff --git a/laravel/config/aliases.php b/laravel/config/aliases.php new file mode 100644 index 00000000..43bc470b --- /dev/null +++ b/laravel/config/aliases.php @@ -0,0 +1,48 @@ + 'Laravel\\Asset', + 'Auth' => 'Laravel\\Auth', + 'Benchmark' => 'Laravel\\Benchmark', + 'Cache' => 'Laravel\\Cache', + 'Config' => 'Laravel\\Config', + 'Cookie' => 'Laravel\\Cookie', + 'Crypter' => 'Laravel\\Crypter', + 'DB' => 'Laravel\\DB', + 'Eloquent' => 'Laravel\\DB\\Eloquent\\Model', + 'File' => 'Laravel\\File', + 'Form' => 'Laravel\\Form', + 'Hash' => 'Laravel\\Hash', + 'HTML' => 'Laravel\\HTML', + 'Inflector' => 'Laravel\\Inflector', + 'Input' => 'Laravel\\Input', + 'Lang' => 'Laravel\\Lang', + 'Loader' => 'Laravel\\Loader', + 'Package' => 'Laravel\\Package', + 'URL' => 'Laravel\\URL', + 'Redirect' => 'Laravel\\Redirect', + 'Request' => 'Laravel\\Request', + 'Response' => 'Laravel\\Response', + 'Session' => 'Laravel\\Session', + 'Str' => 'Laravel\\Str', + 'Validator' => 'Laravel\\Validator', + 'View' => 'Laravel\\View', + +); \ No newline at end of file diff --git a/config/application.php b/laravel/config/application.php similarity index 100% rename from config/application.php rename to laravel/config/application.php diff --git a/config/ascii.php b/laravel/config/ascii.php similarity index 100% rename from config/ascii.php rename to laravel/config/ascii.php diff --git a/config/auth.php b/laravel/config/auth.php similarity index 100% rename from config/auth.php rename to laravel/config/auth.php diff --git a/config/cache.php b/laravel/config/cache.php similarity index 100% rename from config/cache.php rename to laravel/config/cache.php diff --git a/config/db.php b/laravel/config/db.php similarity index 100% rename from config/db.php rename to laravel/config/db.php diff --git a/config/error.php b/laravel/config/error.php similarity index 100% rename from config/error.php rename to laravel/config/error.php diff --git a/config/mimes.php b/laravel/config/mimes.php similarity index 100% rename from config/mimes.php rename to laravel/config/mimes.php diff --git a/config/session.php b/laravel/config/session.php similarity index 100% rename from config/session.php rename to laravel/config/session.php diff --git a/laravel/lang.php b/laravel/lang.php index 75e5d3e1..a8088406 100644 --- a/laravel/lang.php +++ b/laravel/lang.php @@ -67,14 +67,12 @@ public function get($language = null, $default = null) list($module, $file, $line) = $this->parse($this->key, $language); - $this->load($module, $file, $language); - - if ( ! isset(static::$lines[$module][$language.$file][$line])) + if ( ! $this->load($module, $file, $language)) { return is_callable($default) ? call_user_func($default) : $default; } - $line = static::$lines[$module][$language.$file][$line]; + $line = Arr::get(static::$lines[$module][$language.$file], $line, $default); foreach ($this->replacements as $key => $value) { @@ -109,16 +107,22 @@ private function parse($key, $language) * @param string $module * @param string $file * @param string $language - * @return void + * @return bool */ private function load($module, $file, $language) { if (isset(static::$lines[$module][$language.$file])) return; - if (file_exists($path = Module::path($module).'lang/'.$language.'/'.$file.EXT)) + $lang = array(); + + foreach (array(LANG_PATH, Module::path($module).'lang/') as $directory) { - static::$lines[$module][$language.$file] = require $path; + $lang = (file_exists($path = $directory.$language.'/'.$file.EXT)) ? array_merge($lang, require $path) : $lang; } + + if (count($lang) > 0) static::$lines[$module][$language.$file] = $lang; + + return isset(static::$lines[$module][$language.$file]); } /** diff --git a/modules/application/lang/en/pagination.php b/laravel/lang/en/pagination.php similarity index 100% rename from modules/application/lang/en/pagination.php rename to laravel/lang/en/pagination.php diff --git a/modules/application/lang/en/validation.php b/laravel/lang/en/validation.php similarity index 100% rename from modules/application/lang/en/validation.php rename to laravel/lang/en/validation.php diff --git a/laravel/laravel.php b/laravel/laravel.php index 1f19dfc3..6ffc4ab9 100644 --- a/laravel/laravel.php +++ b/laravel/laravel.php @@ -9,7 +9,6 @@ // Define the core framework paths. // -------------------------------------------------------------- define('BASE_PATH', realpath(str_replace('laravel', '', $system)).'/'); -define('CONFIG_PATH', realpath($config).'/'); define('MODULE_PATH', realpath($modules).'/'); define('PACKAGE_PATH', realpath($packages).'/'); define('PUBLIC_PATH', realpath($public).'/'); @@ -22,16 +21,13 @@ // Define various other framework paths. // -------------------------------------------------------------- define('CACHE_PATH', STORAGE_PATH.'cache/'); +define('CONFIG_PATH', SYS_PATH.'config/'); define('DATABASE_PATH', STORAGE_PATH.'db/'); +define('LANG_PATH', SYS_PATH.'lang/'); define('SCRIPT_PATH', PUBLIC_PATH.'js/'); define('SESSION_PATH', STORAGE_PATH.'sessions/'); define('STYLE_PATH', PUBLIC_PATH.'css/'); -// -------------------------------------------------------------- -// Define the default module. -// -------------------------------------------------------------- -define('DEFAULT_MODULE', 'application'); - // -------------------------------------------------------------- // Load the classes used by the auto-loader. // -------------------------------------------------------------- @@ -40,13 +36,23 @@ require SYS_PATH.'module'.EXT; require SYS_PATH.'arr'.EXT; +// -------------------------------------------------------------- +// Define the default module. +// -------------------------------------------------------------- +define('DEFAULT_MODULE', 'application'); + // -------------------------------------------------------------- // Register the active modules. // -------------------------------------------------------------- -Module::$modules = $active; +Module::$modules = array_merge(array('application' => 'application'), $active); unset($active); +// -------------------------------------------------------------- +// Define the default module path. +// -------------------------------------------------------------- +define('DEFAULT_MODULE_PATH', Module::path(DEFAULT_MODULE)); + // -------------------------------------------------------------- // Register the auto-loader. // -------------------------------------------------------------- @@ -142,6 +148,11 @@ // -------------------------------------------------------------- define('ACTIVE_MODULE_PATH', Module::path(ACTIVE_MODULE)); +// -------------------------------------------------------------- +// Register the filters for the default module. +// -------------------------------------------------------------- +Routing\Filter::register(require DEFAULT_MODULE_PATH.'filters'.EXT); + // -------------------------------------------------------------- // Register the filters for the active module. // -------------------------------------------------------------- diff --git a/laravel/module.php b/laravel/module.php index 6de2ea89..ab8829ab 100644 --- a/laravel/module.php +++ b/laravel/module.php @@ -43,9 +43,10 @@ public static function path($module) { if (array_key_exists($module, static::$paths)) return static::$paths[$module]; - if (array_key_exists($module, static::$modules)) $path = MODULE_PATH.static::$modules[$module].'/'; - - return static::$paths[$module] = $path; + if (array_key_exists($module, static::$modules)) + { + return static::$paths[$module] = MODULE_PATH.static::$modules[$module].'/'; + } } /** diff --git a/config/.gitignore b/modules/application/config/.gitignore similarity index 100% rename from config/.gitignore rename to modules/application/config/.gitignore diff --git a/modules/application/config/application.php b/modules/application/config/application.php new file mode 100644 index 00000000..2c0028a4 --- /dev/null +++ b/modules/application/config/application.php @@ -0,0 +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' => '', + +); \ No newline at end of file diff --git a/public/index.php b/public/index.php index 6c6a6e4c..7888af6d 100644 --- a/public/index.php +++ b/public/index.php @@ -11,20 +11,13 @@ // -------------------------------------------------------------- // The active modules for this Laravel installation. // -------------------------------------------------------------- -$active = array( - 'application' => 'application', -); +$active = array(); // -------------------------------------------------------------- // The path to the Laravel directory. // -------------------------------------------------------------- $system = '../laravel'; -// -------------------------------------------------------------- -// The path to the configuration directory. -// -------------------------------------------------------------- -$config = '../config'; - // -------------------------------------------------------------- // The path to the packages directory. // --------------------------------------------------------------