moved session class.

This commit is contained in:
Taylor Otwell 2011-11-09 21:55:21 -06:00
parent 75ba2447f8
commit 9e9ee931b5
9 changed files with 61 additions and 71 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
class Home_Controller extends Controller { class Home_Controller {
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -53,16 +53,11 @@ public static function load($class)
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 @@ protected static function find($class)
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;
}
}
} }
} }

View File

@ -65,7 +65,7 @@ protected static function connect($config)
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);
} }
/** /**

View File

@ -52,7 +52,12 @@ public static function open($action = null, $method = 'POST', $attributes = arra
$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 @@ public static function label($name, $value, $attributes = array())
{ {
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 @@ public static function file($name, $attributes = array())
*/ */
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;

View File

@ -30,7 +30,7 @@
$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));
} }
/** /**

View File

@ -130,9 +130,9 @@ public function execute($method, $parameters = array())
// 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 @@ public function execute($method, $parameters = array())
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 @@ protected function viewable($response)
*/ */
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 @@ protected function filter($name, $filters)
*/ */
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);
} }

View File

@ -1,6 +1,9 @@
<?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 @@
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 @@ protected function age()
{ {
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,

View File

@ -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 @@ public static function to($url = '', $https = false)
{ {
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, '/');
} }
/** /**

View File

@ -29,3 +29,5 @@
// Launch Laravel. // Launch Laravel.
// -------------------------------------------------------------- // --------------------------------------------------------------
require $laravel.'/laravel.php'; require $laravel.'/laravel.php';
echo number_format((microtime(true) - LARAVEL_START) * 1000, 2);