Commit 1e90e424 authored by Taylor Otwell's avatar Taylor Otwell

first commit of 2.0

parent 119b356b
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<h2><?php echo $apology; ?></h2> <h2><?php echo $apology; ?></h2>
<p>We couldn't find the resource you requested. Would you like go to our <a href="<?php echo System\Config::get('application.url'); ?>">home page</a> instead?</p> <p>We couldn't find the resource you requested. Would you like go to our <a href="<?php echo Laravel\Config::get('application.url'); ?>">home page</a> instead?</p>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<h2><?php echo $apology; ?></h2> <h2><?php echo $apology; ?></h2>
<p>Something failed while we were handling your request. Would you like go to our <a href="<?php echo System\Config::get('application.url'); ?>">home page</a> instead?</p> <p>Something failed while we were handling your request. Would you like go to our <a href="<?php echo Laravel\Config::get('application.url'); ?>">home page</a> instead?</p>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
# Laravel Change Log # 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 ## Version 1.5.2
- Moved **system/db/manager.php** to **system/db.php**. Updated alias appropriately. - Moved **system/db/manager.php** to **system/db.php**. Updated alias appropriately.
......
...@@ -18,31 +18,31 @@ return array( ...@@ -18,31 +18,31 @@ return array(
| |
*/ */
'Asset' => 'System\\Asset', 'Asset' => 'Laravel\\Asset',
'Auth' => 'System\\Auth', 'Auth' => 'Laravel\\Auth',
'Benchmark' => 'System\\Benchmark', 'Benchmark' => 'Laravel\\Benchmark',
'Cache' => 'System\\Cache', 'Cache' => 'Laravel\\Cache',
'Config' => 'System\\Config', 'Config' => 'Laravel\\Config',
'Cookie' => 'System\\Cookie', 'Cookie' => 'Laravel\\Cookie',
'Crypter' => 'System\\Crypter', 'Crypter' => 'Laravel\\Crypter',
'DB' => 'System\\DB', 'DB' => 'Laravel\\DB',
'Eloquent' => 'System\\DB\\Eloquent\\Model', 'Eloquent' => 'Laravel\\DB\\Eloquent\\Model',
'File' => 'System\\File', 'File' => 'Laravel\\File',
'Form' => 'System\\Form', 'Form' => 'Laravel\\Form',
'Hash' => 'System\\Hash', 'Hash' => 'Laravel\\Hash',
'HTML' => 'System\\HTML', 'HTML' => 'Laravel\\HTML',
'Inflector' => 'System\\Inflector', 'Inflector' => 'Laravel\\Inflector',
'Input' => 'System\\Input', 'Input' => 'Laravel\\Input',
'Lang' => 'System\\Lang', 'Lang' => 'Laravel\\Lang',
'Loader' => 'System\\Loader', 'Loader' => 'Laravel\\Loader',
'Package' => 'System\\Package', 'Package' => 'Laravel\\Package',
'URL' => 'System\\URL', 'URL' => 'Laravel\\URL',
'Redirect' => 'System\\Redirect', 'Redirect' => 'Laravel\\Redirect',
'Request' => 'System\\Request', 'Request' => 'Laravel\\Request',
'Response' => 'System\\Response', 'Response' => 'Laravel\\Response',
'Session' => 'System\\Session', 'Session' => 'Laravel\\Session',
'Str' => 'System\\Str', 'Str' => 'Laravel\\Str',
'Validator' => 'System\\Validator', 'Validator' => 'Laravel\\Validator',
'View' => 'System\\View', 'View' => 'Laravel\\View',
); );
\ No newline at end of file
...@@ -11,7 +11,7 @@ return array( ...@@ -11,7 +11,7 @@ return array(
| |
*/ */
'url' => 'http://localhost', 'url' => 'http://beta.laravel.com',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
...@@ -82,23 +82,6 @@ return array( ...@@ -82,23 +82,6 @@ return array(
'packages' => array(), '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 | Application Key
......
<?php namespace System; <?php namespace Laravel;
class Arr { class Arr {
...@@ -9,6 +9,11 @@ class Arr { ...@@ -9,6 +9,11 @@ class Arr {
* also be accessed using JavaScript "dot" style notation. Retrieving items nested * also be accessed using JavaScript "dot" style notation. Retrieving items nested
* in multiple arrays is also supported. * in multiple arrays is also supported.
* *
* <code>
* // Returns "taylor"
* Arr::get(array('name' => array('is' => 'Taylor')), 'name.is');
* </code>
*
* @param array $array * @param array $array
* @param string $key * @param string $key
* @param mixed $default * @param mixed $default
...@@ -37,8 +42,16 @@ class Arr { ...@@ -37,8 +42,16 @@ class Arr {
* This method is primarly helpful for setting the value in an array with * This method is primarly helpful for setting the value in an array with
* a variable depth, such as configuration arrays. * 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. * Like the Arr::get method, JavaScript "dot" syntax is supported.
* *
* <code>
* // Set "name.is" to "taylor"
* Arr::set(array('name' => array('is' => 'something')), 'name.is', 'taylor');
* </code>
*
* @param array $array * @param array $array
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
......
<?php namespace System; <?php namespace Laravel;
use System\File; use Laravel\File;
use System\HTML; use Laravel\HTML;
class Asset { class Asset {
...@@ -21,6 +21,14 @@ class Asset { ...@@ -21,6 +21,14 @@ class Asset {
* Containers provide a convenient method of grouping assets while maintaining * Containers provide a convenient method of grouping assets while maintaining
* expressive code and a clean API. * expressive code and a clean API.
* *
* <code>
* // Get the default asset container
* $container = Asset::container();
*
* // Get the "footer" asset container
* $container = Asset::container('footer');
* </code>
*
* @param string $container * @param string $container
* @return Asset_Container * @return Asset_Container
*/ */
...@@ -36,6 +44,17 @@ class Asset { ...@@ -36,6 +44,17 @@ class Asset {
/** /**
* Magic Method for calling methods on the default Asset container. * 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.
*
* <code>
* // Add an asset to the default container
* Asset::add('jquery', 'js/jquery.js');
*
* // Equivalent statement using the container method
* Asset::container()->add('jquery', 'js/jquery.js');
* </code>
*/ */
public static function __callStatic($method, $parameters) public static function __callStatic($method, $parameters)
{ {
...@@ -49,6 +68,8 @@ class Asset_Container { ...@@ -49,6 +68,8 @@ class Asset_Container {
/** /**
* The asset container name. * The asset container name.
* *
* This name may be used to access the container instance via the Asset::container method.
*
* @var string * @var string
*/ */
public $name; public $name;
...@@ -82,6 +103,14 @@ class Asset_Container { ...@@ -82,6 +103,14 @@ class Asset_Container {
* only link to the registered asset after its dependencies have been linked. * only link to the registered asset after its dependencies have been linked.
* For example, you may wish to make jQuery UI dependent on jQuery. * For example, you may wish to make jQuery UI dependent on jQuery.
* *
* <code>
* // Add an asset to the container
* Asset::container()->add('jquery', 'js/jquery.js');
*
* // Add an asset that is dependent on another asset
* Asset::container()->add('jquery-ui', 'js/jquery-ui.js', array('jquery'));
* </code>
*
* @param string $name * @param string $name
* @param string $source * @param string $source
* @param array $dependencies * @param array $dependencies
...@@ -103,7 +132,6 @@ class Asset_Container { ...@@ -103,7 +132,6 @@ class Asset_Container {
* @param array $dependencies * @param array $dependencies
* @param array $attributes * @param array $attributes
* @return void * @return void
* @see add
*/ */
public function style($name, $source, $dependencies = array(), $attributes = array()) public function style($name, $source, $dependencies = array(), $attributes = array())
{ {
...@@ -123,7 +151,6 @@ class Asset_Container { ...@@ -123,7 +151,6 @@ class Asset_Container {
* @param array $dependencies * @param array $dependencies
* @param array $attributes * @param array $attributes
* @return void * @return void
* @see add
*/ */
public function script($name, $source, $dependencies = array(), $attributes = array()) public function script($name, $source, $dependencies = array(), $attributes = array())
{ {
...@@ -131,7 +158,9 @@ class Asset_Container { ...@@ -131,7 +158,9 @@ class Asset_Container {
} }
/** /**
* 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 $type
* @param string $name * @param string $name
...@@ -150,6 +179,10 @@ class Asset_Container { ...@@ -150,6 +179,10 @@ class Asset_Container {
/** /**
* Get the links to all of the registered CSS assets. * Get the links to all of the registered CSS assets.
* *
* <code>
* echo Asset::container()->styles();
* </code>
*
* @return string * @return string
*/ */
public function styles() public function styles()
...@@ -160,6 +193,10 @@ class Asset_Container { ...@@ -160,6 +193,10 @@ class Asset_Container {
/** /**
* Get the links to all of the registered JavaScript assets. * Get the links to all of the registered JavaScript assets.
* *
* <code>
* echo Asset::container()->scripts();
* </code>
*
* @return string * @return string
*/ */
public function scripts() public function scripts()
...@@ -168,7 +205,7 @@ class Asset_Container { ...@@ -168,7 +205,7 @@ class Asset_Container {
} }
/** /**
* Get all of the registered assets for a given group. * Get all of the registered assets for a given type / group.
* *
* @param string $group * @param string $group
* @return string * @return string
...@@ -190,6 +227,10 @@ class Asset_Container { ...@@ -190,6 +227,10 @@ class Asset_Container {
/** /**
* Get the link to a single registered CSS asset. * Get the link to a single registered CSS asset.
* *
* <code>
* echo Asset::container()->get_style('common');
* </code>
*
* @param string $name * @param string $name
* @return string * @return string
*/ */
...@@ -201,6 +242,10 @@ class Asset_Container { ...@@ -201,6 +242,10 @@ class Asset_Container {
/** /**
* Get the link to a single registered JavaScript asset. * Get the link to a single registered JavaScript asset.
* *
* <code>
* echo Asset::container()->get_script('jquery');
* </code>
*
* @param string $name * @param string $name
* @return string * @return string
*/ */
...@@ -210,7 +255,7 @@ class Asset_Container { ...@@ -210,7 +255,7 @@ class Asset_Container {
} }
/** /**
* Get a registered asset. * Get the HTML link to a registered asset.
* *
* @param string $group * @param string $group
* @param string $name * @param string $name
...@@ -287,7 +332,10 @@ class Asset_Container { ...@@ -287,7 +332,10 @@ class Asset_Container {
} }
/** /**
* 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 $asset
* @param string $dependency * @param string $dependency
...@@ -297,11 +345,9 @@ class Asset_Container { ...@@ -297,11 +345,9 @@ class Asset_Container {
*/ */
private function dependency_is_valid($asset, $dependency, $original, $assets) private function dependency_is_valid($asset, $dependency, $original, $assets)
{ {
if ( ! isset($original[$dependency])) if ( ! isset($original[$dependency])) return false;
{
return false; if ($dependency === $asset)
}
elseif ($dependency === $asset)
{ {
throw new \Exception("Asset [$asset] is dependent on itself."); throw new \Exception("Asset [$asset] is dependent on itself.");
} }
......
<?php namespace System; <?php namespace Laravel;
if (Config::get('session.driver') == '') if (Config::get('session.driver') == '')
{ {
...@@ -29,6 +29,7 @@ class Auth { ...@@ -29,6 +29,7 @@ class Auth {
/** /**
* Determine if the current user of the application is authenticated. * Determine if the current user of the application is authenticated.
* *
* @see login()
* @return bool * @return bool
*/ */
public static function check() public static function check()
...@@ -43,8 +44,11 @@ class Auth { ...@@ -43,8 +44,11 @@ class Auth {
* the "by_id" closure in the authentication configuration file. The result * the "by_id" closure in the authentication configuration file. The result
* of the closure will be cached and returned. * of the closure will be cached and returned.
* *
* <code>
* $email = Auth::user()->email;
* </code>
*
* @return object * @return object
* @see $user
*/ */
public static function user() public static function user()
{ {
...@@ -65,6 +69,13 @@ class Auth { ...@@ -65,6 +69,13 @@ class Auth {
* The password passed to the method should be plain text, as it will be hashed * The password passed to the method should be plain text, as it will be hashed
* by the Hash class when authenticating. * by the Hash class when authenticating.
* *
* <code>
* if (Auth::login('email@example.com', 'password'))
* {
* // The credentials are valid and the user is now logged in.
* }
* </code>
*
* @param string $username * @param string $username
* @param string $password * @param string $password
* @return bool * @return bool
...@@ -88,7 +99,8 @@ class Auth { ...@@ -88,7 +99,8 @@ class Auth {
* Log a user into your application. * Log a user into your application.
* *
* The user's ID will be stored in the session and the user will be considered * 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. * Note: The user given to this method should be an object having an "id" property.
* *
...@@ -106,7 +118,7 @@ class Auth { ...@@ -106,7 +118,7 @@ class Auth {
* Log the user out of your application. * Log the user out of your application.
* *
* The user ID will be removed from the session and the user will no longer * 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 * @return void
*/ */
......
<?php namespace System; <?php namespace Laravel;
class Benchmark { class Benchmark {
...@@ -17,7 +17,6 @@ class Benchmark { ...@@ -17,7 +17,6 @@ class Benchmark {
* *
* @param string $name * @param string $name
* @return void * @return void
* @see check
*/ */
public static function start($name) public static function start($name)
{ {
...@@ -29,7 +28,6 @@ class Benchmark { ...@@ -29,7 +28,6 @@ class Benchmark {
* *
* @param string $name * @param string $name
* @return float * @return float
* @see start
*/ */
public static function check($name) public static function check($name)
{ {
......
<?php namespace System; <?php namespace Laravel;
class Cache { class Cache {
...@@ -15,7 +15,15 @@ class Cache { ...@@ -15,7 +15,15 @@ class Cache {
* If no driver name is specified, the default cache driver will be returned * If no driver name is specified, the default cache driver will be returned
* as defined in the cache configuration file. * as defined in the cache configuration file.
* *
* @param string $driver * <code>
* // Get the default cache driver
* $driver = Cache::driver();
*
* // Get the APC cache driver
* $apc = Cache::driver('apc');
* </code>
*
* @param string $driver
* @return Cache\Driver * @return Cache\Driver
*/ */
public static function driver($driver = null) public static function driver($driver = null)
...@@ -43,50 +51,16 @@ class Cache { ...@@ -43,50 +51,16 @@ class Cache {
return static::$drivers[$driver]; return static::$drivers[$driver];
} }
/**
* Get an item from the cache.
*
* @param string $key
* @param mixed $default
* @param string $driver
* @return mixed
*/
public static function get($key, $default = null, $driver = null)
{
if (is_null($item = static::driver($driver)->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. * Pass all other methods to the default driver.
* *
* Passing method calls to the driver instance provides a better API for you. * Passing method calls to the driver instance provides a convenient API for the developer
* For instance, instead of saying Cache::driver()->foo(), you can just say Cache::foo(). * when always using the default cache driver.
*
* <code>
* // Get an item from the default cache driver
* $name = Cache::get('name');
* </code>
*/ */
public static function __callStatic($method, $parameters) public static function __callStatic($method, $parameters)
{ {
......
<?php namespace System\Cache; <?php namespace Laravel\Cache;
use System\Config; use Laravel\Config;
class APC implements Driver { class APC extends Driver {
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key) public function has($key)
{ {
return ( ! is_null($this->get($key))); return ( ! is_null($this->get($key)));
} }
/** public function get($key, $default = null)
* 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; $item = ( ! is_null($cache = apc_fetch(Config::get('cache.key').$key))) ? $cache : null;
return $this->prepare($item, $default);
} }
/**
* Write an item to the cache.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes) public function put($key, $value, $minutes)
{ {
apc_store(Config::get('cache.key').$key, $value, $minutes * 60); 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) public function forget($key)
{ {
apc_delete(Config::get('cache.key').$key); apc_delete(Config::get('cache.key').$key);
......
<?php namespace Laravel\Cache;
abstract class Driver {
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
abstract public function has($key);
/**
* Get an item from the cache.
*
* A default value may also be specified, and will be returned in the requested
* item does not exist in the cache.
*
* <code>
* // 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');
* </code>
*
* @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.
*
* <code>
* // Get the "name" item from the cache or store "Fred" for 30 minutes
* $name = Cache::driver()->remember('name', 'Fred', 30);
* </code>
*
* @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
<?php namespace System\Cache; <?php namespace Laravel\Cache;
class File implements Driver { class File extends Driver {
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key) public function has($key)
{ {
return ( ! is_null($this->get($key))); return ( ! is_null($this->get($key)));
} }
/** public function get($key, $default = null)
* Get an item from the cache.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key)
{ {
if ( ! file_exists(CACHE_PATH.$key)) if ( ! file_exists(CACHE_PATH.$key))
{ {
return null; return $this->prepare(null, $default);
} }
$cache = file_get_contents(CACHE_PATH.$key); $cache = file_get_contents(CACHE_PATH.$key);
// The cache expiration date is stored as a UNIX timestamp at the beginning // 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. // of the cache file. We'll extract it out and check it here.
if (time() >= substr($cache, 0, 10)) return $this->forget($key); if (time() >= substr($cache, 0, 10))
{
$this->forget($key);
return $this->prepare(null, $default);
}
return unserialize(substr($cache, 10)); return $this->prepare(unserialize(substr($cache, 10)), $default);
} }
/**
* Write an item to the cache.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes) public function put($key, $value, $minutes)
{ {
file_put_contents(CACHE_PATH.$key, (time() + ($minutes * 60)).serialize($value), LOCK_EX); 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) public function forget($key)
{ {
@unlink(CACHE_PATH.$key); @unlink(CACHE_PATH.$key);
......
<?php namespace Laravel\Cache;
use Laravel\Config;
use Laravel\Memcached as Mem;
class Memcached extends Driver {
public function has($key)
{
return ( ! is_null($this->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
<?php namespace System; <?php namespace Laravel;
class Config { class Config {
/** /**
* All of the loaded configuration items. * All of the loaded configuration items.
* *
* The configuration arrays are keyed by module and file names.
*
* @var array * @var array
*/ */
public static $items = array(); public static $items = array();
...@@ -12,6 +14,14 @@ class Config { ...@@ -12,6 +14,14 @@ class Config {
/** /**
* Determine if a configuration item or file exists. * Determine if a configuration item or file exists.
* *
* <code>
* // Determine if the "session" configuration file exists
* Config::has('session');
*
* // Determine if the application timezone option exists
* Config::has('application.timezone');
* </code>
*
* @param string $key * @param string $key
* @return bool * @return bool
*/ */
...@@ -30,6 +40,14 @@ class Config { ...@@ -30,6 +40,14 @@ class Config {
* If the name of a configuration file is passed without specifying an item, the * If the name of a configuration file is passed without specifying an item, the
* entire configuration array will be returned. * entire configuration array will be returned.
* *
* <code>
* // 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');
* </code>
*
* @param string $key * @param string $key
* @param string $default * @param string $default
* @return array * @return array
...@@ -51,6 +69,20 @@ class Config { ...@@ -51,6 +69,20 @@ class Config {
/** /**
* Set a configuration item. * 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.
*
* <code>
* // Set the timezone option in the application configuration file
* Config::set('application.timezone', 'America/Chicago');
*
* // Set the session configuration array
* Config::set('session', array());
* </code>
*
* @param string $key * @param string $key
* @param mixed $value * @param mixed $value
* @return void * @return void
...@@ -68,33 +100,26 @@ class Config { ...@@ -68,33 +100,26 @@ class Config {
} }
/** /**
* Parse a configuration key. * Parse a configuration key and return its module, file, and key segments.
* *
* The value on the left side of the dot is the configuration file * Modular configuration keys follow a {module}::{file}.{key} convention.
* name, while the right side of the dot is the item within that file.
* *
* @param string $key * @param string $key
* @return array * @return array
*/ */
private static function parse($key) private static function parse($key)
{ {
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; list($module, $key) = Module::parse($key);
if ($module !== 'application') $segments = explode('.', $key);
{
$key = substr($key, strpos($key, ':') + 2);
}
$key = (count($segments = explode('.', $key)) > 1) ? implode('.', array_slice($segments, 1)) : null; return array($module, $segments[0], (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null);
return array($module, $segments[0], $key);
} }
/** /**
* Load all of the configuration items from a file. * Load all of the configuration items from a module configuration file.
* *
* Laravel supports environment specific configuration files. So, the base configuration * If the configuration file has already been loaded, it will not be loaded again.
* array will be loaded first, then any environment specific options will be merged in.
* *
* @param string $file * @param string $file
* @param string $module * @param string $module
...@@ -104,16 +129,11 @@ class Config { ...@@ -104,16 +129,11 @@ class Config {
{ {
if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true; if (isset(static::$items[$module]) and array_key_exists($file, static::$items[$module])) return true;
$path = ($module === 'application') ? CONFIG_PATH : MODULE_PATH.$module.'/config/'; $config = array();
// 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)) foreach (static::paths($module, $file) as $directory)
{ {
$config = array_merge($config, require $path); $config = (file_exists($path = $directory.$file.EXT)) ? array_merge($config, require $path) : $config;
} }
if (count($config) > 0) static::$items[$module][$file] = $config; if (count($config) > 0) static::$items[$module][$file] = $config;
...@@ -121,4 +141,30 @@ class Config { ...@@ -121,4 +141,30 @@ class Config {
return isset(static::$items[$module][$file]); 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
<?php namespace System; <?php namespace Laravel;
class Cookie { class Cookie {
......
<?php namespace System; <?php namespace Laravel;
class Crypter { class Crypter {
......
<?php namespace System; <?php namespace Laravel;
class DB { class DB {
......
<?php namespace System\DB; <?php namespace Laravel\DB;
class Connection { class Connection {
......
<?php namespace System\DB; <?php namespace Laravel\DB;
use System\Config; use Laravel\Config;
class Connector { class Connector {
......
<?php namespace System\DB; <?php namespace Laravel\DB;
use System\Str; use Laravel\Str;
use System\Config; use Laravel\Config;
use System\Paginator; use Laravel\Paginator;
class Query { class Query {
......
<?php namespace System\Exception; <?php namespace Laravel\Exception;
use System\File; use Laravel\File;
class Examiner { class Examiner {
...@@ -68,7 +68,7 @@ class Examiner { ...@@ -68,7 +68,7 @@ class Examiner {
*/ */
public function message() public function message()
{ {
$file = str_replace(array(APP_PATH, SYS_PATH), array('APP_PATH/', 'SYS_PATH/'), $this->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().'.'; return rtrim($this->exception->getMessage(), '.').' in '.$file.' on line '.$this->exception->getLine().'.';
} }
......
<?php namespace System\Exception; <?php namespace Laravel\Exception;
use System\View; use Laravel\View;
use System\Config; use Laravel\Config;
use System\Response; use Laravel\Response;
class Handler { class Handler {
......
<?php namespace System; <?php namespace Laravel;
class File { class File {
......
<?php namespace System; <?php namespace Laravel;
class Form { class Form {
......
<?php namespace System; <?php namespace Laravel;
class Hash { class Hash {
......
<?php namespace System; <?php namespace Laravel;
class HTML { class HTML {
......
<?php namespace System; <?php namespace Laravel;
class Inflector { class Inflector {
......
<?php namespace System; <?php namespace Laravel;
class Input { class Input {
......
<?php namespace System; <?php namespace Laravel;
class Lang { class Lang {
...@@ -93,16 +93,11 @@ class Lang { ...@@ -93,16 +93,11 @@ class Lang {
*/ */
private function parse($key, $language) private function parse($key, $language)
{ {
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application'; list($module, $key) = Module::parse($key);
if ($module != 'application')
{
$key = substr($key, strpos($key, ':') + 2);
}
if (count($segments = explode('.', $key)) > 1) if (count($segments = explode('.', $key)) > 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."); throw new \Exception("Invalid language line [$key]. A specific line must be specified.");
...@@ -120,9 +115,7 @@ class Lang { ...@@ -120,9 +115,7 @@ class Lang {
{ {
if (isset(static::$lines[$module][$language.$file])) return; if (isset(static::$lines[$module][$language.$file])) return;
$path = ($module === 'application') ? LANG_PATH : MODULE_PATH.$module.'/lang/'; if (file_exists($path = Module::path($module).'lang/'.$language.'/'.$file.EXT))
if (file_exists($path = $path.$language.'/'.$file.EXT))
{ {
static::$lines[$module][$language.$file] = require $path; static::$lines[$module][$language.$file] = require $path;
} }
......
<?php namespace System; <?php namespace Laravel;
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.php');
// -------------------------------------------------------------- // --------------------------------------------------------------
// Define the core framework paths. // Define the core framework paths.
// -------------------------------------------------------------- // --------------------------------------------------------------
define('APP_PATH', realpath($application).'/'); define('BASE_PATH', realpath(str_replace('laravel', '', $system)).'/');
define('SYS_PATH', realpath($system).'/'); define('CONFIG_PATH', realpath($config).'/');
define('PUBLIC_PATH', realpath($public).'/');
define('PACKAGE_PATH', realpath($packages).'/');
define('MODULE_PATH', realpath($modules).'/'); define('MODULE_PATH', realpath($modules).'/');
define('PACKAGE_PATH', realpath($packages).'/');
define('PUBLIC_PATH', realpath($public).'/');
define('STORAGE_PATH', realpath($storage).'/'); define('STORAGE_PATH', realpath($storage).'/');
define('BASE_PATH', realpath(str_replace('system', '', $system)).'/'); define('SYS_PATH', realpath($system).'/');
unset($application, $system, $public, $packages, $modules, $storage); unset($system, $config, $modules, $packages, $public, $storage);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Define various other framework paths. // Define various other framework paths.
// -------------------------------------------------------------- // --------------------------------------------------------------
define('CACHE_PATH', STORAGE_PATH.'cache/'); define('CACHE_PATH', STORAGE_PATH.'cache/');
define('CONFIG_PATH', APP_PATH.'config/');
define('DATABASE_PATH', STORAGE_PATH.'db/'); define('DATABASE_PATH', STORAGE_PATH.'db/');
define('LANG_PATH', APP_PATH.'lang/');
define('LIBRARY_PATH', APP_PATH.'libraries/');
define('MODEL_PATH', APP_PATH.'models/');
define('ROUTE_PATH', APP_PATH.'routes/');
define('SCRIPT_PATH', PUBLIC_PATH.'js/'); define('SCRIPT_PATH', PUBLIC_PATH.'js/');
define('SESSION_PATH', STORAGE_PATH.'sessions/'); define('SESSION_PATH', STORAGE_PATH.'sessions/');
define('STYLE_PATH', PUBLIC_PATH.'css/'); define('STYLE_PATH', PUBLIC_PATH.'css/');
define('VIEW_PATH', APP_PATH.'views/');
// -------------------------------------------------------------- // --------------------------------------------------------------
// Define the PHP file extension. // Define the default module.
// -------------------------------------------------------------- // --------------------------------------------------------------
define('EXT', '.php'); define('DEFAULT_MODULE', 'application');
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the classes used by the auto-loader. // Load the classes used by the auto-loader.
// -------------------------------------------------------------- // --------------------------------------------------------------
require SYS_PATH.'loader'.EXT; require SYS_PATH.'loader'.EXT;
require SYS_PATH.'config'.EXT; require SYS_PATH.'config'.EXT;
require SYS_PATH.'module'.EXT;
require SYS_PATH.'arr'.EXT; require SYS_PATH.'arr'.EXT;
// --------------------------------------------------------------
// Register the active modules.
// --------------------------------------------------------------
Module::$modules = $active;
unset($active);
// -------------------------------------------------------------- // --------------------------------------------------------------
// Register the auto-loader. // Register the auto-loader.
// -------------------------------------------------------------- // --------------------------------------------------------------
Loader::bootstrap(); Loader::bootstrap(array(
Module::path(DEFAULT_MODULE).'libraries/',
Module::path(DEFAULT_MODULE).'models/',
));
spl_autoload_register(array('System\\Loader', 'load')); spl_autoload_register(array('Laravel\\Loader', 'load'));
// -------------------------------------------------------------- // --------------------------------------------------------------
// Set the error reporting and display levels. // Set the error reporting and display levels.
...@@ -55,33 +65,34 @@ error_reporting(E_ALL | E_STRICT); ...@@ -55,33 +65,34 @@ error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 'Off'); ini_set('display_errors', 'Off');
// -------------------------------------------------------------- // --------------------------------------------------------------
// Register the error handlers. // Register the error / exception handlers.
// -------------------------------------------------------------- // --------------------------------------------------------------
set_exception_handler(function($e) $error_dependencies = function()
{ {
require_once SYS_PATH.'exception/handler'.EXT; require_once SYS_PATH.'exception/handler'.EXT;
require_once SYS_PATH.'exception/examiner'.EXT; require_once SYS_PATH.'exception/examiner'.EXT;
require_once SYS_PATH.'file'.EXT; require_once SYS_PATH.'file'.EXT;
};
set_exception_handler(function($e) use ($error_dependencies)
{
call_user_func($error_dependencies);
Exception\Handler::make($e)->handle(); Exception\Handler::make($e)->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; call_user_func($error_dependencies);
require_once SYS_PATH.'exception/examiner'.EXT;
require_once SYS_PATH.'file'.EXT;
Exception\Handler::make(new \ErrorException($error, $number, 0, $file, $line))->handle(); 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())) if ( ! is_null($error = error_get_last()))
{ {
require_once SYS_PATH.'exception/handler'.EXT; call_user_func($error_dependencies);
require_once SYS_PATH.'exception/examiner'.EXT;
require_once SYS_PATH.'file'.EXT;
extract($error); extract($error);
...@@ -97,10 +108,7 @@ date_default_timezone_set(Config::get('application.timezone')); ...@@ -97,10 +108,7 @@ date_default_timezone_set(Config::get('application.timezone'));
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load the session. // Load the session.
// -------------------------------------------------------------- // --------------------------------------------------------------
if (Config::get('session.driver') != '') if (Config::get('session.driver') != '') Session::load(Cookie::get('laravel_session'));
{
Session::load(Cookie::get('laravel_session'));
}
// -------------------------------------------------------------- // --------------------------------------------------------------
// Load all of the core routing classes. // Load all of the core routing classes.
...@@ -127,21 +135,19 @@ if (count(Config::get('application.packages')) > 0) ...@@ -127,21 +135,19 @@ if (count(Config::get('application.packages')) > 0)
// -------------------------------------------------------------- // --------------------------------------------------------------
$segments = explode('/', Request::uri()); $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. // 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. // Register the filters for the active module.
// -------------------------------------------------------------- // --------------------------------------------------------------
Routing\Filter::register(require APP_PATH.'filters'.EXT); if (file_exists(ACTIVE_MODULE_PATH.'filters'.EXT))
if (ACTIVE_MODULE !== 'application' and file_exists($filters = ACTIVE_MODULE_PATH.'filters'.EXT))
{ {
Routing\Filter::register(require $filters); Routing\Filter::register(require ACTIVE_MODULE_PATH.'filters'.EXT);
} }
// -------------------------------------------------------------- // --------------------------------------------------------------
...@@ -159,7 +165,9 @@ foreach (array('before', ACTIVE_MODULE.'::before') as $filter) ...@@ -159,7 +165,9 @@ foreach (array('before', ACTIVE_MODULE.'::before') as $filter)
// -------------------------------------------------------------- // --------------------------------------------------------------
if (is_null($response)) 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(); $response = (is_null($route)) ? Response::error('404') : $route->call();
} }
...@@ -182,10 +190,7 @@ $response->content = (string) $response->content; ...@@ -182,10 +190,7 @@ $response->content = (string) $response->content;
// -------------------------------------------------------------- // --------------------------------------------------------------
// Close the session. // Close the session.
// -------------------------------------------------------------- // --------------------------------------------------------------
if (Config::get('session.driver') != '') if (Config::get('session.driver') != '') Session::close();
{
Session::close();
}
// -------------------------------------------------------------- // --------------------------------------------------------------
// Send the response to the browser. // Send the response to the browser.
......
<?php namespace System; <?php namespace Laravel;
class Loader { class Loader {
...@@ -7,7 +7,7 @@ class Loader { ...@@ -7,7 +7,7 @@ class Loader {
* *
* @var array * @var array
*/ */
public static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH); public static $paths = array(BASE_PATH);
/** /**
* All of the class aliases. * All of the class aliases.
...@@ -26,12 +26,14 @@ class Loader { ...@@ -26,12 +26,14 @@ class Loader {
/** /**
* Bootstrap the auto-loader. * Bootstrap the auto-loader.
* *
* @param array $paths
* @return void * @return void
*/ */
public static function bootstrap() public static function bootstrap($paths = array())
{ {
static::$aliases = Config::get('aliases'); static::$aliases = Config::get('aliases');
static::$modules = Config::get('application.modules');
foreach ($paths as $path) { static::register($path); }
} }
/** /**
...@@ -85,7 +87,7 @@ class Loader { ...@@ -85,7 +87,7 @@ class Loader {
// module name, we'll extract the module name from the file. // module name, we'll extract the module name from the file.
$module = substr($file, 0, strpos($file, '/')); $module = substr($file, 0, strpos($file, '/'));
if (in_array($module, static::$modules)) if (in_array($module, Module::$modules))
{ {
$module = MODULE_PATH.$module.'/'; $module = MODULE_PATH.$module.'/';
......
<?php namespace System; <?php namespace Laravel;
class Memcached { class Memcached {
......
<?php namespace System; <?php namespace Laravel;
class Messages { class Messages {
......
<?php namespace Laravel;
class Module {
/**
* The active modules for the installation.
*
* @var array
*/
public static $modules = array();
/**
* All of the loaded module paths.
*
* @var array
*/
private static $paths = array();
/**
* Parse a modularized identifier and get the module and key.
*
* Modular identifiers follow a {module}::{key} convention.
*
* @param string $key
* @return array
*/
public static function parse($key)
{
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : DEFAULT_MODULE;
if ($module !== DEFAULT_MODULE) $key = substr($key, strpos($key, ':') + 2);
return array($module, $key);
}
/**
* Get the path for a given module.
*
* @param string $module
* @return string
*/
public static function path($module)
{
if (array_key_exists($module, static::$paths)) return static::$paths[$module];
if (array_key_exists($module, static::$modules))
{
$path = (strpos(static::$modules[$module], BASE_PATH) === 0) ? static::$modules[$module].'/' : MODULE_PATH.static::$modules[$module].'/';
}
return static::$paths[$module] = $path;
}
/**
* Get the an array of paths to all of the modules.
*
* The module paths will be determined by the modules that are specified in the application
* modules configuration item. A trailing slash will be added to the paths.
*
* @return array
*/
public static function paths()
{
return array_map(function($module) { return Laravel\Module::path($module); }, static::$modules);
}
}
\ No newline at end of file
<?php namespace System; <?php namespace Laravel;
class Package { class Package {
......
<?php namespace System; <?php namespace Laravel;
class Paginator { class Paginator {
......
<?php namespace System; <?php namespace Laravel;
class Redirect { class Redirect {
......
<?php namespace System; <?php namespace Laravel;
class Request { class Request {
......
<?php namespace System; <?php namespace Laravel;
class Response { class Response {
......
<?php namespace System\Routing; <?php namespace Laravel\Routing;
class Filter { class Filter {
......
<?php namespace System\Routing; <?php namespace Laravel\Routing;
class Finder { class Finder {
......
<?php namespace System\Routing; <?php namespace Laravel\Routing;
use System\Config; use Laravel\Config;
class Loader { class Loader {
...@@ -62,7 +62,7 @@ class Loader { ...@@ -62,7 +62,7 @@ class Loader {
// Since it is no part of the route directory structure, shift the module name off of the // Since it is no part of the route directory structure, shift the module name off of the
// beginning of the array so we can locate the appropriate route file. // beginning of the array so we can locate the appropriate route file.
if (count($segments) > 0 and ACTIVE_MODULE !== 'application') if (count($segments) > 0 and ACTIVE_MODULE !== DEFAULT_MODULE)
{ {
array_shift($segments); array_shift($segments);
} }
...@@ -87,21 +87,15 @@ class Loader { ...@@ -87,21 +87,15 @@ class Loader {
* will be cached and returned on every subsequent call. * will be cached and returned on every subsequent call.
* *
* @param bool $reload * @param bool $reload
* @param string $path
* @return array * @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; 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(); $routes = array();
foreach ($paths as $path) foreach (Module::paths() as $path)
{ {
if (file_exists($path.'routes'.EXT)) if (file_exists($path.'routes'.EXT))
{ {
......
<?php namespace System\Routing; <?php namespace Laravel\Routing;
use System\Package; use Laravel\Package;
use System\Response; use Laravel\Response;
class Route { class Route {
......
<?php namespace System\Routing; <?php namespace Laravel\Routing;
use System\Request; use Laravel\Request;
class Router { class Router {
......
<?php namespace System; <?php namespace Laravel;
class Session { class Session {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
use System\Cache; use Laravel\Cache;
use System\Config; use Laravel\Config;
class APC implements Driver { class APC implements Driver {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
use System\Config; use Laravel\Config;
use System\Crypter; use Laravel\Crypter;
class Cookie implements Driver { class Cookie implements Driver {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
use System\Config; use Laravel\Config;
class DB implements Driver, Sweeper { class DB implements Driver, Sweeper {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
interface Driver { interface Driver {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
class File implements Driver, Sweeper { class File implements Driver, Sweeper {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
use System\Cache; use Laravel\Cache;
use System\Config; use Laravel\Config;
class Memcached implements Driver { class Memcached implements Driver {
......
<?php namespace System\Session; <?php namespace Laravel\Session;
interface Sweeper { interface Sweeper {
......
<?php namespace System; <?php namespace Laravel;
class Str { class Str {
......
<?php namespace System; <?php namespace Laravel;
class URL { class URL {
......
<?php namespace System; <?php namespace Laravel;
class Validator { class Validator {
......
...@@ -68,9 +68,8 @@ class View { ...@@ -68,9 +68,8 @@ class View {
/** /**
* Create a new view instance from a view name. * Create a new view instance from a view name.
* *
* The view names for the active module will be searched first, followed by * The view names for the active module will be searched first, followed by the view names
* the view names for the application directory, followed by the view names * for the default module. Finally, the names for all modules will be searched.
* for all other modules.
* *
* @param string $name * @param string $name
* @param array $data * @param array $data
...@@ -78,7 +77,7 @@ class View { ...@@ -78,7 +77,7 @@ class View {
*/ */
protected static function of($name, $data = array()) protected static function of($name, $data = array())
{ {
foreach (array_unique(array_merge(array(ACTIVE_MODULE, 'application'), Config::get('application.modules'))) as $module) foreach (array_unique(array_merge(array(ACTIVE_MODULE, DEFAULT_MODULE), Module::$modules)) as $module)
{ {
static::load_composers($module); static::load_composers($module);
...@@ -102,16 +101,9 @@ class View { ...@@ -102,16 +101,9 @@ class View {
*/ */
protected static function parse($view) protected static function parse($view)
{ {
$module = (strpos($view, '::') !== false) ? substr($view, 0, strpos($view, ':')) : 'application'; list($module, $view) = Module::parse($view);
$path = ($module == 'application') ? VIEW_PATH : MODULE_PATH.$module.'/views/'; return array($module, Module::path($module).'views/', $view);
if ($module != 'application')
{
$view = substr($view, strpos($view, ':') + 2);
}
return array($module, $path, $view);
} }
/** /**
...@@ -142,7 +134,7 @@ class View { ...@@ -142,7 +134,7 @@ class View {
{ {
if (isset(static::$composers[$module])) return; if (isset(static::$composers[$module])) return;
$composers = ($module == 'application') ? APP_PATH.'composers'.EXT : MODULE_PATH.$module.'/composers'.EXT; $composers = Module::path($module).'composers'.EXT;
static::$composers[$module] = (file_exists($composers)) ? require $composers : array(); static::$composers[$module] = (file_exists($composers)) ? require $composers : array();
} }
......
File added
...@@ -3,40 +3,47 @@ ...@@ -3,40 +3,47 @@
* Laravel - A clean and classy framework for PHP web development. * Laravel - A clean and classy framework for PHP web development.
* *
* @package Laravel * @package Laravel
* @version 1.5.3 * @version 2.0.0
* @author Taylor Otwell * @author Taylor Otwell
* @link http://laravel.com * @link http://laravel.com
*/ */
// -------------------------------------------------------------- // --------------------------------------------------------------
// The path to the application directory. // The active modules for this Laravel installation.
// -------------------------------------------------------------- // --------------------------------------------------------------
$application = '../application'; $active = array(
'application' => 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. // The path to the packages directory.
// -------------------------------------------------------------- // --------------------------------------------------------------
$packages = '../packages'; $packages = '../packages';
// -------------------------------------------------------------- // --------------------------------------------------------------
// The path to the modules directory. // The path to the modules directory.
// -------------------------------------------------------------- // --------------------------------------------------------------
$modules = '../modules'; $modules = '../modules';
// -------------------------------------------------------------- // --------------------------------------------------------------
// The path to the storage directory. // The path to the storage directory.
// -------------------------------------------------------------- // --------------------------------------------------------------
$storage = '../storage'; $storage = '../storage';
// -------------------------------------------------------------- // --------------------------------------------------------------
// The path to the public directory. // The path to the public directory.
// -------------------------------------------------------------- // --------------------------------------------------------------
$public = __DIR__; $public = __DIR__;
// -------------------------------------------------------------- // --------------------------------------------------------------
// Launch Laravel. // Launch Laravel.
......
<?php namespace System\Cache;
interface Driver {
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key);
/**
* Get an item from the cache.
*
* @param string $key
* @return mixed
*/
public function get($key);
/**
* Write an item to the cache.
*
* @param string $key
* @param mixed $value
* @param int $minutes
* @return void
*/
public function put($key, $value, $minutes);
/**
* Delete an item from the cache.
*
* @param string $key
* @return void
*/
public function forget($key);
}
\ No newline at end of file
<?php namespace System\Cache;
use System\Config;
class Memcached implements Driver {
/**
* Determine if an item exists in the cache.
*
* @param string $key
* @return bool
*/
public function has($key)
{
return ( ! is_null($this->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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment