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

first commit of 2.0

parent 119b356b
......@@ -81,7 +81,7 @@
<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>
</body>
</html>
\ No newline at end of file
......@@ -81,7 +81,7 @@
<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>
</body>
</html>
\ No newline at end of file
# 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.
......
......@@ -18,31 +18,31 @@ return array(
|
*/
'Asset' => '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',
'Asset' => '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
......@@ -11,7 +11,7 @@ return array(
|
*/
'url' => 'http://localhost',
'url' => 'http://beta.laravel.com',
/*
|--------------------------------------------------------------------------
......@@ -82,23 +82,6 @@ return 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
......
<?php namespace System;
<?php namespace Laravel;
class Arr {
......@@ -9,6 +9,11 @@ class Arr {
* also be accessed using JavaScript "dot" style notation. Retrieving items nested
* in multiple arrays is also supported.
*
* <code>
* // Returns "taylor"
* Arr::get(array('name' => array('is' => 'Taylor')), 'name.is');
* </code>
*
* @param array $array
* @param string $key
* @param mixed $default
......@@ -37,8 +42,16 @@ class Arr {
* 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.
*
* <code>
* // Set "name.is" to "taylor"
* Arr::set(array('name' => array('is' => 'something')), 'name.is', 'taylor');
* </code>
*
* @param array $array
* @param string $key
* @param mixed $value
......
<?php namespace System;
<?php namespace Laravel;
use System\File;
use System\HTML;
use Laravel\File;
use Laravel\HTML;
class Asset {
......@@ -21,6 +21,14 @@ class Asset {
* Containers provide a convenient method of grouping assets while maintaining
* 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
* @return Asset_Container
*/
......@@ -36,6 +44,17 @@ class Asset {
/**
* 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)
{
......@@ -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 @@ class Asset_Container {
* only link to the registered asset after its dependencies have been linked.
* 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 $source
* @param array $dependencies
......@@ -103,7 +132,6 @@ class Asset_Container {
* @param array $dependencies
* @param array $attributes
* @return void
* @see add
*/
public function style($name, $source, $dependencies = array(), $attributes = array())
{
......@@ -123,7 +151,6 @@ class Asset_Container {
* @param array $dependencies
* @param array $attributes
* @return void
* @see add
*/
public function script($name, $source, $dependencies = array(), $attributes = array())
{
......@@ -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 $name
......@@ -150,6 +179,10 @@ class Asset_Container {
/**
* Get the links to all of the registered CSS assets.
*
* <code>
* echo Asset::container()->styles();
* </code>
*
* @return string
*/
public function styles()
......@@ -160,6 +193,10 @@ class Asset_Container {
/**
* Get the links to all of the registered JavaScript assets.
*
* <code>
* echo Asset::container()->scripts();
* </code>
*
* @return string
*/
public function scripts()
......@@ -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
* @return string
......@@ -190,6 +227,10 @@ class Asset_Container {
/**
* Get the link to a single registered CSS asset.
*
* <code>
* echo Asset::container()->get_style('common');
* </code>
*
* @param string $name
* @return string
*/
......@@ -201,6 +242,10 @@ class Asset_Container {
/**
* Get the link to a single registered JavaScript asset.
*
* <code>
* echo Asset::container()->get_script('jquery');
* </code>
*
* @param string $name
* @return string
*/
......@@ -210,7 +255,7 @@ class Asset_Container {
}
/**
* Get a registered asset.
* Get the HTML link to a registered asset.
*
* @param string $group
* @param string $name
......@@ -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 $dependency
......@@ -297,11 +345,9 @@ class Asset_Container {
*/
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.");
}
......
<?php namespace System;
<?php namespace Laravel;
if (Config::get('session.driver') == '')
{
......@@ -29,6 +29,7 @@ class Auth {
/**
* Determine if the current user of the application is authenticated.
*
* @see login()
* @return bool
*/
public static function check()
......@@ -43,8 +44,11 @@ class Auth {
* the "by_id" closure in the authentication configuration file. The result
* of the closure will be cached and returned.
*
* <code>
* $email = Auth::user()->email;
* </code>
*
* @return object
* @see $user
*/
public static function user()
{
......@@ -65,6 +69,13 @@ class Auth {
* The password passed to the method should be plain text, as it will be hashed
* 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 $password
* @return bool
......@@ -88,7 +99,8 @@ class Auth {
* 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 @@ class Auth {
* 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
*/
......
<?php namespace System;
<?php namespace Laravel;
class Benchmark {
......@@ -17,7 +17,6 @@ class Benchmark {
*
* @param string $name
* @return void
* @see check
*/
public static function start($name)
{
......@@ -29,7 +28,6 @@ class Benchmark {
*
* @param string $name
* @return float
* @see start
*/
public static function check($name)
{
......
<?php namespace System;
<?php namespace Laravel;
class Cache {
......@@ -15,7 +15,15 @@ class Cache {
* If no driver name is specified, the default cache driver will be returned
* 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
*/
public static function driver($driver = null)
......@@ -43,50 +51,16 @@ class Cache {
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.
*
* 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().
* Passing method calls to the driver instance provides a convenient API for the developer
* 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)
{
......
<?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)
{
return ( ! is_null($this->get($key)));
}
/**
* Get an item from the cache.
*
* @param string $key
* @return mixed
*/
public function get($key)
public function get($key, $default = null)
{
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)
{
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);
......
<?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)
{
return ( ! is_null($this->get($key)));
}
/**
* Get an item from the cache.
*
* @param string $key
* @param mixed $default
* @return mixed
*/
public function get($key)
public function get($key, $default = null)
{
if ( ! file_exists(CACHE_PATH.$key))
{
return null;
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)) 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)
{
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);
......
<?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 {
/**
* All of the loaded configuration items.
*
* The configuration arrays are keyed by module and file names.
*
* @var array
*/
public static $items = array();
......@@ -12,6 +14,14 @@ class Config {
/**
* 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
* @return bool
*/
......@@ -30,6 +40,14 @@ class Config {
* If the name of a configuration file is passed without specifying an item, the
* 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 $default
* @return array
......@@ -51,6 +69,20 @@ class Config {
/**
* 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 mixed $value
* @return void
......@@ -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
* name, while the right side of the dot is the item within that file.
* Modular configuration keys follow a {module}::{file}.{key} convention.
*
* @param string $key
* @return array
*/
private static function parse($key)
{
$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);
}
$segments = explode('.', $key);
$key = (count($segments = explode('.', $key)) > 1) ? implode('.', array_slice($segments, 1)) : null;
return array($module, $segments[0], $key);
return array($module, $segments[0], (count($segments) > 1) ? implode('.', array_slice($segments, 1)) : null);
}
/**
* 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
* array will be loaded first, then any environment specific options will be merged in.
* If the configuration file has already been loaded, it will not be loaded again.
*
* @param string $file
* @param string $module
......@@ -104,16 +129,11 @@ class Config {
{
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();
$config = 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;
......@@ -121,4 +141,30 @@ class 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
<?php namespace System;
<?php namespace Laravel;
class Cookie {
......
<?php namespace System;
<?php namespace Laravel;
class Crypter {
......
<?php namespace System;
<?php namespace Laravel;
class DB {
......
<?php namespace System\DB;
<?php namespace Laravel\DB;
class Connection {
......
<?php namespace System\DB;
<?php namespace Laravel\DB;
use System\Config;
use Laravel\Config;
class Connector {
......
<?php namespace System\DB;
<?php namespace Laravel\DB;
use System\Str;
use System\Config;
use System\Paginator;
use Laravel\Str;
use Laravel\Config;
use Laravel\Paginator;
class Query {
......
<?php namespace System\Exception;
<?php namespace Laravel\Exception;
use System\File;
use Laravel\File;
class Examiner {
......@@ -68,7 +68,7 @@ class Examiner {
*/
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().'.';
}
......
<?php namespace System\Exception;
<?php namespace Laravel\Exception;
use System\View;
use System\Config;
use System\Response;
use Laravel\View;
use Laravel\Config;
use Laravel\Response;
class Handler {
......
<?php namespace System;
<?php namespace Laravel;
class File {
......
<?php namespace System;
<?php namespace Laravel;
class Form {
......
<?php namespace System;
<?php namespace Laravel;
class Hash {
......
<?php namespace System;
<?php namespace Laravel;
class HTML {
......
<?php namespace System;
<?php namespace Laravel;
class Inflector {
......
<?php namespace System;
<?php namespace Laravel;
class Input {
......
<?php namespace System;
<?php namespace Laravel;
class Lang {
......@@ -93,16 +93,11 @@ class Lang {
*/
private function parse($key, $language)
{
$module = (strpos($key, '::') !== false) ? substr($key, 0, strpos($key, ':')) : 'application';
if ($module != 'application')
{
$key = substr($key, strpos($key, ':') + 2);
}
list($module, $key) = Module::parse($key);
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.");
......@@ -120,9 +115,7 @@ class Lang {
{
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;
}
......
<?php namespace System;
<?php namespace Laravel;
// --------------------------------------------------------------
// Define the PHP file extension.
// --------------------------------------------------------------
define('EXT', '.php');
// --------------------------------------------------------------
// Define the core framework paths.
// --------------------------------------------------------------
define('APP_PATH', realpath($application).'/');
define('SYS_PATH', realpath($system).'/');
define('PUBLIC_PATH', realpath($public).'/');
define('PACKAGE_PATH', realpath($packages).'/');
define('BASE_PATH', realpath(str_replace('laravel', '', $system)).'/');
define('CONFIG_PATH', realpath($config).'/');
define('MODULE_PATH', realpath($modules).'/');
define('PACKAGE_PATH', realpath($packages).'/');
define('PUBLIC_PATH', realpath($public).'/');
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('CACHE_PATH', STORAGE_PATH.'cache/');
define('CONFIG_PATH', APP_PATH.'config/');
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('SESSION_PATH', STORAGE_PATH.'sessions/');
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.
// --------------------------------------------------------------
require SYS_PATH.'loader'.EXT;
require SYS_PATH.'config'.EXT;
require SYS_PATH.'module'.EXT;
require SYS_PATH.'arr'.EXT;
// --------------------------------------------------------------
// Register the active modules.
// --------------------------------------------------------------
Module::$modules = $active;
unset($active);
// --------------------------------------------------------------
// 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.
......@@ -55,33 +65,34 @@ error_reporting(E_ALL | E_STRICT);
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/examiner'.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();
});
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 @@ date_default_timezone_set(Config::get('application.timezone'));
// --------------------------------------------------------------
// 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 @@ if (count(Config::get('application.packages')) > 0)
// --------------------------------------------------------------
$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 @@ foreach (array('before', ACTIVE_MODULE.'::before') as $filter)
// --------------------------------------------------------------
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 @@ $response->content = (string) $response->content;
// --------------------------------------------------------------
// Close the session.
// --------------------------------------------------------------
if (Config::get('session.driver') != '')
{
Session::close();
}
if (Config::get('session.driver') != '') Session::close();
// --------------------------------------------------------------
// Send the response to the browser.
......
<?php namespace System;
<?php namespace Laravel;
class Loader {
......@@ -7,7 +7,7 @@ class Loader {
*
* @var array
*/
public static $paths = array(BASE_PATH, MODEL_PATH, LIBRARY_PATH);
public static $paths = array(BASE_PATH);
/**
* All of the class aliases.
......@@ -26,12 +26,14 @@ class Loader {
/**
* Bootstrap the auto-loader.
*
* @param array $paths
* @return void
*/
public static function bootstrap()
public static function bootstrap($paths = array())
{
static::$aliases = Config::get('aliases');
static::$modules = Config::get('application.modules');
foreach ($paths as $path) { static::register($path); }
}
/**
......@@ -85,7 +87,7 @@ class Loader {
// module name, we'll extract the module name from the file.
$module = substr($file, 0, strpos($file, '/'));
if (in_array($module, static::$modules))
if (in_array($module, Module::$modules))
{
$module = MODULE_PATH.$module.'/';
......
<?php namespace System;
<?php namespace Laravel;
class Memcached {
......
<?php namespace System;
<?php namespace Laravel;
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 {
......
<?php namespace System;
<?php namespace Laravel;
class Paginator {
......
<?php namespace System;
<?php namespace Laravel;
class Redirect {
......
<?php namespace System;
<?php namespace Laravel;
class Request {
......
<?php namespace System;
<?php namespace Laravel;
class Response {
......
<?php namespace System\Routing;
<?php namespace Laravel\Routing;
class Filter {
......
<?php namespace System\Routing;
<?php namespace Laravel\Routing;
class Finder {
......
<?php namespace System\Routing;
<?php namespace Laravel\Routing;
use System\Config;
use Laravel\Config;
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
// 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);
}
......@@ -87,21 +87,15 @@ class Loader {
* 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))
{
......
<?php namespace System\Routing;
<?php namespace Laravel\Routing;
use System\Package;
use System\Response;
use Laravel\Package;
use Laravel\Response;
class Route {
......
<?php namespace System\Routing;
<?php namespace Laravel\Routing;
use System\Request;
use Laravel\Request;
class Router {
......
<?php namespace System;
<?php namespace Laravel;
class Session {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
use System\Cache;
use System\Config;
use Laravel\Cache;
use Laravel\Config;
class APC implements Driver {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
use System\Config;
use System\Crypter;
use Laravel\Config;
use Laravel\Crypter;
class Cookie implements Driver {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
use System\Config;
use Laravel\Config;
class DB implements Driver, Sweeper {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
interface Driver {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
class File implements Driver, Sweeper {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
use System\Cache;
use System\Config;
use Laravel\Cache;
use Laravel\Config;
class Memcached implements Driver {
......
<?php namespace System\Session;
<?php namespace Laravel\Session;
interface Sweeper {
......
<?php namespace System;
<?php namespace Laravel;
class Str {
......
<?php namespace System;
<?php namespace Laravel;
class URL {
......
<?php namespace System;
<?php namespace Laravel;
class Validator {
......
......@@ -68,9 +68,8 @@ class View {
/**
* 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 application directory, followed by the view names
* for all other modules.
* The view names for the active module will be searched first, followed by the view names
* for the default module. Finally, the names for all modules will be searched.
*
* @param string $name
* @param array $data
......@@ -78,7 +77,7 @@ class View {
*/
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);
......@@ -102,16 +101,9 @@ class 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/';
if ($module != 'application')
{
$view = substr($view, strpos($view, ':') + 2);
}
return array($module, $path, $view);
return array($module, Module::path($module).'views/', $view);
}
/**
......@@ -142,7 +134,7 @@ class View {
{
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();
}
......
File added
......@@ -3,40 +3,47 @@
* Laravel - A clean and classy framework for PHP web development.
*
* @package Laravel
* @version 1.5.3
* @version 2.0.0
* @author Taylor Otwell
* @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.
// --------------------------------------------------------------
$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.
......
<?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