diff --git a/application/config/aliases.php b/application/config/aliases.php deleted file mode 100644 index b3dcb23f..00000000 --- a/application/config/aliases.php +++ /dev/null @@ -1,48 +0,0 @@ - 'System\\Asset', - 'Auth' => 'System\\Auth', - 'Benchmark' => 'System\\Benchmark', - 'Cache' => 'System\\Cache', - 'Config' => 'System\\Config', - 'Cookie' => 'System\\Cookie', - 'Crypter' => 'System\\Crypter', - 'DB' => 'System\\DB', - 'Eloquent' => 'System\\DB\\Eloquent\\Model', - 'File' => 'System\\File', - 'Form' => 'System\\Form', - 'Hash' => 'System\\Hash', - 'HTML' => 'System\\HTML', - 'Inflector' => 'System\\Inflector', - 'Input' => 'System\\Input', - 'Lang' => 'System\\Lang', - 'Loader' => 'System\\Loader', - 'Package' => 'System\\Package', - 'URL' => 'System\\URL', - 'Redirect' => 'System\\Redirect', - 'Request' => 'System\\Request', - 'Response' => 'System\\Response', - 'Session' => 'System\\Session', - 'Str' => 'System\\Str', - 'Validator' => 'System\\Validator', - 'View' => 'System\\View', - -); \ No newline at end of file diff --git a/application/views/error/404.php b/application/views/error/404.php index f5c3729e..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/application/views/error/500.php b/application/views/error/500.php index 5c9bc1b2..b9866194 100644 --- a/application/views/error/500.php +++ b/application/views/error/500.php @@ -81,7 +81,7 @@

-

Something failed while we were handling your request. Would you like go to our home page instead?

+

Something failed while we were handling your request. Would you like go to our home page instead?

\ No newline at end of file diff --git a/changelog.md b/changelog.md index 1a3bd2c1..5eeb29fa 100644 --- a/changelog.md +++ b/changelog.md @@ -1,14 +1,5 @@ # Laravel Change Log -## Version 1.5.3 - -- Various bug fixes. -- Allow columns to be specified on Eloquent queries. - -### Upgrading From 1.5.2 - -- Replace **system** directory. - ## Version 1.5.2 - Moved **system/db/manager.php** to **system/db.php**. Updated alias appropriately. diff --git a/application/config/.gitignore b/config/.gitignore similarity index 100% rename from application/config/.gitignore rename to config/.gitignore diff --git a/config/aliases.php b/config/aliases.php new file mode 100644 index 00000000..4c37e3cc --- /dev/null +++ b/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/application/config/application.php b/config/application.php similarity index 81% rename from application/config/application.php rename to config/application.php index 2a6656bd..c487c23b 100644 --- a/application/config/application.php +++ b/config/application.php @@ -11,7 +11,7 @@ | */ - 'url' => 'http://localhost', + 'url' => 'http://beta.laravel.com', /* |-------------------------------------------------------------------------- @@ -82,23 +82,6 @@ 'packages' => array(), - /* - |-------------------------------------------------------------------------- - | Active Modules - |-------------------------------------------------------------------------- - | - | Modules are a convenient way to organize your application into logical - | components. Each module may have its own libraries, models, routes, - | views, language files, and configuration. - | - | Here you may specify which modules are "active" for your application. - | This simply gives Laravel an easy way to know which directories to - | check when auto-loading your classes, routes, and views. - | - */ - - 'modules' => array(), - /* |-------------------------------------------------------------------------- | Application Key diff --git a/application/config/ascii.php b/config/ascii.php similarity index 100% rename from application/config/ascii.php rename to config/ascii.php diff --git a/application/config/auth.php b/config/auth.php similarity index 100% rename from application/config/auth.php rename to config/auth.php diff --git a/application/config/cache.php b/config/cache.php similarity index 100% rename from application/config/cache.php rename to config/cache.php diff --git a/application/config/db.php b/config/db.php similarity index 100% rename from application/config/db.php rename to config/db.php diff --git a/application/config/error.php b/config/error.php similarity index 100% rename from application/config/error.php rename to config/error.php diff --git a/application/config/mimes.php b/config/mimes.php similarity index 100% rename from application/config/mimes.php rename to config/mimes.php diff --git a/application/config/session.php b/config/session.php similarity index 100% rename from application/config/session.php rename to config/session.php diff --git a/system/arr.php b/laravel/arr.php similarity index 77% rename from system/arr.php rename to laravel/arr.php index c69e5707..63fd99b7 100644 --- a/system/arr.php +++ b/laravel/arr.php @@ -1,4 +1,4 @@ - + * // Returns "taylor" + * Arr::get(array('name' => array('is' => 'Taylor')), 'name.is'); + * + * * @param array $array * @param string $key * @param mixed $default @@ -37,8 +42,16 @@ public static function get($array, $key, $default = null) * This method is primarly helpful for setting the value in an array with * a variable depth, such as configuration arrays. * + * If the specified item doesn't exist, it will be created. If the item's + * parents do no exist, they will also be created as arrays. + * * Like the Arr::get method, JavaScript "dot" syntax is supported. * + * + * // Set "name.is" to "taylor" + * Arr::set(array('name' => array('is' => 'something')), 'name.is', 'taylor'); + * + * * @param array $array * @param string $key * @param mixed $value diff --git a/system/asset.php b/laravel/asset.php similarity index 79% rename from system/asset.php rename to laravel/asset.php index 068d91be..3bdbe948 100644 --- a/system/asset.php +++ b/laravel/asset.php @@ -1,7 +1,7 @@ - + * // Get the default asset container + * $container = Asset::container(); + * + * // Get the "footer" asset container + * $container = Asset::container('footer'); + * + * * @param string $container * @return Asset_Container */ @@ -36,6 +44,17 @@ public static function container($container = 'default') /** * Magic Method for calling methods on the default Asset container. + * + * 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) { @@ -49,6 +68,8 @@ class Asset_Container { /** * The asset container name. * + * This name may be used to access the container instance via the Asset::container method. + * * @var string */ public $name; @@ -82,6 +103,14 @@ 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 @@ -103,7 +132,6 @@ public function add($name, $source, $dependencies = array(), $attributes = array * @param array $dependencies * @param array $attributes * @return void - * @see add */ public function style($name, $source, $dependencies = array(), $attributes = array()) { @@ -123,7 +151,6 @@ public function style($name, $source, $dependencies = array(), $attributes = arr * @param array $dependencies * @param array $attributes * @return void - * @see add */ public function script($name, $source, $dependencies = array(), $attributes = array()) { @@ -131,7 +158,9 @@ public function script($name, $source, $dependencies = array(), $attributes = ar } /** - * Add an asset to the registered assets. + * Add an asset to the array of registered assets. + * + * Assets are organized in the array by type (CSS or JavaScript). * * @param string $type * @param string $name @@ -150,6 +179,10 @@ 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() @@ -160,6 +193,10 @@ public function styles() /** * Get the links to all of the registered JavaScript assets. * + * + * echo Asset::container()->scripts(); + * + * * @return string */ public function scripts() @@ -168,7 +205,7 @@ public function scripts() } /** - * Get all of the registered assets for a given group. + * Get all of the registered assets for a given type / group. * * @param string $group * @return string @@ -190,6 +227,10 @@ 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 */ @@ -201,6 +242,10 @@ 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 */ @@ -210,7 +255,7 @@ public function get_script($name) } /** - * Get a registered asset. + * Get the HTML link to a registered asset. * * @param string $group * @param string $name @@ -287,7 +332,10 @@ private function evaluate_asset($asset, $value, $original, &$sorted, &$assets) } /** - * Check that a dependency is valid. + * Verify that an asset's dependency is valid. + * + * A dependency is considered valid if it exists, is not a circular reference, and is + * not a reference to the owning asset itself. * * @param string $asset * @param string $dependency @@ -297,11 +345,9 @@ private function evaluate_asset($asset, $value, $original, &$sorted, &$assets) */ private function dependency_is_valid($asset, $dependency, $original, $assets) { - if ( ! isset($original[$dependency])) - { - return false; - } - elseif ($dependency === $asset) + if ( ! isset($original[$dependency])) return false; + + if ($dependency === $asset) { throw new \Exception("Asset [$asset] is dependent on itself."); } diff --git a/system/auth.php b/laravel/auth.php similarity index 84% rename from system/auth.php rename to laravel/auth.php index d4f037a2..b5be35b9 100644 --- a/system/auth.php +++ b/laravel/auth.php @@ -1,4 +1,4 @@ - + * $email = Auth::user()->email; + * + * * @return object - * @see $user */ public static function user() { @@ -65,6 +69,13 @@ public static function user() * The password passed to the method should be plain text, as it will be hashed * by the Hash class when authenticating. * + * + * if (Auth::login('email@example.com', 'password')) + * { + * // The credentials are valid and the user is now logged in. + * } + * + * * @param string $username * @param string $password * @return bool @@ -88,7 +99,8 @@ public static function login($username, $password) * Log a user into your application. * * The user's ID will be stored in the session and the user will be considered - * "logged in" on subsequent requests to your application. + * "logged in" on subsequent requests to your application. This method is called + * by the login method after determining a user's credentials are valid. * * Note: The user given to this method should be an object having an "id" property. * @@ -106,7 +118,7 @@ public static function remember($user) * Log the user out of your application. * * The user ID will be removed from the session and the user will no longer - * be considered logged in on subsequent requests. + * be considered logged in on subsequent requests to your application. * * @return void */ diff --git a/system/benchmark.php b/laravel/benchmark.php similarity index 93% rename from system/benchmark.php rename to laravel/benchmark.php index c9c6c09d..a594c41d 100644 --- a/system/benchmark.php +++ b/laravel/benchmark.php @@ -1,4 +1,4 @@ - + * // Get the default cache driver + * $driver = Cache::driver(); + * + * // Get the APC cache driver + * $apc = Cache::driver('apc'); + * + * + * @param string $driver + * @return Cache\Driver + */ + public static function driver($driver = null) + { + if (is_null($driver)) $driver = Config::get('cache.driver'); + + if ( ! array_key_exists($driver, static::$drivers)) + { + switch ($driver) + { + case 'file': + return static::$drivers[$driver] = new Cache\File; + + case 'memcached': + return static::$drivers[$driver] = new Cache\Memcached; + + case 'apc': + return static::$drivers[$driver] = new Cache\APC; + + default: + throw new \Exception("Cache driver [$driver] is not supported."); + } + } + + return static::$drivers[$driver]; + } + + /** + * Pass all other methods to the default driver. + * + * 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 = Cache::get('name'); + * + */ + public static function __callStatic($method, $parameters) + { + return call_user_func_array(array(static::driver(), $method), $parameters); + } + +} \ No newline at end of file diff --git a/laravel/cache/apc.php b/laravel/cache/apc.php new file mode 100644 index 00000000..54964604 --- /dev/null +++ b/laravel/cache/apc.php @@ -0,0 +1,29 @@ +get($key))); + } + + public function get($key, $default = null) + { + $item = ( ! is_null($cache = apc_fetch(Config::get('cache.key').$key))) ? $cache : null; + + return $this->prepare($item, $default); + } + + public function put($key, $value, $minutes) + { + apc_store(Config::get('cache.key').$key, $value, $minutes * 60); + } + + public function forget($key) + { + apc_delete(Config::get('cache.key').$key); + } + +} \ No newline at end of file diff --git a/laravel/cache/driver.php b/laravel/cache/driver.php new file mode 100644 index 00000000..a4a218a7 --- /dev/null +++ b/laravel/cache/driver.php @@ -0,0 +1,93 @@ + + * // 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 + * @return mixed + */ + abstract public function get($key, $default = null); + + /** + * Prepare the cache item for returning to the requestor. + * + * If the item is NULL, the default will be returned. + * + * @param mixed $item + * @param mixed $default + * @return mixed + */ + protected function prepare($item, $default) + { + if ( ! is_null($item)) return $item; + + return (is_callable($default)) ? call_user_func($default) : $default; + } + + /** + * Write an item to the cache. + * + * @param string $key + * @param mixed $value + * @param int $minutes + * @return void + */ + 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 + * @return mixed + */ + public function remember($key, $value, $minutes) + { + if ( ! is_null($item = $this->get($key, null, $driver))) return $item; + + $default = is_callable($default) ? call_user_func($default) : $default; + + $this->put($key, $default, $minutes); + + return $default; + } + + /** + * Delete an item from the cache. + * + * @param string $key + * @return void + */ + abstract public function forget($key); + +} \ No newline at end of file diff --git a/laravel/cache/file.php b/laravel/cache/file.php new file mode 100644 index 00000000..65f591db --- /dev/null +++ b/laravel/cache/file.php @@ -0,0 +1,41 @@ +get($key))); + } + + public function get($key, $default = null) + { + if ( ! file_exists(CACHE_PATH.$key)) + { + return $this->prepare(null, $default); + } + + $cache = file_get_contents(CACHE_PATH.$key); + + // The cache expiration date is stored as a UNIX timestamp at the beginning + // of the cache file. We'll extract it out and check it here. + if (time() >= substr($cache, 0, 10)) + { + $this->forget($key); + + return $this->prepare(null, $default); + } + + return $this->prepare(unserialize(substr($cache, 10)), $default); + } + + public function put($key, $value, $minutes) + { + file_put_contents(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); + } + + public function forget($key) + { + @unlink(CACHE_PATH.$key); + } + +} \ No newline at end of file diff --git a/laravel/cache/memcached.php b/laravel/cache/memcached.php new file mode 100644 index 00000000..fd150d62 --- /dev/null +++ b/laravel/cache/memcached.php @@ -0,0 +1,30 @@ +get($key))); + } + + public function get($key, $default = null) + { + $item = (($cache = Mem::instance()->get(Config::get('cache.key').$key)) !== false) ? $cache : null; + + return $this->prepare($item, $default); + } + + public function put($key, $value, $minutes) + { + Mem::instance()->set(Config::get('cache.key').$key, $value, 0, $minutes * 60); + } + + public function forget($key) + { + Mem::instance()->delete(Config::get('cache.key').$key); + } + +} \ No newline at end of file diff --git a/laravel/config.php b/laravel/config.php new file mode 100644 index 00000000..e14765fd --- /dev/null +++ b/laravel/config.php @@ -0,0 +1,170 @@ + + * // Determine if the "session" configuration file exists + * Config::has('session'); + * + * // Determine if the application timezone option exists + * Config::has('application.timezone'); + * + * + * @param string $key + * @return bool + */ + public static function has($key) + { + return ! is_null(static::get($key)); + } + + /** + * Get a configuration item. + * + * Configuration items are retrieved using "dot" notation. So, asking for the + * "application.timezone" configuration item would return the "timezone" option + * from the "application" configuration file. + * + * If the name of a configuration file is passed without specifying an item, the + * entire configuration array will be returned. + * + * + * // Get the timezone option from the application configuration file + * $timezone = Config::get('application.timezone'); + * + * // Get the SQLite database connection configuration + * $sqlite = Config::get('db.connections.sqlite'); + * + * + * @param string $key + * @param string $default + * @return array + */ + public static function get($key, $default = null) + { + list($module, $file, $key) = static::parse($key); + + if ( ! static::load($module, $file)) + { + return is_callable($default) ? call_user_func($default) : $default; + } + + if (is_null($key)) return static::$items[$module][$file]; + + return Arr::get(static::$items[$module][$file], $key, $default); + } + + /** + * Set a configuration item. + * + * Like the get method, "dot" notation is used to set items, and setting items + * at any depth in the configuration array is supported. + * + * If a specific configuration item is not specified, the entire configuration + * array will be replaced with the given value. + * + * + * // Set the timezone option in the application configuration file + * Config::set('application.timezone', 'America/Chicago'); + * + * // Set the session configuration array + * Config::set('session', array()); + * + * + * @param string $key + * @param mixed $value + * @return void + */ + public static function set($key, $value) + { + list($module, $file, $key) = static::parse($key); + + if ( ! static::load($module, $file)) + { + throw new \Exception("Error setting configuration option. Configuration file [$file] is not defined."); + } + + Arr::set(static::$items[$module][$file], $key, $value); + } + + /** + * Parse a configuration key and return its module, file, and key segments. + * + * Modular configuration keys follow a {module}::{file}.{key} convention. + * + * @param string $key + * @return array + */ + private static function parse($key) + { + list($module, $key) = Module::parse($key); + + $segments = explode('.', $key); + + return array($module, $segments[0], (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null); + } + + /** + * Load all of the configuration items from a module configuration file. + * + * If the configuration file has already been loaded, it will not be loaded again. + * + * @param string $file + * @param string $module + * @return bool + */ + private static function load($module, $file) + { + if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true; + + $config = array(); + + foreach (static::paths($module, $file) as $directory) + { + $config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config; + } + + if (count($config) > 0) static::$items[$module][$file] = $config; + + return isset(static::$items[$module][$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. + * + * By default, the base configuration directory will be searched first, followed by the configuration + * directory for the active module. Next, any environment specific configuration directories + * will be searched. + * + * @param string $module + * @param string $file + * @return array + */ + private static function paths($module, $file) + { + $paths = array(CONFIG_PATH, Module::path($module).'config/'); + + if (isset($_SERVER['LARAVEL_ENV'])) + { + $paths[] = Module::path($module).'/config/'.$_SERVER['LARAVEL_ENV'].'/'; + } + + return $paths; + } + +} \ No newline at end of file diff --git a/system/cookie.php b/laravel/cookie.php similarity index 98% rename from system/cookie.php rename to laravel/cookie.php index 6bba4e7c..bf252e16 100644 --- a/system/cookie.php +++ b/laravel/cookie.php @@ -1,4 +1,4 @@ -exception->getFile()); + $file = str_replace(array(ACTIVE_MODULE_PATH, SYS_PATH), array('MODULE_PATH/', 'SYS_PATH/'), $this->exception->getFile()); return rtrim($this->exception->getMessage(), '.').' in '.$file.' on line '.$this->exception->getLine().'.'; } diff --git a/system/exception/handler.php b/laravel/exception/handler.php similarity index 95% rename from system/exception/handler.php rename to laravel/exception/handler.php index da7684f0..3e21da5e 100644 --- a/system/exception/handler.php +++ b/laravel/exception/handler.php @@ -1,8 +1,8 @@ - 1) { - return array($module, $segments[0], $segments[1]); + return array($module, $segments[0], implode('.', array_slice($segments, 1))); } throw new \Exception("Invalid language line [$key]. A specific line must be specified."); @@ -120,9 +115,7 @@ private function load($module, $file, $language) { if (isset(static::$lines[$module][$language.$file])) return; - $path = ($module === 'application') ? LANG_PATH : MODULE_PATH.$module.'/lang/'; - - if (file_exists($path = $path.$language.'/'.$file.EXT)) + if (file_exists($path = Module::path($module).'lang/'.$language.'/'.$file.EXT)) { static::$lines[$module][$language.$file] = require $path; } diff --git a/system/laravel.php b/laravel/laravel.php similarity index 76% rename from system/laravel.php rename to laravel/laravel.php index b48bb3cc..1f19dfc3 100644 --- a/system/laravel.php +++ b/laravel/laravel.php @@ -1,51 +1,61 @@ -handle(); }); -set_error_handler(function($number, $error, $file, $line) +set_error_handler(function($number, $error, $file, $line) use ($error_dependencies) { - require_once SYS_PATH.'exception/handler'.EXT; - require_once SYS_PATH.'exception/examiner'.EXT; - require_once SYS_PATH.'file'.EXT; + call_user_func($error_dependencies); Exception\Handler::make(new \ErrorException($error, $number, 0, $file, $line))->handle(); }); -register_shutdown_function(function() +register_shutdown_function(function() use ($error_dependencies) { if ( ! is_null($error = error_get_last())) { - require_once SYS_PATH.'exception/handler'.EXT; - require_once SYS_PATH.'exception/examiner'.EXT; - require_once SYS_PATH.'file'.EXT; + call_user_func($error_dependencies); extract($error); @@ -97,10 +108,7 @@ // -------------------------------------------------------------- // Load the session. // -------------------------------------------------------------- -if (Config::get('session.driver') != '') -{ - Session::load(Cookie::get('laravel_session')); -} +if (Config::get('session.driver') != '') Session::load(Cookie::get('laravel_session')); // -------------------------------------------------------------- // Load all of the core routing classes. @@ -127,21 +135,19 @@ // -------------------------------------------------------------- $segments = explode('/', Request::uri()); -define('ACTIVE_MODULE', (in_array($segments[0], Config::get('application.modules'))) ? $segments[0] : 'application'); +define('ACTIVE_MODULE', (array_key_exists($segments[0], Module::$modules)) ? $segments[0] : DEFAULT_MODULE); // -------------------------------------------------------------- // Determine the path to the root of the active module. // -------------------------------------------------------------- -define('ACTIVE_MODULE_PATH', (ACTIVE_MODULE == 'application') ? APP_PATH : MODULE_PATH.ACTIVE_MODULE.'/'); +define('ACTIVE_MODULE_PATH', Module::path(ACTIVE_MODULE)); // -------------------------------------------------------------- // Register the filters for the active module. // -------------------------------------------------------------- -Routing\Filter::register(require APP_PATH.'filters'.EXT); - -if (ACTIVE_MODULE !== 'application' and file_exists($filters = ACTIVE_MODULE_PATH.'filters'.EXT)) +if (file_exists(ACTIVE_MODULE_PATH.'filters'.EXT)) { - Routing\Filter::register(require $filters); + Routing\Filter::register(require ACTIVE_MODULE_PATH.'filters'.EXT); } // -------------------------------------------------------------- @@ -159,7 +165,9 @@ // -------------------------------------------------------------- if (is_null($response)) { - $route = Routing\Router::make(Request::method(), Request::uri(), new Routing\Loader(ACTIVE_MODULE_PATH))->route(); + $loader = new Routing\Loader(ACTIVE_MODULE_PATH); + + $route = Routing\Router::make(Request::method(), Request::uri(), $loader)->route(); $response = (is_null($route)) ? Response::error('404') : $route->call(); } @@ -182,10 +190,7 @@ // -------------------------------------------------------------- // Close the session. // -------------------------------------------------------------- -if (Config::get('session.driver') != '') -{ - Session::close(); -} +if (Config::get('session.driver') != '') Session::close(); // -------------------------------------------------------------- // Send the response to the browser. diff --git a/system/loader.php b/laravel/loader.php similarity index 91% rename from system/loader.php rename to laravel/loader.php index a2300851..9124905b 100644 --- a/system/loader.php +++ b/laravel/loader.php @@ -1,4 +1,4 @@ - 0 and ACTIVE_MODULE !== 'application') + if (count($segments) > 0 and ACTIVE_MODULE !== DEFAULT_MODULE) { array_shift($segments); } @@ -87,21 +87,15 @@ private function load_nested_routes($segments) * will be cached and returned on every subsequent call. * * @param bool $reload - * @param string $path * @return array */ - public static function all($reload = false, $path = APP_PATH) + public static function all($reload = false) { if ( ! is_null(static::$routes) and ! $reload) return static::$routes; - // Merge all of the module paths in with the specified path so that all - // active module routes will also be loaded. So, by default, this method - // will search the application path and all active module paths for routes. - $paths = array_merge(array($path), array_map(function($module) { return MODULE_PATH.$module.'/'; }, Config::get('application.modules'))); - $routes = array(); - foreach ($paths as $path) + foreach (Module::paths() as $path) { if (file_exists($path.'routes'.EXT)) { diff --git a/system/routing/route.php b/laravel/routing/route.php similarity index 96% rename from system/routing/route.php rename to laravel/routing/route.php index d3dc4a01..5f2bc590 100644 --- a/system/routing/route.php +++ b/laravel/routing/route.php @@ -1,7 +1,7 @@ - realpath('../application'), +); // -------------------------------------------------------------- -// The path to the system directory. +// The path to the Laravel directory. // -------------------------------------------------------------- -$system = '../system'; +$system = '../laravel'; + +// -------------------------------------------------------------- +// The path to the configuration directory. +// -------------------------------------------------------------- +$config = '../config'; // -------------------------------------------------------------- // The path to the packages directory. // -------------------------------------------------------------- -$packages = '../packages'; +$packages = '../packages'; // -------------------------------------------------------------- // The path to the modules directory. // -------------------------------------------------------------- -$modules = '../modules'; +$modules = '../modules'; // -------------------------------------------------------------- // The path to the storage directory. // -------------------------------------------------------------- -$storage = '../storage'; +$storage = '../storage'; // -------------------------------------------------------------- // The path to the public directory. // -------------------------------------------------------------- -$public = __DIR__; +$public = __DIR__; // -------------------------------------------------------------- // Launch Laravel. diff --git a/system/cache.php b/system/cache.php deleted file mode 100644 index b08344db..00000000 --- a/system/cache.php +++ /dev/null @@ -1,96 +0,0 @@ -get($key))) - { - return is_callable($default) ? call_user_func($default) : $default; - } - - return $item; - } - - /** - * 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. - * - * @param string $key - * @param mixed $default - * @param int $minutes - * @param string $driver - * @return mixed - */ - public static function remember($key, $default, $minutes, $driver = null) - { - if ( ! is_null($item = static::get($key, null, $driver))) return $item; - - $default = is_callable($default) ? call_user_func($default) : $default; - - static::driver($driver)->put($key, $default, $minutes); - - return $default; - } - - /** - * Pass all other methods to the default driver. - * - * Passing method calls to the driver instance provides a better API for you. - * For instance, instead of saying Cache::driver()->foo(), you can just say Cache::foo(). - */ - public static function __callStatic($method, $parameters) - { - return call_user_func_array(array(static::driver(), $method), $parameters); - } - -} \ No newline at end of file diff --git a/system/cache/apc.php b/system/cache/apc.php deleted file mode 100644 index deb07090..00000000 --- a/system/cache/apc.php +++ /dev/null @@ -1,53 +0,0 @@ -get($key))); - } - - /** - * Get an item from the cache. - * - * @param string $key - * @return mixed - */ - public function get($key) - { - return ( ! is_null($cache = apc_fetch(Config::get('cache.key').$key))) ? $cache : null; - } - - /** - * Write an item to the cache. - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return void - */ - public function put($key, $value, $minutes) - { - apc_store(Config::get('cache.key').$key, $value, $minutes * 60); - } - - /** - * Delete an item from the cache. - * - * @param string $key - * @return void - */ - public function forget($key) - { - apc_delete(Config::get('cache.key').$key); - } - -} \ No newline at end of file diff --git a/system/cache/driver.php b/system/cache/driver.php deleted file mode 100644 index 69a93289..00000000 --- a/system/cache/driver.php +++ /dev/null @@ -1,39 +0,0 @@ -get($key))); - } - - /** - * Get an item from the cache. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function get($key) - { - if ( ! file_exists(CACHE_PATH.$key)) - { - return null; - } - - $cache = file_get_contents(CACHE_PATH.$key); - - // The cache expiration date is stored as a UNIX timestamp at the beginning - // of the cache file. We'll extract it out and check it here. - if (time() >= substr($cache, 0, 10)) return $this->forget($key); - - return unserialize(substr($cache, 10)); - } - - /** - * Write an item to the cache. - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return void - */ - public function put($key, $value, $minutes) - { - file_put_contents(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); - } - - /** - * Delete an item from the cache. - * - * @param string $key - * @return void - */ - public function forget($key) - { - @unlink(CACHE_PATH.$key); - } - -} \ No newline at end of file diff --git a/system/cache/memcached.php b/system/cache/memcached.php deleted file mode 100644 index cb68cf7d..00000000 --- a/system/cache/memcached.php +++ /dev/null @@ -1,53 +0,0 @@ -get($key))); - } - - /** - * Get an item from the cache. - * - * @param string $key - * @return mixed - */ - public function get($key) - { - return (($cache = \System\Memcached::instance()->get(Config::get('cache.key').$key)) !== false) ? $cache : null; - } - - /** - * Write an item to the cache. - * - * @param string $key - * @param mixed $value - * @param int $minutes - * @return void - */ - public function put($key, $value, $minutes) - { - \System\Memcached::instance()->set(Config::get('cache.key').$key, $value, 0, $minutes * 60); - } - - /** - * Delete an item from the cache. - * - * @param string $key - * @return void - */ - public function forget($key) - { - \System\Memcached::instance()->delete(Config::get('cache.key').$key); - } - -} \ No newline at end of file diff --git a/system/config.php b/system/config.php deleted file mode 100644 index a30cfd82..00000000 --- a/system/config.php +++ /dev/null @@ -1,124 +0,0 @@ - 1) ? implode('.', array_slice($segments, 1)) : null; - - return array($module, $segments[0], $key); - } - - /** - * Load all of the configuration items from a file. - * - * Laravel supports environment specific configuration files. So, the base configuration - * array will be loaded first, then any environment specific options will be merged in. - * - * @param string $file - * @param string $module - * @return bool - */ - private static function load($module, $file) - { - if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true; - - $path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/'; - - // Load the base configuration file. Once that is loaded, we will merge any environment - // specific configuration options into the base array. This allows for the convenient - // cascading of configuration options depending on the application environment. - $config = (file_exists($base = $path.$file.EXT)) ? require $base : array(); - - if (isset($_SERVER['LARAVEL_ENV']) and file_exists($path = $path.$_SERVER['LARAVEL_ENV'].'/'.$file.EXT)) - { - $config = array_merge($config, require $path); - } - - if (count($config) > 0) static::$items[$module][$file] = $config; - - return isset(static::$items[$module][$file]); - } - -} \ No newline at end of file