Skip to content

Commit

Permalink
Merge f957107 into 394732e
Browse files Browse the repository at this point in the history
  • Loading branch information
codeguy committed Dec 17, 2016
2 parents 394732e + f957107 commit fe32a2b
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 231 deletions.
356 changes: 269 additions & 87 deletions Slim/App.php

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions Slim/Interfaces/RouterInterface.php
Expand Up @@ -104,4 +104,11 @@ public function relativePathFor($name, array $data = [], array $queryParams = []
* @throws InvalidArgumentException If required data not provided
*/
public function pathFor($name, array $data = [], array $queryParams = []);

/**
* Set default route invocation strategy
*
* @param InvocationStrategyInterface $strategy
*/
public function setDefaultInvocationStrategy(InvocationStrategyInterface $strategy);
}
21 changes: 0 additions & 21 deletions Slim/Routable.php
Expand Up @@ -8,7 +8,6 @@
*/
namespace Slim;

use Interop\Container\ContainerInterface;
use Slim\Interfaces\CallableResolverInterface;

/**
Expand All @@ -31,13 +30,6 @@ abstract class Routable
*/
protected $callableResolver;

/**
* Container
*
* @var ContainerInterface
*/
protected $container;

/**
* Route middleware
*
Expand Down Expand Up @@ -92,19 +84,6 @@ public function getCallableResolver()
return $this->callableResolver;
}

/**
* Set container for use with resolveCallable
*
* @param ContainerInterface $container
*
* @return self
*/
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
return $this;
}

/**
* Prepend middleware to the middleware collection
*
Expand Down
30 changes: 27 additions & 3 deletions Slim/Route.php
Expand Up @@ -9,12 +9,10 @@
namespace Slim;

use Exception;
use Slim\Interfaces\CallableResolverInterface;
use Throwable;
use InvalidArgumentException;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Exception\SlimException;
use Slim\Handlers\Strategies\RequestResponse;
use Slim\Interfaces\InvocationStrategyInterface;
use Slim\Interfaces\RouteInterface;
Expand Down Expand Up @@ -65,6 +63,11 @@ class Route extends Routable implements RouteInterface
*/
protected $outputBuffering = 'append';

/**
* @var \Slim\Interfaces\InvocationStrategyInterface
*/
protected $routeInvocationStrategy;

/**
* Route parameters
*
Expand All @@ -88,6 +91,27 @@ public function __construct($methods, $pattern, $callable, $groups = [], $identi
$this->callable = $callable;
$this->groups = $groups;
$this->identifier = 'route' . $identifier;
$this->routeInvocationStrategy = new RequestResponse();
}

/**
* Set route invocation strategy
*
* @param InvocationStrategyInterface $strategy
*/
public function setInvocationStrategy(InvocationStrategyInterface $strategy)
{
$this->routeInvocationStrategy = $strategy;
}

/**
* Get route invocation strategy
*
* @return InvocationStrategyInterface
*/
public function getInvocationStrategy()
{
return $this->routeInvocationStrategy;
}

/**
Expand Down Expand Up @@ -331,7 +355,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
}

/** @var InvocationStrategyInterface $handler */
$handler = isset($this->container) ? $this->container->get('foundHandler') : new RequestResponse();
$handler = $this->routeInvocationStrategy;

// invoke route callable
if ($this->outputBuffering === false) {
Expand Down
46 changes: 28 additions & 18 deletions Slim/Router.php
Expand Up @@ -9,14 +9,14 @@
namespace Slim;

use FastRoute\Dispatcher;
use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use RuntimeException;
use Psr\Http\Message\ServerRequestInterface;
use FastRoute\RouteCollector;
use FastRoute\RouteParser;
use FastRoute\RouteParser\Std as StdParser;
use Slim\Interfaces\CallableResolverInterface;
use Slim\Interfaces\InvocationStrategyInterface;
use Slim\Interfaces\RouteGroupInterface;
use Slim\Interfaces\RouterInterface;
use Slim\Interfaces\RouteInterface;
Expand All @@ -31,13 +31,6 @@
*/
class Router implements RouterInterface
{
/**
* Container Interface
*
* @var ContainerInterface
*/
protected $container;

/**
* Parser
*
Expand All @@ -52,6 +45,11 @@ class Router implements RouterInterface
*/
protected $callableResolver;

/**
* @var \Slim\Interfaces\InvocationStrategyInterface
*/
protected $routeInvocationStrategy;

/**
* Base path used in pathFor()
*
Expand Down Expand Up @@ -101,6 +99,26 @@ public function __construct(RouteParser $parser = null)
$this->routeParser = $parser ?: new StdParser;
}

/**
* Set default route invocation strategy
*
* @param InvocationStrategyInterface $strategy
*/
public function setDefaultInvocationStrategy(InvocationStrategyInterface $strategy)
{
$this->routeInvocationStrategy = $strategy;
}

/**
* Get default route invocation strategy
*
* @return InvocationStrategyInterface|null
*/
public function getDefaultInvocationStrategy()
{
return $this->routeInvocationStrategy;
}

/**
* Set the base path used in pathFor()
*
Expand Down Expand Up @@ -152,14 +170,6 @@ public function setCallableResolver(CallableResolverInterface $resolver)
$this->callableResolver = $resolver;
}

/**
* @param ContainerInterface $container
*/
public function setContainer(ContainerInterface $container)
{
$this->container = $container;
}

/**
* Add route
*
Expand Down Expand Up @@ -227,8 +237,8 @@ protected function createRoute($methods, $pattern, $callable)
if ($this->callableResolver) {
$route->setCallableResolver($this->callableResolver);
}
if ($this->container) {
$route->setContainer($this->container);
if ($this->routeInvocationStrategy) {
$route->setInvocationStrategy($this->routeInvocationStrategy);
}

return $route;
Expand Down
4 changes: 3 additions & 1 deletion UPGRADING.md
@@ -1,5 +1,7 @@
# How to upgrade

* [2098] - You need to add the App's router to the container for a straight upgrade. If you've created your own router factory in the container though, then you need to set it into the $app.
* [2102] - You must inject custom route invocation strategy with `$app->getRouter()->setDefaultInvocationStrategy($myStrategy)`

[2098]: 92612999931799571752400592
[2098]: https://github.com/slimphp/Slim/pull/2098
[2102]: https://github.com/slimphp/Slim/pull/2102

0 comments on commit fe32a2b

Please sign in to comment.