Skip to content

Commit 659b351

Browse files
authored
Merge pull request #63 from sunrise-php/release/v2.6.0
v2.6.0
2 parents a5fb1ce + 6c592ef commit 659b351

Some content is hidden

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

43 files changed

+2545
-639
lines changed

.circleci/config.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# PHP CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-php/ for more details
4+
#
5+
version: 2
6+
jobs:
7+
php71:
8+
docker:
9+
- image: circleci/php:7.1-cli-node-browsers
10+
steps:
11+
- checkout
12+
- run: php -v
13+
- run: composer install --no-interaction --prefer-source --no-suggest
14+
- run: php vendor/bin/phpunit --colors=always
15+
php72:
16+
docker:
17+
- image: circleci/php:7.2-cli-node-browsers
18+
steps:
19+
- checkout
20+
- run: php -v
21+
- run: composer install --no-interaction --prefer-source --no-suggest
22+
- run: php vendor/bin/phpunit --colors=always
23+
php73:
24+
docker:
25+
- image: circleci/php:7.3-cli-node-browsers
26+
steps:
27+
- checkout
28+
- run: php -v
29+
- run: composer install --no-interaction --prefer-source --no-suggest
30+
- run: php vendor/bin/phpunit --colors=always
31+
php74:
32+
docker:
33+
- image: circleci/php:7.4-cli-node-browsers
34+
steps:
35+
- checkout
36+
- run: php -v
37+
- run: composer install --no-interaction --prefer-source --no-suggest
38+
- run: php vendor/bin/phpunit --colors=always
39+
php80:
40+
docker:
41+
- image: circleci/php:8.0-cli-node-browsers
42+
steps:
43+
- checkout
44+
- run: php -v
45+
- run: composer install --no-interaction --prefer-source --no-suggest
46+
- run: php vendor/bin/phpunit --colors=always
47+
workflows:
48+
version: 2
49+
build:
50+
jobs:
51+
- php71
52+
- php72
53+
- php73
54+
- php74
55+
- php80

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

README.md

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# HTTP router for PHP 7.1+ (incl. PHP 8) 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)
22

3-
[![Build Status](https://scrutinizer-ci.com/g/sunrise-php/http-router/badges/build.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-router/build-status/master)
3+
[![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)
55
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sunrise-php/http-router/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sunrise-php/http-router/?branch=master)
66
[![Total Downloads](https://poser.pugx.org/sunrise/http-router/downloads?format=flat)](https://packagist.org/packages/sunrise/http-router)
@@ -12,12 +12,12 @@
1212
## Installation
1313

1414
```bash
15-
composer require 'sunrise/http-router:^2.5'
15+
composer require 'sunrise/http-router:^2.6'
1616
```
1717

1818
## QuickStart
1919

20-
The example uses other sunrise packages, but you can use for example `zend/diactoros`, or any other.
20+
The example uses other sunrise packages, but you can use, for example, `zend/diactoros` or any other.
2121

2222
```bash
2323
composer require sunrise/http-message sunrise/http-server-request
@@ -88,16 +88,17 @@ $response = $router->handle($request);
8888
$response = $router->process($request, $handler);
8989
```
9090

91-
#### Strategy loading routes from annotations
91+
#### Strategy loading routes from descriptors (annotations or attributes)
9292

9393
```php
9494
use Doctrine\Common\Annotations\AnnotationRegistry;
95-
use Sunrise\Http\Router\Loader\AnnotationDirectoryLoader;
95+
use Sunrise\Http\Router\Loader\DescriptorDirectoryLoader;
9696
use Sunrise\Http\Router\Router;
9797

98+
// necessary if you will use annotations (annotations isn't attributes)...
9899
AnnotationRegistry::registerLoader('class_exists');
99100

100-
$loader = new AnnotationDirectoryLoader();
101+
$loader = new DescriptorDirectoryLoader();
101102
$loader->attach('src/Controller');
102103

103104
// or attach an array
@@ -139,10 +140,26 @@ $response = $router->process($request, $handler);
139140

140141
#### Route Annotation Example
141142

143+
##### Minimal annotation view
144+
142145
```php
143146
/**
144147
* @Route(
145-
* name="apiEntryUpdate",
148+
* name="api_v1_entry_update",
149+
* path="/api/v1/entry/{id<@uuid>}(/{optionalAttribute})",
150+
* methods={"PATCH"},
151+
* )
152+
*/
153+
final class EntryUpdateRequestHandler implements RequestHandlerInterface
154+
```
155+
156+
##### Full annotation
157+
158+
```php
159+
/**
160+
* @Route(
161+
* name="api_v1_entry_update",
162+
* host="api.host",
146163
* path="/api/v1/entry/{id<@uuid>}(/{optionalAttribute})",
147164
* methods={"PATCH"},
148165
* middlewares={
@@ -158,6 +175,47 @@ $response = $router->process($request, $handler);
158175
* priority=0,
159176
* )
160177
*/
178+
final class EntryUpdateRequestHandler implements RequestHandlerInterface
179+
```
180+
181+
#### Route Attribute Example
182+
183+
##### Minimal attribute view
184+
185+
```php
186+
use Sunrise\Http\Router\Attribute\Route;
187+
188+
#[Route(
189+
name: 'api_v1_entry_update',
190+
path: '/api/v1/entry/{id<@uuid>}(/{optionalAttribute})',
191+
methods: ['PATCH'],
192+
)]
193+
final class EntryUpdateRequestHandler implements RequestHandlerInterface
194+
```
195+
196+
##### Full attribute
197+
198+
```php
199+
use Sunrise\Http\Router\Attribute\Route;
200+
201+
#[Route(
202+
name: 'api_v1_entry_update',
203+
host: 'api.host',
204+
path: '/api/v1/entry/{id<@uuid>}(/{optionalAttribute})',
205+
methods: ['PATCH'],
206+
middlewares: [
207+
\App\Middleware\CorsMiddleware::class,
208+
\App\Middleware\ApiAuthMiddleware::class,
209+
],
210+
attributes: [
211+
'optionalAttribute' => 'defaultValue',
212+
],
213+
summary: 'Updates an entry by UUID',
214+
description: 'Here you can describe the method in more detail...',
215+
tags: ['api', 'entry'],
216+
priority: 0,
217+
)]
218+
final class EntryUpdateRequestHandler implements RequestHandlerInterface
161219
```
162220

163221
---
@@ -245,6 +303,26 @@ $collector->group(function ($collector) {
245303
$collector->get('api.entry.read', '/api/v1/entry/{id<\d+>}(/{optional<\w+>})');
246304
```
247305

306+
### Hosts (available from version 2.6.0)
307+
308+
> Note: if you don't assign a host for a route, it will be available on any hosts!
309+
310+
```php
311+
// move the hosts table into the settings...
312+
$router->addHost('public.host', 'www.example.com');
313+
$router->addHost('admin.host', 'secret.example.com');
314+
$router->addHost('api.host', 'api.example.com');
315+
316+
// the route will available only on the `secret.example.com` host...
317+
$route->setHost('admin.host');
318+
319+
// routes in the group will available on the `secret.example.com` host...
320+
$collector->group(function ($collector) {
321+
// some code...
322+
})
323+
->setHost('admin.host');
324+
```
325+
248326
---
249327

250328
## Test run

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sunrise/http-router",
33
"homepage": "https://github.com/sunrise-php/http-router",
4-
"description": "Sunrise // HTTP router for PHP 7.1+ (incl. PHP 8) based on PSR-7 and PSR-15 with support for annotations and OpenApi Specification",
4+
"description": "Sunrise // HTTP router for PHP 7.1+ (incl. PHP 8 with attributes) based on PSR-7 and PSR-15 with support for annotations and OpenApi Specification",
55
"license": "MIT",
66
"keywords": [
77
"fenric",
@@ -14,7 +14,9 @@
1414
"psr-7",
1515
"psr-15",
1616
"php7",
17-
"php8"
17+
"php8",
18+
"attributes",
19+
"php-attributes"
1820
],
1921
"authors": [
2022
{

0 commit comments

Comments
 (0)