mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
various refactoring and tweaks.
This commit is contained in:
parent
df9130dafa
commit
af36cb3d5a
@ -45,8 +45,10 @@ return array(
|
||||
|
|
||||
*/
|
||||
|
||||
'servers' => array(
|
||||
'memcached' => array(
|
||||
|
||||
array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 100),
|
||||
|
||||
),
|
||||
|
||||
);
|
@ -59,13 +59,19 @@ return array(
|
||||
|
||||
'auth' => function()
|
||||
{
|
||||
if ( ! Auth::check()) return Redirect::to_login();
|
||||
if ( ! Auth::check())
|
||||
{
|
||||
return Redirect::to_login();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
'csrf' => function()
|
||||
{
|
||||
if (Input::get('csrf_token') !== Form::raw_token()) return Response::error('500');
|
||||
if (Input::get('csrf_token') !== Form::raw_token())
|
||||
{
|
||||
return Response::error('500');
|
||||
}
|
||||
},
|
||||
|
||||
);
|
0
application/language/en/.gitignore
vendored
0
application/language/en/.gitignore
vendored
@ -49,7 +49,6 @@ $constants = array(
|
||||
'ROUTE_PATH' => APP_PATH.'routes/',
|
||||
'SESSION_PATH' => STORAGE_PATH.'sessions/',
|
||||
'SYS_CONFIG_PATH' => SYS_PATH.'config/',
|
||||
'SYS_LANG_PATH' => SYS_PATH.'language/',
|
||||
'SYS_VIEW_PATH' => SYS_PATH.'views/',
|
||||
'VIEW_PATH' => APP_PATH.'views/',
|
||||
);
|
||||
|
@ -6,8 +6,12 @@
|
||||
* error handler to create a more readable message.
|
||||
*/
|
||||
$message = function($e)
|
||||
{
|
||||
$file = str_replace(array(APP_PATH, SYS_PATH), array('APP_PATH/', 'SYS_PATH/'), $e->getFile());
|
||||
{
|
||||
$search = array(APP_PATH, SYS_PATH);
|
||||
|
||||
$replace = array('APP_PATH/', 'SYS_PATH/');
|
||||
|
||||
$file = str_replace($search, $replace, $e->getFile());
|
||||
|
||||
return rtrim($e->getMessage(), '.').' in '.$file.' on line '.$e->getLine().'.';
|
||||
};
|
||||
@ -35,14 +39,23 @@ $severity = function($e)
|
||||
E_STRICT => 'Runtime Notice',
|
||||
);
|
||||
|
||||
return (array_key_exists($e->getCode(), $levels)) ? $levels[$e->getCode()] : $e->getCode();
|
||||
if (array_key_exists($e->getCode(), $levels))
|
||||
{
|
||||
$level = $levels[$e->getCode()];
|
||||
}
|
||||
else
|
||||
{
|
||||
$level = $e->getCode();
|
||||
}
|
||||
|
||||
return $level;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create the exception handler function. All of the error handlers
|
||||
* registered with PHP call this closure to keep the code D.R.Y.
|
||||
* Each of the formatting closures defined above will be passed
|
||||
* into the handler for convenient use.
|
||||
* registered by the framework call this closure to avoid duplicate
|
||||
* code. Each of the formatting closures defined above will be
|
||||
* passed into the handler for convenient use.
|
||||
*/
|
||||
$handler = function($e) use ($message, $severity)
|
||||
{
|
||||
|
2
laravel/cache/drivers/driver.php
vendored
2
laravel/cache/drivers/driver.php
vendored
@ -61,7 +61,7 @@ abstract class Driver {
|
||||
* cache, store the default value in the cache and return it.
|
||||
*
|
||||
* <code>
|
||||
* // Get an item from the cache, or cache a value for 15 minutes if it doesn't exist
|
||||
* // Get an item from the cache, or cache a value for 15 minutes
|
||||
* $name = Cache::remember('name', 'Taylor', 15);
|
||||
*
|
||||
* // Use a closure for deferred execution
|
||||
|
4
laravel/cache/manager.php
vendored
4
laravel/cache/manager.php
vendored
@ -12,8 +12,8 @@ class Manager {
|
||||
/**
|
||||
* Get a cache driver instance.
|
||||
*
|
||||
* If no driver name is specified, the default cache driver will be
|
||||
* returned as defined in the cache configuration file.
|
||||
* If no driver name is specified, the default cache driver will
|
||||
* be returned as defined in the cache configuration file.
|
||||
*
|
||||
* <code>
|
||||
* // Get the default cache driver instance
|
||||
|
@ -101,7 +101,7 @@ return array(
|
||||
{
|
||||
$memcache = new \Memcache;
|
||||
|
||||
foreach (Config::get('cache.servers') as $server)
|
||||
foreach (Config::get('cache.memcached') as $server)
|
||||
{
|
||||
$memcache->addServer($server['host'], $server['port'], true, $server['weight']);
|
||||
}
|
||||
|
@ -43,6 +43,36 @@ class Connection {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a fluent query against a table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return Query
|
||||
*/
|
||||
public function table($table)
|
||||
{
|
||||
return new Query($this, $this->grammar(), $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new query grammar for the connection.
|
||||
*
|
||||
* @return Grammars\Grammar
|
||||
*/
|
||||
protected function grammar()
|
||||
{
|
||||
if (isset($this->grammar)) return $this->grammar;
|
||||
|
||||
switch (isset($this->config['grammar']) ? $this->config['grammar'] : $this->driver())
|
||||
{
|
||||
case 'mysql':
|
||||
return $this->grammar = new Grammars\MySQL;
|
||||
|
||||
default:
|
||||
return $this->grammar = new Grammars\Grammar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a SQL query against the connection and return a single column result.
|
||||
*
|
||||
@ -109,18 +139,18 @@ class Connection {
|
||||
*/
|
||||
public function query($sql, $bindings = array())
|
||||
{
|
||||
// First we need to remove all expressions from the bindings
|
||||
// since they will be placed into the query as raw strings.
|
||||
// Remove expressions from the bindings since they injected into
|
||||
// the query as raw strings and are not bound parameters.
|
||||
foreach ($bindings as $key => $value)
|
||||
{
|
||||
if ($value instanceof Expression) unset($bindings[$key]);
|
||||
}
|
||||
|
||||
$sql = $this->transform($sql, $bindings);
|
||||
$sql = $this->transform(trim($sql), $bindings);
|
||||
|
||||
$this->queries[] = compact('sql', 'bindings');
|
||||
|
||||
return $this->execute($this->pdo->prepare(trim($sql)), $bindings);
|
||||
return $this->execute($this->pdo->prepare($sql), $bindings);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -178,36 +208,6 @@ class Connection {
|
||||
return $statement->rowCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Begin a fluent query against a table.
|
||||
*
|
||||
* @param string $table
|
||||
* @return Query
|
||||
*/
|
||||
public function table($table)
|
||||
{
|
||||
return new Query($this, $this->grammar(), $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new query grammar for the connection.
|
||||
*
|
||||
* @return Grammars\Grammar
|
||||
*/
|
||||
protected function grammar()
|
||||
{
|
||||
if (isset($this->grammar)) return $this->grammar;
|
||||
|
||||
switch (isset($this->config['grammar']) ? $this->config['grammar'] : $this->driver())
|
||||
{
|
||||
case 'mysql':
|
||||
return $this->grammar = new Grammars\MySQL;
|
||||
|
||||
default:
|
||||
return $this->grammar = new Grammars\Grammar;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the driver name for the database connection.
|
||||
*
|
||||
|
@ -47,8 +47,6 @@ class Grammar {
|
||||
{
|
||||
$sql = array();
|
||||
|
||||
// Iterate through each query component, calling the compiler for that
|
||||
// component and passing the query instance into the compiler.
|
||||
foreach ($this->components as $component)
|
||||
{
|
||||
if ( ! is_null($query->$component))
|
||||
@ -111,9 +109,6 @@ class Grammar {
|
||||
*/
|
||||
protected function joins(Query $query)
|
||||
{
|
||||
// Since creating a JOIN clause using string concatenation is a little
|
||||
// cumbersome, we will create a format we can pass to "sprintf" to
|
||||
// make things cleaner.
|
||||
$format = '%s JOIN %s ON %s %s %s';
|
||||
|
||||
foreach ($query->joins as $join)
|
||||
@ -281,9 +276,9 @@ class Grammar {
|
||||
// every insert to the table.
|
||||
$columns = $this->columnize(array_keys(reset($values)));
|
||||
|
||||
// Build the list of parameter place-holders for the array of values bound
|
||||
// to the query. Each insert statement should have the same number of bound
|
||||
// parameters, so we can just use the first array of values.
|
||||
// Build the list of parameter place-holders of values bound to the query.
|
||||
// Each insert should have the same number of bound paramters, so we can
|
||||
// just use the first array of values.
|
||||
$parameters = $this->parameterize(reset($values));
|
||||
|
||||
$parameters = implode(', ', array_fill(0, count($values), '('.$parameters.')'));
|
||||
|
@ -270,7 +270,14 @@ class HTML {
|
||||
|
||||
foreach ($list as $key => $value)
|
||||
{
|
||||
$html .= (is_array($value)) ? static::elements($type, $value) : '<li>'.static::entities($value).'</li>';
|
||||
if (is_array($value))
|
||||
{
|
||||
$html .= static::elements($type, $value);
|
||||
}
|
||||
else
|
||||
{
|
||||
$html .= '<li>'.static::entities($value).'</li>';
|
||||
}
|
||||
}
|
||||
|
||||
return '<'.$type.static::attributes($attributes).'>'.$html.'</'.$type.'>';
|
||||
|
@ -37,7 +37,7 @@ class Lang {
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $paths = array(SYS_LANG_PATH, LANG_PATH);
|
||||
protected $paths = array(LANG_PATH);
|
||||
|
||||
/**
|
||||
* Create a new Lang instance.
|
||||
@ -164,9 +164,6 @@ class Lang {
|
||||
|
||||
$language = array();
|
||||
|
||||
// Language files cascade. Typically, the system language array is
|
||||
// loaded first, followed by the application array. This allows the
|
||||
// convenient overriding of the system language files.
|
||||
foreach ($this->paths as $directory)
|
||||
{
|
||||
if (file_exists($path = $directory.$this->language.'/'.$file.EXT))
|
||||
|
@ -60,13 +60,11 @@ abstract class Controller {
|
||||
}
|
||||
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// be instances of the Response class. If the method did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response) $response = new Response($response);
|
||||
|
||||
$filters = array_merge($controller->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
Filter::run($controller->filters('after'), array($response));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
@ -93,6 +93,12 @@ class Route {
|
||||
// Since "before" filters can halt the request cycle, we will return
|
||||
// any response from the before filters. Allowing filters to halt the
|
||||
// request cycle makes tasks like authorization convenient.
|
||||
//
|
||||
// The route is responsible for running the global filters, and any
|
||||
// filters defined on the route itself. Since all incoming requests
|
||||
// come through a route (either defined or ad-hoc), it makes sense
|
||||
// to let the route handle the global filters. If the route uses
|
||||
// a controller, the controller will only call its own filters.
|
||||
$before = array_merge(array('before'), $this->filters('before'));
|
||||
|
||||
if ( ! is_null($response = Filter::run($before, array(), true)))
|
||||
@ -104,21 +110,22 @@ class Route {
|
||||
{
|
||||
if ($response instanceof Delegate)
|
||||
{
|
||||
return Controller::call($response->destination, $this->parameters);
|
||||
$response = Controller::call($response->destination, $this->parameters);
|
||||
}
|
||||
else
|
||||
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response)
|
||||
{
|
||||
// The after filter and the framework expects all responses to
|
||||
// be instances of the Response class. If the route did not
|
||||
// return an instsance of Response, we will make on now.
|
||||
if ( ! $response instanceof Response) $response = new Response($response);
|
||||
|
||||
$filters = array_merge($this->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
|
||||
return $response;
|
||||
$response = new Response($response);
|
||||
}
|
||||
|
||||
$filters = array_merge($this->filters('after'), array('after'));
|
||||
|
||||
Filter::run($filters, array($response));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
return Response::error('404');
|
||||
|
@ -153,7 +153,10 @@ class Router {
|
||||
foreach (explode(', ', $keys) as $key)
|
||||
{
|
||||
// Append the provided formats to the route as an optional regular expression.
|
||||
if ( ! is_null($formats = $this->provides($callback))) $key .= '(\.('.implode('|', $formats).'))?';
|
||||
if ( ! is_null($formats = $this->provides($callback)))
|
||||
{
|
||||
$key .= '(\.('.implode('|', $formats).'))?';
|
||||
}
|
||||
|
||||
if (preg_match('#^'.$this->wildcards($key).'$#', $destination))
|
||||
{
|
||||
@ -216,7 +219,9 @@ class Router {
|
||||
{
|
||||
foreach (array_reverse($segments, true) as $key => $value)
|
||||
{
|
||||
if (file_exists($path = $this->controllers.implode('/', array_slice($segments, 0, $key + 1)).EXT))
|
||||
$controller = implode('/', array_slice($segments, 0, $key + 1)).EXT;
|
||||
|
||||
if (file_exists($path = $this->controllers.$controller))
|
||||
{
|
||||
return $key + 1;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php namespace Laravel\Security;
|
||||
|
||||
use Laravel\IoC;
|
||||
use Laravel\Str;
|
||||
use Laravel\Config;
|
||||
use Laravel\Cookie;
|
||||
@ -42,7 +41,7 @@ class Auth {
|
||||
/**
|
||||
* Get the current user of the application.
|
||||
*
|
||||
* This method will call the "user" closure in the authentication configuration file.
|
||||
* This method will call the "user" closure in the auth configuration file.
|
||||
* If the user is not authenticated, null will be returned by the methd.
|
||||
*
|
||||
* If no user exists in the session, the method will check for a "remember me"
|
||||
@ -64,7 +63,9 @@ class Auth {
|
||||
|
||||
static::$user = call_user_func(Config::get('auth.user'), Session::get(Auth::user_key));
|
||||
|
||||
if (is_null(static::$user) and ! is_null($cookie = Cookie::get(Auth::remember_key)))
|
||||
$cookie = Cookie::get(Auth::remember_key);
|
||||
|
||||
if (is_null(static::$user) and ! is_null($cookie))
|
||||
{
|
||||
static::$user = static::recall($cookie);
|
||||
}
|
||||
@ -113,7 +114,9 @@ class Auth {
|
||||
{
|
||||
$config = Config::get('auth');
|
||||
|
||||
if ( ! is_null($user = call_user_func($config['attempt'], $username, $password, $config)))
|
||||
$user = call_user_func($config['attempt'], $username, $password, $config);
|
||||
|
||||
if ( ! is_null($user))
|
||||
{
|
||||
static::login($user, $config, $remember);
|
||||
|
||||
|
@ -54,7 +54,9 @@ class Crypter {
|
||||
|
||||
$iv = mcrypt_create_iv(static::iv_size(), $randomizer);
|
||||
|
||||
return base64_encode($iv.mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv));
|
||||
$value = mcrypt_encrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
|
||||
|
||||
return base64_encode($iv.$value);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -67,20 +69,20 @@ class Crypter {
|
||||
{
|
||||
list($iv, $value) = static::parse(base64_decode($value, true));
|
||||
|
||||
return rtrim(mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv), "\0");
|
||||
$value = mcrypt_decrypt(static::$cipher, static::key(), $value, static::$mode, $iv);
|
||||
|
||||
return rtrim($value, "\0");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an encrypted value into the input vector and the actual value.
|
||||
*
|
||||
* If the given value is not valid base64 data, an exception will be thrown.
|
||||
*
|
||||
* @param string $value
|
||||
* @return array
|
||||
*/
|
||||
protected static function parse($value)
|
||||
{
|
||||
if ( ! is_string($value))
|
||||
if ($value === false)
|
||||
{
|
||||
throw new \Exception('Decryption error. Input value is not valid base64 data.');
|
||||
}
|
||||
|
@ -137,9 +137,9 @@ class Manager {
|
||||
/**
|
||||
* Write an item to the session flash data.
|
||||
*
|
||||
* Flash data only exists for the next request. After that, it will
|
||||
* be removed from the session. Flash data is useful for temporary
|
||||
* status or welcome messages.
|
||||
* Flash data only exists for the next request. After that, it will be
|
||||
* removed from the session. Flash data is useful for temporary status
|
||||
* or welcome messages.
|
||||
*
|
||||
* <code>
|
||||
* // Flash an item to the session
|
||||
@ -236,9 +236,6 @@ class Manager {
|
||||
{
|
||||
static::$session['last_activity'] = time();
|
||||
|
||||
// To age the data, we will forget all of the old keys and then
|
||||
// rewrite the newly flashed items to have old keys, which will
|
||||
// be available for the next request.
|
||||
foreach (static::$session['data'] as $key => $value)
|
||||
{
|
||||
if (strpos($key, ':old:') === 0) static::forget($key);
|
||||
|
@ -281,7 +281,7 @@ class Validator {
|
||||
*/
|
||||
protected function validate_size($attribute, $value, $parameters)
|
||||
{
|
||||
return $this->get_size($attribute, $value) == $parameters[0];
|
||||
return $this->size($attribute, $value) == $parameters[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -294,7 +294,7 @@ class Validator {
|
||||
*/
|
||||
protected function validate_between($attribute, $value, $parameters)
|
||||
{
|
||||
return $this->get_size($attribute, $value) >= $parameters[0] and $this->get_size($attribute, $value) <= $parameters[1];
|
||||
return $this->size($attribute, $value) >= $parameters[0] and $this->size($attribute, $value) <= $parameters[1];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -307,7 +307,7 @@ class Validator {
|
||||
*/
|
||||
protected function validate_min($attribute, $value, $parameters)
|
||||
{
|
||||
return $this->get_size($attribute, $value) >= $parameters[0];
|
||||
return $this->size($attribute, $value) >= $parameters[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,7 +320,7 @@ class Validator {
|
||||
*/
|
||||
protected function validate_max($attribute, $value, $parameters)
|
||||
{
|
||||
return $this->get_size($attribute, $value) <= $parameters[0];
|
||||
return $this->size($attribute, $value) <= $parameters[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -335,7 +335,7 @@ class Validator {
|
||||
* @param mixed $value
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_size($attribute, $value)
|
||||
protected function size($attribute, $value)
|
||||
{
|
||||
if (is_numeric($value) and $this->has_rule($attribute, $this->numeric_rules))
|
||||
{
|
||||
|
@ -133,10 +133,9 @@ class View {
|
||||
{
|
||||
if (is_null(static::$composers)) static::$composers = require APP_PATH.'composers'.EXT;
|
||||
|
||||
// The view's name may specified in several different ways in the
|
||||
// composers file. The composer may simple have a string value,
|
||||
// which is the name. Or, it may an array value in which a
|
||||
// "name" key exists.
|
||||
// The view's name may specified in several different ways in the composers
|
||||
// file. The composer may simple have a string value, which is the name.
|
||||
// Or, it may an array value in which a "name" key exists.
|
||||
foreach (static::$composers as $key => $value)
|
||||
{
|
||||
if ($name === $value or (is_array($value) and $name === Arr::get($value, 'name')))
|
||||
@ -174,10 +173,10 @@ class View {
|
||||
{
|
||||
static::compose($this);
|
||||
|
||||
// All nested views and responses are evaluated before the
|
||||
// main view. This allows the assets used by these views to
|
||||
// be added to the asset container before the main view is
|
||||
// evaluated and dumps the links to the assets.
|
||||
// All nested views and responses are evaluated before the main view.
|
||||
// This allows the assets used by the nested views to be added to the
|
||||
// asset container before the main view is evaluated and dumps the
|
||||
// links to the assets.
|
||||
foreach ($this->data as &$data)
|
||||
{
|
||||
if ($data instanceof View or $data instanceof Response)
|
||||
@ -188,9 +187,9 @@ class View {
|
||||
|
||||
ob_start() and extract($this->data, EXTR_SKIP);
|
||||
|
||||
// If the view is a "Blade" view, we need to check the view for
|
||||
// modifications and get the path to the compiled view file.
|
||||
// Otherwise, we'll just use the regular path to the view.
|
||||
// If the view is Bladed, we need to check the view for modifications
|
||||
// and get the path to the compiled view file. Otherwise, we'll just
|
||||
// use the regular path to the view.
|
||||
$view = (strpos($this->path, BLADE_EXT) !== false) ? $this->compile() : $this->path;
|
||||
|
||||
try { include $view; } catch (Exception $e) { ob_get_clean(); throw $e; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user