Skip to content

Commit bd571c7

Browse files
committedFeb 17, 2024
ORC-399: Create package for deprecation routing
Signed-off-by: Serhii Donii <serhii.donii@macpaw.com>
1 parent 4492880 commit bd571c7

28 files changed

+1275
-2
lines changed
 

‎.github/workflows/ci.yaml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [ main, develop ]
7+
8+
jobs:
9+
run:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
php:
15+
- '8.3'
16+
coverage: ['none']
17+
symfony-versions:
18+
- '6.4.*'
19+
- '7.0.*'
20+
include:
21+
- php: '8.3'
22+
symfony-versions: '^6.4'
23+
coverage: 'none'
24+
25+
name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
30+
- uses: actions/cache@v2
31+
with:
32+
path: ~/.composer/cache/files
33+
key: ${{ matrix.php }}-${{ matrix.symfony-versions }}
34+
35+
- name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: ${{ matrix.php }}
39+
coverage: ${{ matrix.coverage }}
40+
41+
- name: Add PHPUnit matcher
42+
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
43+
44+
- name: Set composer cache directory
45+
id: composer-cache
46+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
47+
48+
- name: Cache composer
49+
uses: actions/cache@v2.1.2
50+
with:
51+
path: ${{ steps.composer-cache.outputs.dir }}
52+
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }}
53+
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer
54+
55+
- name: Update Symfony version
56+
if: matrix.symfony-versions != ''
57+
run: |
58+
composer require symfony/config:${{ matrix.symfony-versions }} --no-update --no-scripts
59+
composer require symfony/dependency-injection:${{ matrix.symfony-versions }} --no-update --no-scripts
60+
composer require symfony/http-kernel:${{ matrix.symfony-versions }} --no-update --no-scripts
61+
composer require symfony/routing:${{ matrix.symfony-versions }} --no-update --no-scripts
62+
composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts
63+
composer require --dev symfony/browser-kit:${{ matrix.symfony-versions }} --no-update --no-scripts
64+
- name: Install dependencies
65+
run: composer install
66+
67+
- name: Run PHPUnit tests
68+
run: vendor/bin/phpunit
69+
if: matrix.coverage == 'none'

‎.github/workflows/static_analyse.yaml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
on:
2+
pull_request:
3+
push:
4+
branches: [ main, develop ]
5+
6+
jobs:
7+
php-cs-fixer:
8+
name: PHP-CS-Fixer
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
14+
- name: Setup PHP
15+
uses: shivammathur/setup-php@v2
16+
17+
- name: Install dependencies
18+
run: composer install --no-progress --no-interaction --prefer-dist
19+
20+
- name: Run script
21+
run: vendor/bin/phpcs
22+
23+
phpstan:
24+
name: PHPStan
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v2
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
33+
- name: Install dependencies
34+
run: composer install --no-progress --no-interaction --prefer-dist
35+
36+
- name: Run script
37+
run: vendor/bin/phpstan analyse
38+
39+
composer-validate:
40+
name: Composer validate
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v2
45+
46+
- name: Setup PHP
47+
uses: shivammathur/setup-php@v2
48+
49+
- name: Install dependencies
50+
run: composer install --no-progress --no-interaction --prefer-dist
51+
52+
- name: Run script
53+
run: composer validate

‎.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.idea
2+
/*.DStore*
3+
/docker-compose.override.yml
4+
/*.iml
5+
/composer.lock
6+
/vendor/
7+
/phpunit.xml
8+
/phpcs.xml
9+
/var
10+
/coverage
11+
/.*cache*

‎.infrastructure/.docker/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ARG from_image
2+
3+
FROM $from_image
4+
5+
RUN apk add --no-cache bash \
6+
&& curl --silent https://getcomposer.org/composer-stable.phar -o /usr/bin/composer && chmod a+x /usr/bin/composer

‎README.md

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
# symfony-deprecated-routes
2-
Symfony Deprecated Routes Bundle
1+
# Symfony Deprecated Routes Bundle
2+
3+
Symfony Deprecated Routes Bundle offers to mark some api routes as deprecated.
4+
5+
## Installation
6+
7+
Use Composer to install the bundle:
8+
9+
```shell
10+
composer require macpaw/symfony-messenger-bundle
11+
```
12+
13+
## Setup bundle
14+
15+
Enable the bundle by adding it to the list of registered bundles in config/bundles.php
16+
17+
```php
18+
// config/bundles.php
19+
20+
return [
21+
Macpaw\SymfonyDeprecatedRoutes\DeprecatedRoutesBundle::class => ['all' => true],
22+
// ...
23+
];
24+
```
25+
26+
## Extend bundle options
27+
28+
This bundle provide configuration for marking routes
29+
30+
| Option | Type | Description | Default value |
31+
|-----------------|-------|-------------------------------------------------------------------------------------------------|---------------|
32+
| headers | array | Deprecation headers names | |
33+
| isDisabled | bool | Disable add marks for routes | false |
34+
| headers | array | Deprecation headers names | |
35+
| isSinceRequired | bool | If true enable validation for set [route attribute](src/Routing/Attribute/DeprecatedRoute.php) | false |
36+
37+
### Headers names options
38+
39+
| Name | Description |
40+
|-----------------------|-------------------------------------|
41+
| deprecatedMessageName | Deprecated message info header name |
42+
| deprecatedFromName | Start deprecation date |
43+
| deprecatedSinceName | The date of the removal route |
44+
45+
## Full config example with default values
46+
47+
`config/packages/deprecated-routes.yaml`
48+
49+
```shell
50+
deprecated-routes:
51+
isSinceRequired: false
52+
isDisabled: false
53+
54+
headers:
55+
deprecatedMessageName: 'X-DEPRECATED'
56+
deprecatedFromName: 'X-DEPRECATED-FROM'
57+
deprecatedSinceName: 'X-DEPRECATED-SINCE'
58+
```

‎Resource/config/services.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
6+
Macpaw\SymfonyDeprecatedRoutes\Routing\:
7+
resource: '../../src/Routing/*'
8+
exclude:
9+
- ../../src/Routing/EventSubscriber
10+
11+
Macpaw\SymfonyDeprecatedRoutes\Routing\EventSubscriber\DeprecationRoutesEventSubscriber:
12+
tags: ['kernel.event_subscriber']
13+
arguments:
14+
$deprecationFromHeaderName: 'X-DEPRECATED-FROM'
15+
$deprecationSinceHeaderName: 'X-DEPRECATED-SINCE'
16+
$deprecationHeaderName: 'X-DEPRECATED'
17+
18+
Macpaw\SymfonyDeprecatedRoutes\Routing\Loader\RoutesLoaderDecorator:
19+
class: Macpaw\SymfonyDeprecatedRoutes\Routing\Loader\RoutesLoaderDecorator
20+
decorates: routing.loader
21+
arguments: [ '@Macpaw\SymfonyDeprecatedRoutes\Routing\Loader\RoutesLoaderDecorator.inner' ]

‎composer.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"name": "macpaw/symfony-deprecated-routes",
3+
"description": "Symfony Deprecated Routes Annotations",
4+
"license": "MIT",
5+
"type": "library",
6+
"require-dev": {
7+
"symfony/browser-kit": "^6.0",
8+
"phpunit/phpunit": "^10.5",
9+
"squizlabs/php_codesniffer": "^3.8",
10+
"symfony/yaml": "^6.4|^7.0",
11+
"symfony/framework-bundle": "^6.4|^7.0"
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"Macpaw\\SymfonyDeprecatedRoutes\\": "src/"
16+
}
17+
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"Macpaw\\SymfonyDeprecatedRoutes\\Tests\\": "tests/"
21+
}
22+
},
23+
"config": {
24+
"allow-plugins": {
25+
"dealerdirect/phpcodesniffer-composer-installer": true
26+
}
27+
},
28+
"scripts": {
29+
"validate": [
30+
"composer validate"
31+
]
32+
},
33+
"minimum-stability": "stable",
34+
"require": {
35+
"php": "^8.1",
36+
"symfony/config": "^6.4|^7.0",
37+
"symfony/dependency-injection": "^6.4|^7.0",
38+
"symfony/http-kernel": "^6.4|^7.0",
39+
"symfony/routing": "^6.4|^7.0",
40+
"phpstan/phpstan-symfony": "^1.3",
41+
"symfony/event-dispatcher": "^6.4"
42+
}
43+
}

‎docker-compose.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: '3.9'
2+
3+
services:
4+
php83:
5+
build:
6+
context: .infrastructure/.docker
7+
dockerfile: Dockerfile
8+
args:
9+
from_image: php:8.3-fpm-alpine
10+
working_dir: /app
11+
environment:
12+
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/vendor/bin"
13+
volumes:
14+
- ./:/app
15+
php82:
16+
working_dir: /app
17+
build:
18+
context: .infrastructure/.docker
19+
dockerfile: Dockerfile
20+
args:
21+
from_image: php:8.2-fpm-alpine
22+
environment:
23+
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/vendor/bin"
24+
volumes:
25+
- ./:/app
26+
php81:
27+
build:
28+
context: .infrastructure/.docker
29+
dockerfile: Dockerfile
30+
args:
31+
from_image: php:8.1-fpm-alpine
32+
working_dir: /app
33+
environment:
34+
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/app/vendor/bin"
35+
volumes:
36+
- ./:/app

‎phpcs.xml.dist

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg value="p"/>
9+
<arg name="extensions" value="php"/>
10+
<arg name="tab-width" value="4"/>
11+
<arg name="report-width" value="120"/>
12+
13+
<rule ref="PSR12" />
14+
15+
<file>src/</file>
16+
<file>tests/</file>
17+
18+
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
19+
<rule ref="Generic.PHP.RequireStrictTypes"/>
20+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
21+
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"></rule>
22+
<rule ref="Squiz.Commenting.FunctionComment.SpacingAfterParamType"></rule>
23+
24+
<rule ref="Generic.PHP.ForbiddenFunctions">
25+
<properties>
26+
<property name="forbiddenFunctions" type="array" value="eval=>NULL,dd=>NULL,die=>NULL,var_dump=>NULL,dump=>NULL,sizeof=>count,delete=>unset,print=>echo,echo=>NULL,print_r=>NULL,create_function=>NULL"/>
27+
</properties>
28+
</rule>
29+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
30+
<properties>
31+
<property name="spacing" value="1" />
32+
<property name="spacingBeforeFirst" value="0" />
33+
<property name="spacingAfterLast" value="0" />
34+
</properties>
35+
</rule>
36+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
37+
<properties>
38+
<property name="ignoreBlankLines" value="false" />
39+
</properties>
40+
</rule>
41+
</ruleset>

‎phpstan.neon

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: max
3+
excludePaths:
4+
- src/DependencyInjection/Configuration.php
5+
paths:
6+
- src
7+
- tests

‎phpunit.xml.dist

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
5+
colors="true"
6+
cacheDirectory="/tmp/phpunit">
7+
<php>
8+
<ini name="error_reporting" value="-1"/>
9+
<ini name="memory_limit" value="-1"/>
10+
<server name="APP_ENV" value="test" force="true"/>
11+
<server name="APP_DEBUG" value="0" force="true"/>
12+
<server name="SHELL_VERBOSITY" value="-1"/>
13+
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/>
14+
<server name="SYMFONY_PHPUNIT_VERSION" value="10"/>
15+
<server name="KERNEL_CLASS" value="Macpaw\SymfonyDeprecatedRoutes\Tests\App"/>
16+
<!-- https://github.com/phpDocumentor/TypeResolver/issues/148#issuecomment-1005542099 -->
17+
<server name="SYMFONY_PHPUNIT_REQUIRE" value="phpdocumentor/type-resolver:1.6"/>
18+
</php>
19+
20+
<testsuites>
21+
<testsuite name="unit">
22+
<directory>tests/Unit</directory>
23+
</testsuite>
24+
<testsuite name="Functional">
25+
<directory>tests/Functional</directory>
26+
</testsuite>
27+
</testsuites>
28+
<source>
29+
<include>
30+
<directory>./src/Routing</directory>
31+
</include>
32+
<exclude>
33+
<directory suffix="Exception.php">src</directory>
34+
<directory suffix="php">src/DependencyInjection</directory>
35+
</exclude>
36+
</source>
37+
</phpunit>

0 commit comments

Comments
 (0)