Skip to content

Commit 7b13168

Browse files
committed
Merge conflicts
2 parents b9d8326 + 385c5a0 commit 7b13168

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1939
-1471
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ php:
55
- 5.5
66
- 5.6
77
- 7.0
8-
- hhvm
98

109
matrix:
1110
fast_finish: true
@@ -26,5 +25,5 @@ script:
2625
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
2726

2827
after_success:
29-
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
30-
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
28+
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
29+
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
All Notable changes to `League\Route` will be documented in this file
44

5+
## 2.0.0 - 2016-02
6+
7+
### Added
8+
- All routing and dispatching now built around PSR-7.
9+
- Can now group routes with prefix and match conditions.
10+
- Routes now stored against a specific `Route` object that describes the route.
11+
- New `dispatch` method on `RouteCollection` that is a compliant PSR-7 middleware.
12+
- Additional route matching conditions for scheme and host.
13+
14+
## Changed
15+
- API rewrite to simplify.
16+
- API naming improvements.
17+
- Strategies now less opinionated about return from controller.
18+
519
## 1.2.0 - 2015-08-24
620

721
### Added

README.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/882acb6c-3001-4313-857d-6f7200f5ab90/big.png)](https://insight.sensiolabs.com/projects/882acb6c-3001-4313-857d-6f7200f5ab90)
1212

13-
This package is compliant with [PSR-1], [PSR-2] and [PSR-4]. If you notice compliance oversights,
13+
This package is compliant with [PSR-1], [PSR-2], [PSR-4] and [PSR-7]. If you notice compliance oversights,
1414
please send a patch via pull request.
1515

1616
[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md
1717
[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
1818
[PSR-4]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
19+
[PSR-7]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md
1920

2021
## Install
2122

@@ -32,18 +33,14 @@ The following versions of PHP are supported by this version.
3233
* PHP 5.4
3334
* PHP 5.5
3435
* PHP 5.6
35-
* HHVM
36+
* PHP 7
3637

3738
## Documentation
3839

3940
Route has [full documentation](http://route.thephpleague.com), powered by [Jekyll](http://jekyllrb.com/).
4041

4142
Contribute to this documentation in the [gh-pages branch](https://github.com/thephpleague/route/tree/gh-pages/).
4243

43-
## Todo
44-
45-
- Add knowledge of variadic uri wildcard arguments to `MethodArgumentStrategy`. (Blocked by changes to Container).
46-
4744
## Testing
4845

4946
``` bash
@@ -56,8 +53,8 @@ Please see [CONTRIBUTING](https://github.com/thephpleague/route/blob/master/CONT
5653

5754
## Credits
5855

59-
- [Nikita Popov](https://github.com/nikic)
6056
- [Phil Bennett](https://github.com/philipobenito)
57+
- [Nikita Popov](https://github.com/nikic) (FastRoute)
6158
- [All Contributors](https://github.com/thephpleague/route/contributors)
6259

6360
All `Orno\Route` contributions can be found [here](https://github.com/orno/route/graphs/contributors).

composer.json

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
"description": "A fast routing and dispatch package built on top of FastRoute.",
44
"keywords": [
55
"league",
6-
"route"
6+
"route",
7+
"dispatcher",
8+
"psr-7",
9+
"psr7"
710
],
811
"homepage": "https://github.com/thephpleague/route",
912
"license": "MIT",
1013
"authors": [
1114
{
1215
"name": "Phil Bennett",
1316
"email": "philipobenito@gmail.com",
14-
"homepage": "http://philipobenito.github.io",
17+
"homepage": "http://www.philipobenito.com",
1518
"role": "Developer"
1619
}
1720
],
1821
"require": {
19-
"php" : ">=5.4.0",
20-
"league/container": "~1.0",
21-
"nikic/fast-route": "~0.3",
22-
"symfony/http-foundation": "~2.6"
22+
"php": ">=5.4.0",
23+
"league/container": "^2.0",
24+
"nikic/fast-route": "^0.7",
25+
"psr/http-message": "^1.0"
2326
},
2427
"require-dev": {
25-
"phpunit/phpunit" : "4.*"
28+
"phpunit/phpunit" : "^4.0"
2629
},
2730
"replace": {
2831
"orno/route": "~1.0",
@@ -36,11 +39,13 @@
3639
"autoload-dev": {
3740
"psr-4": {
3841
"League\\Route\\Test\\": "tests"
39-
}
42+
},
43+
"files": ["tests/Asset/functions.php"]
4044
},
4145
"extra": {
4246
"branch-alias": {
43-
"dev-master": "1.0-dev"
47+
"dev-master": "2.x-dev",
48+
"1.x": "1.x-dev"
4449
}
4550
}
4651
}

src/Dispatcher.php

Lines changed: 53 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -2,144 +2,102 @@
22

33
namespace League\Route;
44

5-
use Closure;
65
use FastRoute\Dispatcher as FastRoute;
76
use FastRoute\Dispatcher\GroupCountBased as GroupCountBasedDispatcher;
8-
use League\Container\ContainerAwareInterface;
9-
use League\Container\ContainerInterface;
107
use League\Route\Http\Exception\MethodNotAllowedException;
118
use League\Route\Http\Exception\NotFoundException;
12-
use League\Route\Strategy\RestfulStrategy;
13-
use League\Route\Strategy\StrategyInterface;
14-
use League\Route\Strategy\StrategyTrait;
15-
use RuntimeException;
9+
use League\Route\Strategy\JsonStrategy;
10+
use League\Route\Strategy\StrategyAwareInterface;
11+
use League\Route\Strategy\StrategyAwareTrait;
12+
use Psr\Http\Message\ResponseInterface;
13+
use Psr\Http\Message\ServerRequestInterface;
1614

17-
class Dispatcher extends GroupCountBasedDispatcher
15+
class Dispatcher extends GroupCountBasedDispatcher implements StrategyAwareInterface
1816
{
19-
/**
20-
* Route strategy functionality
21-
*/
22-
use StrategyTrait;
23-
24-
/**
25-
* @var \League\Container\ContainerInterface
26-
*/
27-
protected $container;
28-
29-
/**
30-
* @var array
31-
*/
32-
protected $routes;
17+
use StrategyAwareTrait;
3318

3419
/**
35-
* Constructor
20+
* Match and dispatch a route matching the given http method and uri.
3621
*
37-
* @param \League\Container\ContainerInterface $container
38-
* @param array $routes
39-
* @param array $data
40-
*/
41-
public function __construct(ContainerInterface $container, array $routes, array $data)
42-
{
43-
$this->container = $container;
44-
$this->routes = $routes;
45-
46-
parent::__construct($data);
47-
}
48-
49-
/**
50-
* Match and dispatch a route matching the given http method and uri
22+
* @param \Psr\Http\Message\ServerRequestInterface $request
23+
* @param \Psr\Http\Message\ResponseInterface $response
5124
*
52-
* @param string $method
53-
* @param string $uri
54-
* @return \Symfony\Component\HttpFoundation\Response
25+
* @return \Psr\Http\Message\ResponseInterface
5526
*/
56-
public function dispatch($method, $uri)
27+
public function handle(ServerRequestInterface $request, ResponseInterface $response)
5728
{
58-
$match = parent::dispatch($method, $uri);
29+
$match = $this->dispatch(
30+
$request->getMethod(),
31+
$request->getUri()->getPath()
32+
);
5933

6034
if ($match[0] === FastRoute::NOT_FOUND) {
61-
return $this->handleNotFound();
35+
return $this->handleNotFound($response);
6236
}
6337

6438
if ($match[0] === FastRoute::METHOD_NOT_ALLOWED) {
65-
$allowed = (array) $match[1];
66-
return $this->handleNotAllowed($allowed);
39+
$allowed = (array) $match[1];
40+
return $this->handleNotAllowed($response, $allowed);
6741
}
6842

69-
$handler = (isset($this->routes[$match[1]]['callback'])) ? $this->routes[$match[1]]['callback'] : $match[1];
70-
$strategy = $this->routes[$match[1]]['strategy'];
71-
$vars = (array) $match[2];
72-
73-
return $this->handleFound($handler, $strategy, $vars);
43+
return $this->handleFound($match[1], $request, $response, (array) $match[2]);
7444
}
7545

7646
/**
77-
* Handle dispatching of a found route
47+
* Handle dispatching of a found route.
48+
*
49+
* @param callable $route
50+
* @param \Psr\Http\Message\ServerRequestInterface $request
51+
* @param \Psr\Http\Message\ResponseInterface $response
52+
* @param array $vars
7853
*
79-
* @param string|\Closure $handler
80-
* @param \League\Route\Strategy\StrategyInterface $strategy
81-
* @param array $vars
82-
* @return \Symfony\Component\HttpFoundation\Response
83-
* @throws \RuntimeException
54+
* @return \Psr\Http\Message\ResponseInterface
8455
*/
85-
protected function handleFound($handler, StrategyInterface $strategy, array $vars)
86-
{
87-
if (is_null($this->getStrategy())) {
88-
$this->setStrategy($strategy);
89-
}
90-
91-
$controller = null;
92-
93-
// figure out what the controller is
94-
if (($handler instanceof Closure) || is_callable($handler)) {
95-
$controller = $handler;
96-
}
97-
98-
if (is_string($handler) && strpos($handler, '::') !== false) {
99-
$controller = explode('::', $handler);
100-
}
101-
102-
// if controller method wasn't specified, throw exception.
103-
if (! $controller) {
104-
throw new RuntimeException('A class method must be provided as a controller. ClassName::methodName');
105-
}
106-
107-
// dispatch via strategy
108-
if ($strategy instanceof ContainerAwareInterface) {
109-
$strategy->setContainer($this->container);
110-
}
111-
112-
return $strategy->dispatch($controller, $vars);
56+
protected function handleFound(
57+
callable $route,
58+
ServerRequestInterface $request,
59+
ResponseInterface $response,
60+
array $vars
61+
) {
62+
return call_user_func_array($route, [$request, $response, $vars]);
11363
}
11464

11565
/**
116-
* Handle a not found route
66+
* Handle a not found route.
11767
*
118-
* @return \Symfony\Component\HttpFoundation\Response
68+
* @param \Psr\Http\Message\ResponseInterface $response
69+
*
70+
* @throws \League\Route\Http\Exception\NotFoundException if a response cannot be built
71+
*
72+
* @return \Psr\Http\Message\ResponseInterface
11973
*/
120-
protected function handleNotFound()
74+
protected function handleNotFound(ResponseInterface $response)
12175
{
12276
$exception = new NotFoundException;
12377

124-
if ($this->getStrategy() instanceof RestfulStrategy) {
125-
return $exception->getJsonResponse();
78+
if ($this->getStrategy() instanceof JsonStrategy) {
79+
return $exception->buildJsonResponse($response);
12680
}
12781

12882
throw $exception;
12983
}
13084

13185
/**
132-
* Handles a not allowed route
86+
* Handles a not allowed route.
87+
*
88+
* @param \Psr\Http\Message\ResponseInterface $response
89+
* @param array $allowed
90+
*
91+
* @throws \League\Route\Http\Exception\MethodNotAllowedException if a response cannot be built
13392
*
134-
* @param array $allowed
135-
* @return \Symfony\Component\HttpFoundation\Response
93+
* @return \Psr\Http\Message\ResponseInterface
13694
*/
137-
protected function handleNotAllowed(array $allowed)
95+
protected function handleNotAllowed(ResponseInterface $response, array $allowed)
13896
{
13997
$exception = new MethodNotAllowedException($allowed);
14098

141-
if ($this->getStrategy() instanceof RestfulStrategy) {
142-
return $exception->getJsonResponse();
99+
if ($this->getStrategy() instanceof JsonStrategy) {
100+
return $exception->buildJsonResponse($response);
143101
}
144102

145103
throw $exception;

0 commit comments

Comments
 (0)