Commit 9e9ee931 authored by Taylor Otwell's avatar Taylor Otwell

moved session class.

parent 75ba2447
<?php <?php
class Home_Controller extends Controller { class Home_Controller {
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
......
...@@ -53,16 +53,11 @@ class Autoloader { ...@@ -53,16 +53,11 @@ class Autoloader {
protected static function find($class) protected static function find($class)
{ {
// After PHP namespaces were introduced, most libaries ditched underscores for // After PHP namespaces were introduced, most libaries ditched underscores for
// for namespaces to indicate the class directory hierarchy. We will chec for // for namespaces to indicate the class directory hierarchy. We will check for
// the present of namespace slashes to determine the directory separator. // the present of namespace slashes to determine the directory separator.
if (strpos($class, '\\') !== false) $separator = (strpos($class, '\\') !== false) ? '\\' : '_';
{
$library = substr($class, 0, strpos($class, '\\')); $library = substr($class, 0, strpos($class, $separator));
}
else
{
$library = substr($class, 0, strpos($class, '_'));
}
$file = str_replace('\\', '/', $class); $file = str_replace('\\', '/', $class);
...@@ -95,6 +90,20 @@ class Autoloader { ...@@ -95,6 +90,20 @@ class Autoloader {
return $path; return $path;
} }
// Since not all controllers will be resolved by the controller resolver,
// we will do a quick check in the controller directory for the class.
// For instance, since base controllers would not be resolved by the
// controller class, we will need to resolve them here.
if (strpos($class, '_Controller') !== false)
{
$controller = str_replace(array('_Controller', '_'), array('', '/'), $class);
if (file_exists($path = strtolower(CONTROLLER_PATH.$controller.EXT)))
{
return $path;
}
}
} }
} }
\ No newline at end of file
...@@ -65,7 +65,7 @@ class Manager { ...@@ -65,7 +65,7 @@ class Manager {
return call_user_func($config['connector'], $config); return call_user_func($config['connector'], $config);
} }
return IoC::container()->core("database.connectors.{$config['driver']}")->connect($config); return IoC::core("database.connectors.{$config['driver']}")->connect($config);
} }
/** /**
......
...@@ -52,7 +52,12 @@ class Form { ...@@ -52,7 +52,12 @@ class Form {
$attributes['accept-charset'] = Config::get('application.encoding'); $attributes['accept-charset'] = Config::get('application.encoding');
} }
$append = ($method == 'PUT' or $method == 'DELETE') ? static::hidden(Request::spoofer, $method) : ''; $append = '';
if ($method == 'PUT' or $method == 'DELETE')
{
$append = static::hidden(Request::spoofer, $method);
}
return '<form'.HTML::attributes($attributes).'>'.$append.PHP_EOL; return '<form'.HTML::attributes($attributes).'>'.$append.PHP_EOL;
} }
...@@ -166,7 +171,11 @@ class Form { ...@@ -166,7 +171,11 @@ class Form {
{ {
static::$labels[] = $name; static::$labels[] = $name;
return '<label for="'.$name.'"'.HTML::attributes($attributes).'>'.HTML::entities($value).'</label>'.PHP_EOL; $attributes = HTML::attributes($attributes);
$value = HTML::entities($value);
return '<label for="'.$name.'"'.$attributes.'>'.$value.'</label>'.PHP_EOL;
} }
/** /**
...@@ -324,7 +333,9 @@ class Form { ...@@ -324,7 +333,9 @@ class Form {
*/ */
public static function textarea($name, $value = '', $attributes = array()) public static function textarea($name, $value = '', $attributes = array())
{ {
$attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'name' => $name)); $attributes['name'] = $name;
$attributes['id'] = static::id($name, $attributes);
if ( ! isset($attributes['rows'])) $attributes['rows'] = 10; if ( ! isset($attributes['rows'])) $attributes['rows'] = 10;
......
...@@ -30,7 +30,7 @@ if (Config::$items['session']['driver'] !== '') ...@@ -30,7 +30,7 @@ if (Config::$items['session']['driver'] !== '')
$id = Cookie::get(Config::$items['session']['cookie']); $id = Cookie::get(Config::$items['session']['cookie']);
IoC::container()->instance('laravel.session', new Session($driver, $id)); IoC::container()->instance('laravel.session', new Session\Manager($driver, $id));
} }
/** /**
......
...@@ -130,9 +130,9 @@ abstract class Controller { ...@@ -130,9 +130,9 @@ abstract class Controller {
// If the controller has specified a layout view. The response // If the controller has specified a layout view. The response
// returned by the controller method will be bound to that view // returned by the controller method will be bound to that view
// and the layout will be considered the response. // and the layout will be considered the response.
if ( ! is_null($this->layout) and $this->viewable($response)) if (is_null($response) and ! is_null($this->layout))
{ {
$response = $this->layout->with('content', $response); $response = $this->layout;
} }
} }
...@@ -149,34 +149,6 @@ abstract class Controller { ...@@ -149,34 +149,6 @@ abstract class Controller {
return $response; return $response;
} }
/**
* Deteremine if a given response is considered "viewable".
*
* This is primarily used to determine which types of responses should be
* bound to the controller's layout and which should not. We do not want
* to bind redirects and file downloads to the layout, as this obviously
* would not make any sense.
*
* @param mixed $response
* @return bool
*/
protected function viewable($response)
{
if ($response instanceof Response)
{
if ($response instanceof Redirect)
{
return false;
}
elseif ($response->headers['Content-Description'] == 'File Transfer')
{
return false;
}
}
return true;
}
/** /**
* Register filters on the controller's methods. * Register filters on the controller's methods.
* *
...@@ -195,9 +167,9 @@ abstract class Controller { ...@@ -195,9 +167,9 @@ abstract class Controller {
*/ */
protected function filter($name, $filters) protected function filter($name, $filters)
{ {
$this->filters[] = new Filter_Collection($name, $filters); $this->filters[$name][] = new Filter_Collection($name, $filters);
return $this->filters[count($this->filters) - 1]; return $this->filters[$name][count($this->filters) - 1];
} }
/** /**
...@@ -209,11 +181,13 @@ abstract class Controller { ...@@ -209,11 +181,13 @@ abstract class Controller {
*/ */
protected function filters($name, $method) protected function filters($name, $method)
{ {
if ( ! isset($this->filters[$name])) return array();
$filters = array(); $filters = array();
foreach ($this->filters as $filter) foreach ($this->filters[$name] as $filter)
{ {
if ($filter->name === $name and $filter->applies($method)) if ($filter->applies($method))
{ {
$filters = array_merge($filters, $filter->filters); $filters = array_merge($filters, $filter->filters);
} }
......
<?php namespace Laravel; <?php namespace Laravel\Session;
use Closure; use Closure;
use Laravel\Str;
use Laravel\Config;
use Laravel\Cookie;
use Laravel\Session\Drivers\Driver; use Laravel\Session\Drivers\Driver;
use Laravel\Session\Drivers\Sweeper; use Laravel\Session\Drivers\Sweeper;
...@@ -9,7 +12,7 @@ if (Config::$items['application']['key'] === '') ...@@ -9,7 +12,7 @@ if (Config::$items['application']['key'] === '')
throw new \Exception("An application key is required to use sessions."); throw new \Exception("An application key is required to use sessions.");
} }
class Session { class Manager {
/** /**
* The session array that is stored by the driver. * The session array that is stored by the driver.
...@@ -266,7 +269,10 @@ class Session { ...@@ -266,7 +269,10 @@ class Session {
{ {
foreach ($this->session['data'] as $key => $value) foreach ($this->session['data'] as $key => $value)
{ {
if (strpos($key, ':old:') === 0) $this->forget($key); if (strpos($key, ':old:') === 0)
{
$this->forget($key);
}
} }
// Now that all of the "old" keys have been removed from the session data, // Now that all of the "old" keys have been removed from the session data,
......
...@@ -10,6 +10,9 @@ class URL { ...@@ -10,6 +10,9 @@ class URL {
* <code> * <code>
* // Create a URL to a location within the application * // Create a URL to a location within the application
* $url = URL::to('user/profile'); * $url = URL::to('user/profile');
*
* // Create a HTTPS URL to a location within the application
* $url = URL::to('user/profile', true);
* </code> * </code>
* *
* @param string $url * @param string $url
...@@ -20,29 +23,14 @@ class URL { ...@@ -20,29 +23,14 @@ class URL {
{ {
if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url; if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url;
return rtrim(static::root($https), '/').'/'.ltrim($url, '/'); $root = Config::$items['application']['url'].'/'.Config::$items['application']['index'];
}
/**
* Get the URL to the root of the application.
*
* @param bool $https
* @return string
*/
protected static function root($https = false)
{
$base = Config::$items['application']['url'].'/'.Config::$items['application']['index'];
// It is possible for the developer to totally disable the generation of links
// that use HTTPS. This is primarily to create a convenient test environment
// when using SSL is not an option. We will only replace the first occurence
// of "http" with "https" since URLs are sometimes passed in query strings.
if ($https and Config::$items['application']['ssl']) if ($https and Config::$items['application']['ssl'])
{ {
$base = preg_replace('~http://~', 'https://', $base, 1); $root = preg_replace('~http://~', 'https://', $root, 1);
} }
return $base; return rtrim($root, '/').'/'.ltrim($url, '/');
} }
/** /**
......
...@@ -29,3 +29,5 @@ $public = __DIR__; ...@@ -29,3 +29,5 @@ $public = __DIR__;
// Launch Laravel. // Launch Laravel.
// -------------------------------------------------------------- // --------------------------------------------------------------
require $laravel.'/laravel.php'; require $laravel.'/laravel.php';
echo number_format((microtime(true) - LARAVEL_START) * 1000, 2);
\ 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