From 32989d39c86373a417369fa143ff73c79958f37e Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 22 Oct 2011 23:25:07 -0500 Subject: [PATCH] some small refactorings and cleanup. --- laravel/asset.php | 2 ++ laravel/blade.php | 21 +++------------ laravel/database/connection.php | 10 +++++--- laravel/paginator.php | 4 ++- laravel/routing/route.php | 44 +++++++++++++++++--------------- laravel/routing/router.php | 1 + laravel/session/manager.php | 4 ++- laravel/validation/validator.php | 2 -- laravel/view.php | 8 ++---- 9 files changed, 45 insertions(+), 51 deletions(-) diff --git a/laravel/asset.php b/laravel/asset.php index c58ec8a3..e06648f2 100644 --- a/laravel/asset.php +++ b/laravel/asset.php @@ -261,6 +261,7 @@ protected function evaluate_asset($asset, $value, $original, &$sorted, &$assets) if (count($assets[$asset]['dependencies']) == 0) { $sorted[$asset] = $value; + unset($assets[$asset]); } else @@ -270,6 +271,7 @@ protected function evaluate_asset($asset, $value, $original, &$sorted, &$assets) if ( ! $this->dependency_is_valid($asset, $dependency, $original, $assets)) { unset($assets[$asset]['dependencies'][$key]); + continue; } diff --git a/laravel/blade.php b/laravel/blade.php index f05a4ef0..13fc77d0 100644 --- a/laravel/blade.php +++ b/laravel/blade.php @@ -3,29 +3,16 @@ class Blade { /** - * Rewrites the specified file containing Blade pseudo-code into valid PHP. + * Compiles the specified file containing Blade pseudo-code into valid PHP. * * @param string $path * @return string */ - public static function parse($path) + public static function compile($path) { - return static::parse_string(file_get_contents($path)); - } + $value = file_get_contents($path); - /** - * Rewrites the specified string containing Blade pseudo-code into valid PHP. - * - * @param string $value - * @return string - */ - public static function parse_string($value) - { - $value = static::echos($value); - $value = static::openings($value); - $value = static::closings($value); - - return $value; + return static::closings(static::openings(static::echos($value))); } /** diff --git a/laravel/database/connection.php b/laravel/database/connection.php index 352e2992..8d8a106b 100644 --- a/laravel/database/connection.php +++ b/laravel/database/connection.php @@ -194,16 +194,18 @@ protected function execute(PDOStatement $statement, $bindings) { $result = $statement->execute($bindings); - if (strpos(strtoupper($statement->queryString), 'SELECT') === 0) + $sql = strtoupper($statement->queryString); + + if (strpos($sql, 'SELECT') === 0) { return $statement->fetchAll(PDO::FETCH_CLASS, 'stdClass'); } - elseif (strpos(strtoupper($statement->queryString), 'INSERT') === 0) + elseif (strpos($sql, 'UPDATE') === 0 or strpos($sql, 'DELETE') === 0) { - return $result; + return $statement->rowCount(); } - return $statement->rowCount(); + return $result; } /** diff --git a/laravel/paginator.php b/laravel/paginator.php index 2a6eede1..4de36915 100644 --- a/laravel/paginator.php +++ b/laravel/paginator.php @@ -252,7 +252,9 @@ protected function element($element, $text, $page, $disabler) // the current URI, this makes pretty good sense. list($uri, $secure) = array(Request::uri(), Request::secure()); - return HTML::link($uri.$this->appendage($element, $page), $text, array('class' => $class), $secure); + $appendage = $this->appendage($element, $page); + + return HTML::link($uri.$appendage, $text, array('class' => $class), $secure); } } diff --git a/laravel/routing/route.php b/laravel/routing/route.php index 47c106b5..0642d142 100644 --- a/laravel/routing/route.php +++ b/laravel/routing/route.php @@ -101,34 +101,38 @@ public function call() // 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))) - { - return $response; - } + $response = Filter::run($before, array(), true); - if ( ! is_null($response = $this->response())) + if (is_null($response) and ! is_null($response = $this->response())) { if ($response instanceof Delegate) { $response = Controller::call($response->destination, $this->parameters); } - - // 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; } - return Response::error('404'); + // If we still don't have a response, we're out of options and + // will use the 404 response. We will still let the response + // hit the after filter in case the developer is doing any + // logging or other work where every response is needed. + if (is_null($response)) + { + $response = Response::error('404'); + } + + // 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; } /** diff --git a/laravel/routing/router.php b/laravel/routing/router.php index 5b65944b..85de9d14 100644 --- a/laravel/routing/router.php +++ b/laravel/routing/router.php @@ -153,6 +153,7 @@ protected function match($destination, $keys, $callback) foreach (explode(', ', $keys) as $key) { // Append the provided formats to the route as an optional regular expression. + // This should make the route look something like: "user(\.(json|xml|html))?" if ( ! is_null($formats = $this->provides($callback))) { $key .= '(\.('.implode('|', $formats).'))?'; diff --git a/laravel/session/manager.php b/laravel/session/manager.php index 5c02f65a..dfa60793 100644 --- a/laravel/session/manager.php +++ b/laravel/session/manager.php @@ -278,7 +278,9 @@ public static function close() // driver must do its garbage collection manually. Alternatively, some // drivers such as APC and Memcached are not required to manually // clean up their sessions. - if (mt_rand(1, $config['sweepage'][1]) <= $config['sweepage'][0] and static::$driver instanceof Drivers\Sweeper) + $sweep = (mt_rand(1, $config['sweepage'][1]) <= $config['sweepage'][0]); + + if ($sweep and static::$driver instanceof Drivers\Sweeper) { static::$driver->sweep(time() - ($config['lifetime'] * 60)); } diff --git a/laravel/validation/validator.php b/laravel/validation/validator.php index 812eb2d7..ce8aa5ed 100644 --- a/laravel/validation/validator.php +++ b/laravel/validation/validator.php @@ -163,8 +163,6 @@ protected function check($attribute, $rule) { list($rule, $parameters) = $this->parse($rule); - // Verify that the attribute and rule combination is actually - // validatable before attempting to call the validation rule. $value = Arr::get($this->attributes, $attribute); if ( ! $this->validatable($rule, $attribute, $value)) return; diff --git a/laravel/view.php b/laravel/view.php index 4ec7cdf7..6497e49d 100644 --- a/laravel/view.php +++ b/laravel/view.php @@ -123,8 +123,7 @@ public static function of($name, $data = array()) /** * Find the key for a view by name. * - * The view's key can be used to create instances of the view through the typical - * methods available on the view factory. + * The view "key" is the string that should be passed into the "make" method. * * @param string $name * @return string @@ -133,9 +132,6 @@ protected static function name($name) { 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. foreach (static::$composers as $key => $value) { if ($name === $value or (is_array($value) and $name === Arr::get($value, 'name'))) @@ -215,7 +211,7 @@ protected function compile() // without re-compiling. if ((file_exists($compiled) and filemtime($this->path) > filemtime($compiled)) or ! file_exists($compiled)) { - file_put_contents($compiled, Blade::parse($this->path)); + file_put_contents($compiled, Blade::compile($this->path)); } return $compiled;