
diff --git a/application/config/application.php b/application/config/application.php
index a27e0af0..74ae6984 100644
--- a/application/config/application.php
+++ b/application/config/application.php
@@ -112,24 +112,26 @@
*/
'aliases' => array(
+ 'Arr' => 'Laravel\\Arr',
'Asset' => 'Laravel\\Asset',
- 'Auth' => 'Laravel\\Security\\Auth',
+ 'Auth' => 'Laravel\\Auth',
'Benchmark' => 'Laravel\\Benchmark',
'Cache' => 'Laravel\\Cache\\Manager',
'Config' => 'Laravel\\Config',
'Controller' => 'Laravel\\Routing\\Controller',
'Cookie' => 'Laravel\\Cookie',
- 'Crypter' => 'Laravel\\Security\\Crypter',
+ 'Crypter' => 'Laravel\\Crypter',
'DB' => 'Laravel\\Database\\Manager',
'Eloquent' => 'Laravel\\Database\\Eloquent\\Model',
'File' => 'Laravel\\File',
'Form' => 'Laravel\\Form',
- 'Hash' => 'Laravel\\Security\\Hash',
+ 'Hash' => 'Laravel\\Hash',
'HTML' => 'Laravel\\HTML',
'Inflector' => 'Laravel\\Inflector',
'Input' => 'Laravel\\Input',
'IoC' => 'Laravel\\IoC',
'Lang' => 'Laravel\\Lang',
+ 'Memcached' => 'Laravel\\Memcached',
'Paginator' => 'Laravel\\Paginator',
'URL' => 'Laravel\\URL',
'Redirect' => 'Laravel\\Redirect',
@@ -139,7 +141,7 @@
'Section' => 'Laravel\\Section',
'Session' => 'Laravel\\Facades\\Session',
'Str' => 'Laravel\\Str',
- 'Validator' => 'Laravel\\Validation\\Validator',
+ 'Validator' => 'Laravel\\Validator',
'View' => 'Laravel\\View',
),
diff --git a/laravel/arr.php b/laravel/arr.php
index 3e84d56a..6c15c2f3 100644
--- a/laravel/arr.php
+++ b/laravel/arr.php
@@ -75,6 +75,42 @@ public static function set(&$array, $key, $value)
$array[array_shift($keys)] = $value;
}
+ /**
+ * Remove an array item from a given array.
+ *
+ * The same "dot" syntax used by the "get" method may be used here.
+ *
+ *
+ * // Remove the $array['user']['name'] item from the array
+ * Arr::forget($array, 'user.name');
+ *
+ *
+ * @param array $array
+ * @param string $key
+ * @param mixed $value
+ * @return void
+ */
+ public static function forget(&$array, $key)
+ {
+ if (is_null($key)) return;
+
+ $keys = explode('.', $key);
+
+ while (count($keys) > 1)
+ {
+ $key = array_shift($keys);
+
+ if ( ! isset($array[$key]) or ! is_array($array[$key]))
+ {
+ return;
+ }
+
+ $array =& $array[$key];
+ }
+
+ unset($array[array_shift($keys)]);
+ }
+
/**
* Return the first element in an array which passes a given truth test.
*
diff --git a/laravel/security/auth.php b/laravel/auth.php
similarity index 97%
rename from laravel/security/auth.php
rename to laravel/auth.php
index ace58f0f..b48af281 100644
--- a/laravel/security/auth.php
+++ b/laravel/auth.php
@@ -1,10 +1,4 @@
- array('singleton' => true, 'resolver' => function($c)
- {
- return new Routing\Router($c->core('routing.loader'), CONTROLLER_PATH);
- }),
-
-
- 'laravel.routing.loader' => array('singleton' => true, 'resolver' => function($c)
- {
- return new Routing\Loader(APP_PATH, ROUTE_PATH);
- }),
-
-
- 'laravel.routing.caller' => array('resolver' => function($c)
- {
- return new Routing\Caller($c, require APP_PATH.'filters'.EXT, CONTROLLER_PATH);
- }),
-
-
- 'laravel.database.connectors.sqlite' => array('resolver' => function($c)
- {
- return new Database\Connectors\SQLite(DATABASE_PATH);
- }),
-
- 'laravel.database.connectors.mysql' => array('resolver' => function($c)
- {
- return new Database\Connectors\MySQL;
- }),
-
- 'laravel.database.connectors.pgsql' => array('resolver' => function($c)
- {
- return new Database\Connectors\Postgres;
- }),
-
-
- 'laravel.cache.apc' => array('resolver' => function($c)
- {
- return new Cache\Drivers\APC(Config::get('cache.key'));
- }),
-
-
- 'laravel.cache.file' => array('resolver' => function($c)
- {
- return new Cache\Drivers\File(CACHE_PATH);
- }),
-
-
- 'laravel.cache.redis' => array('resolver' => function()
- {
- return new Cache\Drivers\Redis(Redis::db());
- }),
-
-
- 'laravel.cache.memcached' => array('resolver' => function($c)
- {
- return new Cache\Drivers\Memcached($c->core('cache.memcache.connection'), Config::get('cache.key'));
- }),
-
-
- 'laravel.cache.memcache.connection' => array('singleton' => true, 'resolver' => function($c)
- {
- $memcache = new \Memcache;
-
- foreach (Config::get('cache.memcached') as $server)
- {
- $memcache->addServer($server['host'], $server['port'], true, $server['weight']);
- }
-
- if ($memcache->getVersion() === false)
- {
- throw new \Exception('Could not establish memcached connection. Please verify your memcached configuration.');
- }
-
- return $memcache;
- }),
-
-
- 'laravel.session.apc' => array('resolver' => function($c)
- {
- return new Session\Drivers\APC($c->core('cache.apc'));
- }),
-
-
- 'laravel.session.cookie' => array('resolver' => function($c)
- {
- return new Session\Drivers\Cookie;
- }),
-
-
- 'laravel.session.database' => array('resolver' => function($c)
- {
- return new Session\Drivers\Database(Database\Manager::connection());
- }),
-
-
- 'laravel.session.file' => array('resolver' => function($c)
- {
- return new Session\Drivers\File(SESSION_PATH);
- }),
-
-
- 'laravel.session.redis' => array('resolver' => function($c)
- {
- return new Session\Drivers\Redis($c->core('cache.redis'));
- }),
-
-
- 'laravel.session.memcached' => array('resolver' => function($c)
- {
- return new Session\Drivers\Memcached($c->core('cache.memcached'));
- }),
-
-);
\ No newline at end of file
diff --git a/laravel/security/crypter.php b/laravel/crypter.php
similarity index 97%
rename from laravel/security/crypter.php
rename to laravel/crypter.php
index 35df5872..51ff19bf 100644
--- a/laravel/security/crypter.php
+++ b/laravel/crypter.php
@@ -1,4 +1,4 @@
-connect($config);
+ return Connectors\Factory::make($config['driver'])->connect($config);
}
/**
diff --git a/laravel/security/hash.php b/laravel/hash.php
similarity index 97%
rename from laravel/security/hash.php
rename to laravel/hash.php
index 49c64ff3..a1eabcd6 100644
--- a/laravel/security/hash.php
+++ b/laravel/hash.php
@@ -1,4 +1,4 @@
-flash(Input::old_input, array());
+ }
+ }
+
/**
* Determine if the old input data contains an item.
*
diff --git a/laravel/container.php b/laravel/ioc.php
similarity index 50%
rename from laravel/container.php
rename to laravel/ioc.php
index 63679d37..f573852b 100644
--- a/laravel/container.php
+++ b/laravel/ioc.php
@@ -3,32 +3,96 @@
class IoC {
/**
- * The active container instance.
+ * The registered dependencies.
*
- * @var Container
+ * @var array
*/
- public static $container;
+ protected static $registry = array();
/**
- * Bootstrap the global IoC instance.
+ * The resolved singleton instances.
*
+ * @var array
+ */
+ protected static $singletons = array();
+
+ /**
+ * Bootstrap the application IoC container.
+ *
+ * @param array $registry
* @return void
*/
- public static function bootstrap()
+ public static function bootstrap($registry = array())
{
Config::load('container');
- static::$container = new Container(Config::$items['container']);
+ static::$registry = Config::$items['container'];
}
/**
- * Get the active container instance.
+ * Register an object and its resolver.
*
- * @return Container
+ * The IoC container instance is always passed to the resolver, allowing the
+ * nested resolution of other objects from the container.
+ *
+ *
+ * // Register an object and its resolver
+ * IoC::register('mailer', function($c) {return new Mailer;});
+ *
+ *
+ * @param string $name
+ * @param Closure $resolver
+ * @return void
*/
- public static function container()
+ public static function register($name, $resolver, $singleton = false)
{
- return static::$container;
+ static::$registry[$name] = array('resolver' => $resolver, 'singleton' => $singleton);
+ }
+
+ /**
+ * Determine if an object has been registered in the container.
+ *
+ * @param string $name
+ * @return bool
+ */
+ public static function registered($name)
+ {
+ return array_key_exists($name, static::$registry);
+ }
+
+ /**
+ * Register an object as a singleton.
+ *
+ * Singletons will only be instantiated the first time they are resolved.
+ * On subsequent requests for the object, the original instance will be returned.
+ *
+ * @param string $name
+ * @param Closure $resolver
+ * @return void
+ */
+ public static function singleton($name, $resolver)
+ {
+ static::register($name, $resolver, true);
+ }
+
+ /**
+ * Register an instance as a singleton.
+ *
+ * This method allows you to register an already existing object instance
+ * with the container to be managed as a singleton instance.
+ *
+ *
+ * // Register an instance as a singleton in the container
+ * IoC::instance('mailer', new Mailer);
+ *
+ *
+ * @param string $name
+ * @param mixed $instance
+ * @return void
+ */
+ public static function instance($name, $instance)
+ {
+ static::$singletons[$name] = $instance;
}
/**
@@ -51,141 +115,7 @@ public static function container()
*/
public static function core($name, $parameters = array())
{
- return static::$container->core($name, $parameters);
- }
-
- /**
- * Magic Method for calling methods on the active container instance.
- *
- *
- * // Call the "resolve" method on the active container
- * $instance = IoC::resolve('laravel.routing.router');
- *
- * // Call the "instance" method on the active container
- * IoC::instance('mailer', new Mailer);
- *
- */
- public static function __callStatic($method, $parameters)
- {
- return call_user_func_array(array(static::$container, $method), $parameters);
- }
-
-}
-
-class Container {
-
- /**
- * The resolved singleton instances.
- *
- * @var array
- */
- public $singletons = array();
-
- /**
- * The registered dependencies.
- *
- * @var array
- */
- protected $registry = array();
-
- /**
- * Create a new IoC container instance.
- *
- * @param array $registry
- * @return void
- */
- public function __construct($registry = array())
- {
- $this->registry = $registry;
- }
-
- /**
- * Register an object and its resolver.
- *
- * The IoC container instance is always passed to the resolver, allowing the
- * nested resolution of other objects from the container.
- *
- *
- * // Register an object and its resolver
- * IoC::register('mailer', function($c) {return new Mailer;});
- *
- *
- * @param string $name
- * @param Closure $resolver
- * @return void
- */
- public function register($name, $resolver, $singleton = false)
- {
- $this->registry[$name] = array('resolver' => $resolver, 'singleton' => $singleton);
- }
-
- /**
- * Determine if an object has been registered in the container.
- *
- * @param string $name
- * @return bool
- */
- public function registered($name)
- {
- return array_key_exists($name, $this->registry);
- }
-
- /**
- * Register an object as a singleton.
- *
- * Singletons will only be instantiated the first time they are resolved.
- * On subsequent requests for the object, the original instance will be returned.
- *
- * @param string $name
- * @param Closure $resolver
- * @return void
- */
- public function singleton($name, $resolver)
- {
- $this->register($name, $resolver, true);
- }
-
- /**
- * Register an instance as a singleton.
- *
- * This method allows you to register an already existing object instance
- * with the container to be managed as a singleton instance.
- *
- *
- * // Register an instance as a singleton in the container
- * IoC::instance('mailer', new Mailer);
- *
- *
- * @param string $name
- * @param mixed $instance
- * @return void
- */
- public function instance($name, $instance)
- {
- $this->singletons[$name] = $instance;
- }
-
- /**
- * Resolve a core Laravel class from the container.
- *
- *
- * // Resolve the "laravel.router" class from the container
- * $input = IoC::core('router');
- *
- * // Equivalent resolution using the "resolve" method
- * $input = IoC::resolve('laravel.router');
- *
- * // Pass an array of parameters to the resolver
- * $input = IoC::core('router', array('test'));
- *
- *
- * @param string $name
- * @param array $parameters
- * @return mixed
- */
- public function core($name, $parameters = array())
- {
- return $this->resolve("laravel.{$name}", $parameters);
+ return static::resolve("laravel.{$name}", $parameters);
}
/**
@@ -203,23 +133,28 @@ public function core($name, $parameters = array())
* @param array $parameters
* @return mixed
*/
- public function resolve($name, $parameters = array())
+ public static function resolve($name, $parameters = array())
{
- if (array_key_exists($name, $this->singletons)) return $this->singletons[$name];
+ if (array_key_exists($name, static::$singletons))
+ {
+ return static::$singletons[$name];
+ }
- if ( ! $this->registered($name))
+ if ( ! static::registered($name))
{
throw new \Exception("Error resolving [$name]. No resolver has been registered in the container.");
}
- $object = call_user_func($this->registry[$name]['resolver'], $this, $parameters);
+ $object = call_user_func(static::$registry[$name]['resolver'], $parameters);
- if (isset($this->registry[$name]['singleton']) and $this->registry[$name]['singleton'])
+ if (isset(static::$registry[$name]['singleton']) and static::$registry[$name]['singleton'])
{
- return $this->singletons[$name] = $object;
+ return static::$singletons[$name] = $object;
}
return $object;
}
}
+
+IoC::bootstrap();
\ No newline at end of file
diff --git a/laravel/laravel.php b/laravel/laravel.php
index 18920564..971ae6a2 100644
--- a/laravel/laravel.php
+++ b/laravel/laravel.php
@@ -99,11 +99,16 @@
*/
if (Config::$items['session']['driver'] !== '')
{
- $driver = IoC::core('session.'.Config::$items['session']['driver']);
+ require SYS_PATH.'ioc'.EXT;
+ require SYS_PATH.'session/payload'.EXT;
+ require SYS_PATH.'session/drivers/driver'.EXT;
+ require SYS_PATH.'session/drivers/factory'.EXT;
$id = Cookie::get(Config::$items['session']['cookie']);
- IoC::instance('laravel.session', new Session\Manager($driver, $id));
+ $driver = Session\Drivers\Factory::make(Config::$items['session']['driver']);
+
+ IoC::instance('laravel.session', new Session\Payload($driver, $id));
}
/**
@@ -168,7 +173,11 @@
list($uri, $method) = array(Request::uri(), Request::method());
-Request::$route = IoC::core('routing.router')->route($method, $uri);
+$loader = new Routing\Loader(APP_PATH, ROUTE_PATH);
+
+$router = new Routing\Router($loader, CONTROLLER_PATH);
+
+Request::$route = $router->route($method, $uri);
if ( ! is_null(Request::$route))
{
diff --git a/laravel/memcached.php b/laravel/memcached.php
new file mode 100644
index 00000000..8089b21a
--- /dev/null
+++ b/laravel/memcached.php
@@ -0,0 +1,62 @@
+
+ * // Create a new localhost Memcached connection instance.
+ * $memcache = Memcached::connect(array('host' => '127.0.0.1', 'port' => 11211));
+ *
+ *
+ * @param array $servers
+ * @return Memcache
+ */
+ public static function connect($servers)
+ {
+ $memcache = new \Memcache;
+
+ foreach ($servers as $server)
+ {
+ $memcache->addServer($server['host'], $server['port'], true, $server['weight']);
+ }
+
+ if ($memcache->getVersion() === false)
+ {
+ throw new \Exception('Could not establish memcached connection. Please verify your configuration.');
+ }
+
+ return $memcache;
+ }
+
+}
\ No newline at end of file
diff --git a/laravel/validation/messages.php b/laravel/messages.php
similarity index 98%
rename from laravel/validation/messages.php
rename to laravel/messages.php
index 4dad26ac..170915e6 100644
--- a/laravel/validation/messages.php
+++ b/laravel/messages.php
@@ -1,4 +1,4 @@
-session = $driver->load($id);
}
+ // If the session doesn't exist or is invalid, we will create a new session
+ // array and mark the session as being non-existent. Some drivers, such as
+ // the database driver, need to know whether the session exists in storage
+ // so they can know whether to "insert" or "update" the session.
if (is_null($this->session) or $this->invalid())
{
$this->exists = false;
- $this->session = array('id' => Str::random(40), 'data' => array());
+ $this->session = array('id' => Str::random(40), 'data' => array(
+ ':new:' => array(),
+ ':old:' => array(),
+ ));
}
+ // A CSRF token is stored in every session. The token is used by the Form
+ // class and the "csrf" filter to protect the application from cross-site
+ // request forgery attacks. The token is simply a long, random string
+ // which should be posted with each request.
if ( ! $this->has('csrf_token'))
{
- // A CSRF token is stored in every session. The token is used by the
- // Form class and the "csrf" filter to protect the application from
- // cross-site request forgery attacks. The token is simply a long,
- // random string which should be posted with each request.
$this->put('csrf_token', Str::random(40));
}
}
@@ -113,12 +121,17 @@ public function has($key)
*/
public function get($key, $default = null)
{
- foreach (array($key, ':old:'.$key, ':new:'.$key) as $possibility)
+ if (isset($this->session['data'][$key]))
{
- if (array_key_exists($possibility, $this->session['data']))
- {
- return $this->session['data'][$possibility];
- }
+ return $this->session['data'][$key];
+ }
+ elseif (isset($this->session['data'][':new:'][$key]))
+ {
+ return $this->session['data'][':new:'][$key];
+ }
+ elseif (isset($this->session['data'][':old:'][$key]))
+ {
+ return $this->session['data'][':old:'][$key];
}
return ($default instanceof Closure) ? call_user_func($default) : $default;
@@ -133,13 +146,14 @@ public function get($key, $default = null)
*/
public function put($key, $value)
{
- $this->session['data'][$key] = $value;
+ Arr::set($this->session['data'], $key, $value);
}
/**
* Write an item to the session flash data.
*
- * Flash data only exists for the next request to the application.
+ * Flash data only exists for the next request to the application, and is
+ * useful for storing temporary data such as error or status messages.
*
* @param string $key
* @param mixed $value
@@ -147,27 +161,17 @@ public function put($key, $value)
*/
public function flash($key, $value)
{
- $this->put(':new:'.$key, $value);
+ Arr::set($this->session['data'][':new:'], $key, $value);
}
/**
- * Keep all of the session flash data from expiring at the end of the request.
+ * Keep the session flash data from expiring at the end of the request.
*
* @return void
*/
public function reflash()
{
- $flash = array();
-
- foreach ($this->session['data'] as $key => $value)
- {
- if (strpos($key, ':old:') === 0)
- {
- $flash[] = str_replace(':old:', '', $key);
- }
- }
-
- $this->keep($flash);
+ $this->session['data'][':new:'] += $this->session['data'][':old:'];
}
/**
@@ -188,11 +192,11 @@ public function keep($keys)
* Remove an item from the session data.
*
* @param string $key
- * @return Driver
+ * @return void
*/
public function forget($key)
{
- unset($this->session['data'][$key]);
+ Arr::forget($this->session['data'], $key);
}
/**
@@ -250,7 +254,9 @@ public function save(Driver $driver)
// need to determine if garbage collection should be run for the request.
// Since garbage collection can be expensive, the probability of it
// occuring is controlled by the "sweepage" configuration option.
- if ($driver instanceof Sweeper and (mt_rand(1, $config['sweepage'][1]) <= $config['sweepage'][0]))
+ $sweepage = $config['sweepage'];
+
+ if ($driver instanceof Sweeper and (mt_rand(1, $sweepage[1]) <= $sweepage[0]))
{
$driver->sweep(time() - ($config['lifetime'] * 60));
}
@@ -267,21 +273,9 @@ public function save(Driver $driver)
*/
protected function age()
{
- foreach ($this->session['data'] as $key => $value)
- {
- if (strpos($key, ':old:') === 0)
- {
- $this->forget($key);
- }
- }
+ $this->session['data'][':old:'] = $this->session['data'][':new:'];
- // Now that all of the "old" keys have been removed from the session data,
- // we can re-address all of the newly flashed keys to have old addresses.
- // The array_combine method uses the first array for keys, and the second
- // array for values to construct a single array from both.
- $keys = str_replace(':new:', ':old:', array_keys($this->session['data']));
-
- $this->session['data'] = array_combine($keys, array_values($this->session['data']));
+ $this->session['data'][':new:'] = array();
}
/**
diff --git a/laravel/validation/validator.php b/laravel/validator.php
similarity index 99%
rename from laravel/validation/validator.php
rename to laravel/validator.php
index 9d76db35..3b00d3e5 100644
--- a/laravel/validation/validator.php
+++ b/laravel/validator.php
@@ -1,11 +1,6 @@
-data[$key]);
}
+ /**
+ * Get the evaluated string content of the view.
+ *
+ * @return string
+ */
+ public function __toString()
+ {
+ return $this->render();
+ }
+
/**
* Magic Method for handling the dynamic creation of named views.
*
diff --git a/laravel/views/error/exception.php b/laravel/views/error/exception.php
deleted file mode 100644
index 223ad5f5..00000000
--- a/laravel/views/error/exception.php
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-