Skip to content

Commit 90cce9a

Browse files
authored
Merge pull request #76 from sunrise-php/release/v2.10.1
v2.10.1
2 parents 612067e + 3b6a526 commit 90cce9a

File tree

65 files changed

+436
-446
lines changed

Some content is hidden

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

65 files changed

+436
-446
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,39 @@ jobs:
1111
- checkout
1212
- run: php -v
1313
- run: composer install --no-interaction --no-suggest --prefer-source
14-
- run: php vendor/bin/phpunit --colors=always
14+
- run: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text
1515
php72:
1616
docker:
1717
- image: circleci/php:7.2-cli-node-browsers
1818
steps:
1919
- checkout
2020
- run: php -v
2121
- run: composer install --no-interaction --no-suggest --prefer-source
22-
- run: php vendor/bin/phpunit --colors=always
22+
- run: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text
2323
php73:
2424
docker:
2525
- image: circleci/php:7.3-cli-node-browsers
2626
steps:
2727
- checkout
2828
- run: php -v
2929
- run: composer install --no-interaction --no-suggest --prefer-source
30-
- run: php vendor/bin/phpunit --colors=always
30+
- run: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text
3131
php74:
3232
docker:
3333
- image: circleci/php:7.4-cli-node-browsers
3434
steps:
3535
- checkout
3636
- run: php -v
3737
- run: composer install --no-interaction --no-suggest --prefer-source
38-
- run: php vendor/bin/phpunit --colors=always
38+
- run: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text
3939
php80:
4040
docker:
4141
- image: circleci/php:8.0-cli-node-browsers
4242
steps:
4343
- checkout
4444
- run: php -v
4545
- run: composer install --no-interaction --no-suggest --prefer-source
46-
- run: php vendor/bin/phpunit --colors=always
46+
- run: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-text
4747
workflows:
4848
version: 2
4949
build:

.gitignore

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
.php_cs.cache
2-
.phpunit.result.cache
3-
composer.lock
4-
coverage.xml
5-
phpbench.json
6-
phpcs.xml
7-
phpunit.xml
8-
vendor/
1+
/.php_cs.cache
2+
/.phpunit.result.cache
3+
/composer.lock
4+
/coverage.xml
5+
/phpbench.json
6+
/phpcs.xml
7+
/phpunit.xml
8+
/vendor/

.scrutinizer.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
build:
2+
environment:
3+
php:
4+
version: '8.0'
25
nodes:
36
analysis:
47
tests:
@@ -7,7 +10,7 @@ build:
710
coverage:
811
tests:
912
override:
10-
- command: php vendor/bin/phpunit --coverage-clover coverage.xml
13+
- command: XDEBUG_MODE=coverage php vendor/bin/phpunit --coverage-clover coverage.xml
1114
coverage:
1215
file: coverage.xml
1316
format: clover

README.md

Lines changed: 27 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi (Swagger)
1+
# HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenAPI (Swagger) Specification
22

33
[![Build Status](https://circleci.com/gh/sunrise-php/http-router.svg?style=shield)](https://circleci.com/gh/sunrise-php/http-router)
44
[![Code Coverage](https://scrutinizer-ci.com/g/sunrise-php/http-router/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-router/?branch=master)
@@ -15,17 +15,24 @@
1515
composer require 'sunrise/http-router:^2.10'
1616
```
1717

18+
## Support for OpenAPI (Swagger) Specification (optional)
19+
20+
```bash
21+
composer require 'sunrise/http-router-openapi:^2.0'
22+
```
23+
24+
More details can be found here: [sunrise/http-router-openapi](https://github.com/sunrise-php/http-router-openapi).
25+
1826
## QuickStart
1927

20-
The example uses other sunrise packages, but you can use, for example, `zend/diactoros` or any other.
28+
This example uses other sunrise packages, but you can use e.g. `zend/diactoros` or any other.
2129

2230
```bash
2331
composer require sunrise/http-message sunrise/http-server-request
2432
```
2533

2634
```php
2735
use Sunrise\Http\Message\ResponseFactory;
28-
use Sunrise\Http\Router\RequestHandler\CallableRequestHandler;
2936
use Sunrise\Http\Router\RouteCollector;
3037
use Sunrise\Http\Router\Router;
3138
use Sunrise\Http\ServerRequest\ServerRequestFactory;
@@ -34,14 +41,24 @@ use function Sunrise\Http\Router\emit;
3441

3542
$collector = new RouteCollector();
3643

37-
// set container if necessary...
38-
$collector->setContainer($container);
44+
// PSR-15 request handler (optimal performance):
45+
$collector->get('home', '/', new HomeRequestHandler());
3946

40-
$collector->get('home', '/', new CallableRequestHandler(function ($request) {
41-
return (new ResponseFactory)->createJsonResponse(200, [
42-
'status' => 'ok',
43-
]);
44-
}));
47+
// or you can use an anonymous function as your request handler:
48+
$collector->get('home', '/', function ($request) {
49+
return (new ResponseFactory)->createResponse(200);
50+
});
51+
52+
// or you can use the name of a class that implements PSR-15:
53+
$collector->get('home', '/', HomeRequestHandler::class);
54+
55+
// or you can use a class method name as your request handler:
56+
// (note that such a class mayn't implement PSR-15)
57+
$collector->get('home', '/', [HomeRequestHandler::class, 'index']);
58+
59+
// most likely you will need to use PSR-11 container:
60+
// (note that only named classes will be pulled from such a container)
61+
$collector->setContainer($container);
4562

4663
$router = new Router();
4764
$router->addRoute(...$collector->getCollection()->all());
@@ -412,48 +429,6 @@ final class EntryUpdateRequestHandler implements RequestHandlerInterface
412429

413430
## Useful to know
414431

415-
### OpenApi (Swagger)
416-
417-
```bash
418-
composer require 'sunrise/http-router-openapi:^1.1'
419-
```
420-
421-
#### Generation documentation for Swagger (OAS)
422-
423-
```php
424-
use Sunrise\Http\Router\OpenApi\Object\Info;
425-
use Sunrise\Http\Router\OpenApi\OpenApi;
426-
427-
$openApi = new OpenApi(new Info('0.0.1', 'API'));
428-
429-
$openApi->addRoute(...$router->getRoutes());
430-
431-
$openApi->toArray();
432-
```
433-
434-
#### Validation a request body via Swagger documentation
435-
436-
```php
437-
use Sunrise\Http\Router\OpenApi\Middleware\RequestBodyValidationMiddleware;
438-
439-
$route->addMiddleware(new RequestBodyValidationMiddleware());
440-
```
441-
442-
or using annotations:
443-
444-
```php
445-
/**
446-
* @Route(
447-
* name="foo",
448-
* path="/foo",
449-
* methods={"post"},
450-
* middlewares={
451-
* "Sunrise\Http\Router\OpenApi\Middleware\RequestBodyValidationMiddleware",
452-
* },
453-
* )
454-
*/
455-
```
456-
457432
### Generation a route URI
458433

459434
```php

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@
5757
},
5858
"autoload-dev": {
5959
"psr-4": {
60-
"Sunrise\\Http\\Router\\Test\\Fixture\\": "tests/fixtures/"
60+
"Sunrise\\Http\\Router\\Tests\\Fixtures\\": "tests/fixtures/"
6161
}
6262
},
6363
"scripts": {
6464
"test": [
6565
"phpcs",
66-
"XDEBUG_MODE=coverage phpunit --colors=always --coverage-text"
66+
"XDEBUG_MODE=coverage phpunit --coverage-text"
6767
]
6868
}
6969
}

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</include>
77
</coverage>
88
<testsuites>
9-
<testsuite name="Sunrise HTTP Router Test Suite">
9+
<testsuite name="sunrise.http.router.testSuite">
1010
<directory>./tests/</directory>
1111
</testsuite>
1212
</testsuites>

tests/Command/RouteListCommandTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php declare(strict_types=1);
22

3-
namespace Sunrise\Http\Router\Test\Command;
3+
namespace Sunrise\Http\Router\Tests\Command;
44

55
/**
66
* Import classes
77
*/
88
use PHPUnit\Framework\TestCase;
99
use Sunrise\Http\Router\Command\RouteListCommand;
1010
use Sunrise\Http\Router\Router;
11-
use Sunrise\Http\Router\Test\Fixture;
11+
use Sunrise\Http\Router\Tests\Fixtures;
1212
use Symfony\Component\Console\Tester\CommandTester;
1313

1414
/**
@@ -23,9 +23,9 @@ class RouteListCommandTest extends TestCase
2323
public function testRun() : void
2424
{
2525
$routes = [
26-
new Fixture\Route(),
27-
new Fixture\Route(),
28-
new Fixture\Route(),
26+
new Fixtures\Route(),
27+
new Fixtures\Route(),
28+
new Fixtures\Route(),
2929
];
3030

3131
$router = new Router();

tests/Exception/BadRequestExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Sunrise\Http\Router\Test\Exception;
3+
namespace Sunrise\Http\Router\Tests\Exception;
44

55
/**
66
* Import classes

tests/Exception/ExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Sunrise\Http\Router\Test\Exception;
3+
namespace Sunrise\Http\Router\Tests\Exception;
44

55
/**
66
* Import classes

tests/Exception/InvalidArgumentExceptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php declare(strict_types=1);
22

3-
namespace Sunrise\Http\Router\Test\Exception;
3+
namespace Sunrise\Http\Router\Tests\Exception;
44

55
/**
66
* Import classes

0 commit comments

Comments
 (0)