Skip to content

Commit

Permalink
Merge branch 'release-1.6.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Lockhart committed Jun 24, 2012
2 parents 5606b17 + 5b4f658 commit 29d662d
Show file tree
Hide file tree
Showing 38 changed files with 341 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Slim/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Exception/Pass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Exception/RequestSlash.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Exception/Stop.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Http/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/ContentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/Flash.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/MethodOverride.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/PrettyExceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
2 changes: 1 addition & 1 deletion Slim/Middleware/SessionCookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
60 changes: 47 additions & 13 deletions Slim/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand All @@ -32,19 +32,19 @@
*/

/**
* Route
* Slim_Route
* @package Slim
* @author Josh Lockhart
* @since 1.0.0
*/
class Slim_Route {
/**
* @var string The route pattern (ie. "/books/:id")
* @var string The route pattern (e.g. "/books/:id")
*/
protected $pattern;

/**
* @var mixed The callable associated with this route
* @var mixed The route callable
*/
protected $callable;

Expand All @@ -54,7 +54,7 @@ class Slim_Route {
protected $conditions = array();

/**
* @var array Default conditions applied to all Route instances
* @var array Default conditions applied to all route instances
*/
protected static $defaultConditions = array();

Expand All @@ -79,13 +79,13 @@ class Slim_Route {
protected $router;

/**
* @var array[Callable] Middleware
* @var array[Callable] Middleware to be run before only this route instance
*/
protected $middleware = array();

/**
* Constructor
* @param string $pattern The URL pattern (ie. "/books/:id")
* @param string $pattern The URL pattern (e.g. "/books/:id")
* @param mixed $callable Anything that returns TRUE for is_callable()
*/
public function __construct( $pattern, $callable ) {
Expand Down Expand Up @@ -141,7 +141,7 @@ public function getCallable() {
* @param mixed $callable
* @return void
*/
public function setCallable($callable) {
public function setCallable( $callable ) {
$this->callable = $callable;
}

Expand Down Expand Up @@ -188,6 +188,41 @@ public function getParams() {
return $this->params;
}

/**
* Set route parameters
* @param array $params
* @return void
*/
public function setParams( $params ) {
$this->params = $params;
}

/**
* Get route parameter value
* @param string $index Name of URL parameter
* @return string
* @throws InvalidArgumentException If route parameter does not exist at index
*/
public function getParam( $index ) {
if ( !isset($this->params[$index]) ) {
throw new InvalidArgumentException('Route parameter does not exist at specified index');
}
return $this->params[$index];
}

/**
* Set route parameter value
* @param string $index Name of URL parameter
* @param mixed $value The new parameter value
* @throws InvalidArgumentException If route parameter does not exist at index
*/
public function setParam( $index, $value ) {
if ( !isset($this->params[$index]) ) {
throw new InvalidArgumentException('Route parameter does not exist at specified index');
}
$this->params[$index] = $value;
}

/**
* Add supported HTTP method(s)
* @return void
Expand Down Expand Up @@ -316,13 +351,12 @@ public function matches( $resourceUri ) {
}
}
return true;
} else {
return false;
}
return false;
}

/**
* Convert a URL parameter (ie. ":id") into a regular expression
* Convert a URL parameter (e.g. ":id") into a regular expression
* @param array URL parameters
* @return string Regular expression for URL parameter
*/
Expand Down Expand Up @@ -368,7 +402,7 @@ public function conditions( array $conditions ) {
* matches this route's pattern, a Slim_Exception_RequestSlash
* will be thrown triggering an HTTP 301 Permanent Redirect to the same
* URI _with_ a trailing slash. This Exception is caught in the
* `Slim::run` loop. If this route's pattern is defined without a
* `Slim::call` loop. If this route's pattern is defined without a
* trailing slash, and if the current request URI does have a trailing
* slash, this route will not be matched and a 404 Not Found
* response will be sent if no subsequent matching routes are found.
Expand All @@ -391,7 +425,7 @@ public function dispatch() {
}

//Invoke callable
if ( is_callable($this->getCallable()) ) {
if ( is_callable($this->callable) ) {
call_user_func_array($this->callable, array_values($this->params));
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion Slim/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -110,6 +110,7 @@ public function getResponse() {
* @return Slim_Route|false
*/
public function getCurrentRoute() {
$this->getMatchedRoutes(); // <-- Parse if not already parsed
return $this->current();
}

Expand Down
7 changes: 3 additions & 4 deletions Slim/Slim.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down Expand Up @@ -1159,11 +1159,10 @@ public function call() {
$this->response['Allow'] = implode(' ', $httpMethodsAllowed);
$this->halt(405, 'HTTP method not allowed for the requested resource. Use one of these instead: ' . implode(', ', $httpMethodsAllowed)); } else { $this->notFound(); } }
$this->applyHook('slim.after.router');
$this->response->write(ob_get_clean());
$this->applyHook('slim.after');
$this->stop();
} catch ( Slim_Exception_Stop $e ) {
$this->response()->write(ob_get_contents());
$this->response()->write(ob_get_clean());
$this->applyHook('slim.after');
} catch ( Slim_Exception_RequestSlash $e ) {
$this->response->redirect($this->request->getPath() . '/', 301);
} catch ( Exception $e ) {
Expand Down
2 changes: 1 addition & 1 deletion Slim/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
* @package Slim
*
* MIT LICENSE
Expand Down
17 changes: 15 additions & 2 deletions docs/routing-middleware.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,22 @@ If you are running PHP >= 5.3, you can get a bit more creative. Suppose you want
Slim::flash('error', 'Login required');
Slim::redirect('/login');
}
}
}
};
};
$app = new Slim();
$app->get('/foo', $authenticateForRole('admin'), function () {
//Display admin control panel
});

## Are there any parameters passed to the Route Middleware callable?

Yes. The middleware callable is called with three parameters, `Slim_Http_Request`, `Slim_Http_Response` and the currently matched `Slim_Route`.

$aBitOfInfo = function ($request, $response, $route) {
$response->write(sprintf("We got %d GET/POST parameter(s)", count($request->params())));
echo "Current route is " . $route->getName();
};

$app->get('/foo', $aBitOfInfo, function () {
echo "foo";
});
2 changes: 1 addition & 1 deletion tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
*
* MIT LICENSE
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/HeadersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
*
* MIT LICENSE
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
*
* MIT LICENSE
*
Expand Down
2 changes: 1 addition & 1 deletion tests/Http/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @copyright 2011 Josh Lockhart
* @link http://www.slimframework.com
* @license http://www.slimframework.com/license
* @version 1.6.3
* @version 1.6.4
*
* MIT LICENSE
*
Expand Down
Loading

0 comments on commit 29d662d

Please sign in to comment.