Commit 32989d39 by Taylor Otwell

some small refactorings and cleanup.

parent b71ecb43
...@@ -261,6 +261,7 @@ class Asset_Container { ...@@ -261,6 +261,7 @@ class Asset_Container {
if (count($assets[$asset]['dependencies']) == 0) if (count($assets[$asset]['dependencies']) == 0)
{ {
$sorted[$asset] = $value; $sorted[$asset] = $value;
unset($assets[$asset]); unset($assets[$asset]);
} }
else else
...@@ -270,6 +271,7 @@ class Asset_Container { ...@@ -270,6 +271,7 @@ class Asset_Container {
if ( ! $this->dependency_is_valid($asset, $dependency, $original, $assets)) if ( ! $this->dependency_is_valid($asset, $dependency, $original, $assets))
{ {
unset($assets[$asset]['dependencies'][$key]); unset($assets[$asset]['dependencies'][$key]);
continue; continue;
} }
......
...@@ -3,29 +3,16 @@ ...@@ -3,29 +3,16 @@
class Blade { 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 * @param string $path
* @return string * @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);
}
/** return static::closings(static::openings(static::echos($value)));
* 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;
} }
/** /**
......
...@@ -194,16 +194,18 @@ class Connection { ...@@ -194,16 +194,18 @@ class Connection {
{ {
$result = $statement->execute($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'); 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;
} }
/** /**
......
...@@ -252,7 +252,9 @@ class Paginator { ...@@ -252,7 +252,9 @@ class Paginator {
// the current URI, this makes pretty good sense. // the current URI, this makes pretty good sense.
list($uri, $secure) = array(Request::uri(), Request::secure()); 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);
} }
} }
......
...@@ -101,17 +101,24 @@ class Route { ...@@ -101,17 +101,24 @@ class Route {
// a controller, the controller will only call its own filters. // a controller, the controller will only call its own filters.
$before = array_merge(array('before'), $this->filters('before')); $before = array_merge(array('before'), $this->filters('before'));
if ( ! is_null($response = Filter::run($before, array(), true))) $response = Filter::run($before, array(), true);
{
return $response;
}
if ( ! is_null($response = $this->response())) if (is_null($response) and ! is_null($response = $this->response()))
{ {
if ($response instanceof Delegate) if ($response instanceof Delegate)
{ {
$response = Controller::call($response->destination, $this->parameters); $response = Controller::call($response->destination, $this->parameters);
} }
}
// 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 // 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 route did not
...@@ -128,9 +135,6 @@ class Route { ...@@ -128,9 +135,6 @@ class Route {
return $response; return $response;
} }
return Response::error('404');
}
/** /**
* Call the closure defined for the route, or get the route delegator. * Call the closure defined for the route, or get the route delegator.
* *
......
...@@ -153,6 +153,7 @@ class Router { ...@@ -153,6 +153,7 @@ class Router {
foreach (explode(', ', $keys) as $key) foreach (explode(', ', $keys) as $key)
{ {
// Append the provided formats to the route as an optional regular expression. // 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))) if ( ! is_null($formats = $this->provides($callback)))
{ {
$key .= '(\.('.implode('|', $formats).'))?'; $key .= '(\.('.implode('|', $formats).'))?';
......
...@@ -278,7 +278,9 @@ class Manager { ...@@ -278,7 +278,9 @@ class Manager {
// driver must do its garbage collection manually. Alternatively, some // driver must do its garbage collection manually. Alternatively, some
// drivers such as APC and Memcached are not required to manually // drivers such as APC and Memcached are not required to manually
// clean up their sessions. // 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)); static::$driver->sweep(time() - ($config['lifetime'] * 60));
} }
......
...@@ -163,8 +163,6 @@ class Validator { ...@@ -163,8 +163,6 @@ class Validator {
{ {
list($rule, $parameters) = $this->parse($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); $value = Arr::get($this->attributes, $attribute);
if ( ! $this->validatable($rule, $attribute, $value)) return; if ( ! $this->validatable($rule, $attribute, $value)) return;
......
...@@ -123,8 +123,7 @@ class View { ...@@ -123,8 +123,7 @@ class View {
/** /**
* Find the key for a view by name. * Find the key for a view by name.
* *
* The view's key can be used to create instances of the view through the typical * The view "key" is the string that should be passed into the "make" method.
* methods available on the view factory.
* *
* @param string $name * @param string $name
* @return string * @return string
...@@ -133,9 +132,6 @@ class View { ...@@ -133,9 +132,6 @@ class View {
{ {
if (is_null(static::$composers)) static::$composers = require APP_PATH.'composers'.EXT; 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) foreach (static::$composers as $key => $value)
{ {
if ($name === $value or (is_array($value) and $name === Arr::get($value, 'name'))) if ($name === $value or (is_array($value) and $name === Arr::get($value, 'name')))
...@@ -215,7 +211,7 @@ class View { ...@@ -215,7 +211,7 @@ class View {
// without re-compiling. // without re-compiling.
if ((file_exists($compiled) and filemtime($this->path) > filemtime($compiled)) or ! file_exists($compiled)) 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; return $compiled;
......
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