Skip to content
This repository has been archived by the owner on Sep 19, 2022. It is now read-only.

Commit

Permalink
Making middleware optionally arrays and updated comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yaworsw committed Apr 4, 2014
1 parent 18a9d23 commit f2cd7b0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
22 changes: 0 additions & 22 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -112,28 +112,6 @@ Minimal bootstrap file for this example

## Configuration

### RESTful Routing

You can define the http method that routes use by adding it to the beginning of the route and separating the http method and the path by a space (or any whitespace char(s) [space, tab, newline]).

$app->addRoutes(array(
'/' => 'Home:index',
'get /posts' => 'Posts:index',
'get /posts/:id' => 'Posts:show',
'post /posts' => 'Posts:create'
));

Leading spaces in routes are ignored and all spaces in between the http method and the route are ignored so that you can have sexy indenting like this:

$app->addRoutes(array(
' /' => 'Home:index',
'get /posts' => 'Posts:index',
'get /posts/:id' => 'Posts:show',
'post /posts' => 'Posts:create'
));

If you don't specify an http method then that route will work with any http method.

### controller.class_prefix

Optional class prefix for controller classes. Will be prepended to routes.
Expand Down
4 changes: 2 additions & 2 deletions src/SlimController/Slim.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ class Slim extends \Slim\Slim
* With explicit HTTP method
* <code>
* $app->addRoutes(array(
* '/some/path' => array('className:methodName', 'get')
* '/some/path' => array('get' => 'className:methodName')
* ));
* </code>
*
* With local middleware
* <code>
* $app->addRoutes(array(
* '/some/path' => array('className:methodName', 'get', function() {})
* '/some/path' => array('get' => 'className:methodName', function() {})
* '/other/path' => array('className:methodName', function() {})
* ));
* </code>
Expand Down
23 changes: 22 additions & 1 deletion tests/SlimController/Tests/SlimTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testAddRoutesWithVariables()
$this->assertEquals(1, count($this->app->router()->getMatchedRoutes($this->req->getMethod(), $this->req->getResourceUri())));
}

public function testAddRoutesInRestFormat()
public function testAddRoutesInExtendedFormat()
{
$this->setUrl('/bla');
$this->app->addRoutes(array(
Expand Down Expand Up @@ -76,6 +76,27 @@ public function testGlobalMiddlewareIsAddedToRoute()
$this->assertSame(1, count($middleware));
}

public function testGlobalMiddlewareIsAddedToRouteAsArray()
{
$middlewares = array(
function() { return false; },
function() { return false; }
);

$this->setUrl('/bla');
$this->app->addRoutes(array(
'/bla' => 'Controller:index'
), $middlewares);

/** @var \Slim\Route[] $routes */
$routes = $this->app->router()->getMatchedRoutes($this->req->getMethod(), $this->req->getResourceUri());
$this->assertEquals(1, count($routes));

$middleware = $routes[0]->getMiddleware();
$this->assertInternalType('array', $middleware);
$this->assertSame(2, count($middleware));
}

public function testLocalMiddlewareIsAddedToRoute()
{
$this->setUrl('/bla');
Expand Down

0 comments on commit f2cd7b0

Please sign in to comment.