-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from MacPaw/feat/request-dto-resolver
feat: symfony request dto resolver bundle
- Loading branch information
Showing
28 changed files
with
784 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: CI | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main, develop] | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: | ||
- '8.2' | ||
- '8.3' | ||
symfony-versions: | ||
- '^6.4' | ||
- '^7.0' | ||
|
||
name: PHP ${{ matrix.php }} Symfony ${{ matrix.symfony-versions }} ${{ matrix.description }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/.composer/cache/files | ||
key: ${{ matrix.php }}-${{ matrix.symfony-versions }} | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
coverage: ${{ matrix.coverage }} | ||
|
||
- name: Add PHPUnit matcher | ||
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | ||
|
||
- name: Set composer cache directory | ||
id: composer-cache | ||
run: echo "::set-output name=dir::$(composer config cache-files-dir)" | ||
|
||
- name: Cache composer | ||
uses: actions/[email protected] | ||
with: | ||
path: ${{ steps.composer-cache.outputs.dir }} | ||
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer-${{ hashFiles('composer.json') }} | ||
restore-keys: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.symfony-versions }}-composer | ||
|
||
- name: Update Symfony version | ||
if: matrix.symfony-versions != '' | ||
run: | | ||
composer require symfony/form:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
composer require symfony/framework-bundle:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
composer require symfony/validator:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
composer require --dev symfony/yaml:${{ matrix.symfony-versions }} --no-update --no-scripts | ||
- name: Install dependencies | ||
run: composer install | ||
|
||
- name: Run PHPUnit tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Code style and static analysis | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: [main, develop] | ||
|
||
jobs: | ||
php-cs-fixer: | ||
name: PHP-CS-Fixer | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
|
||
- name: Install dependencies | ||
run: composer install --no-progress --no-interaction --prefer-dist | ||
|
||
- name: Run script | ||
run: vendor/bin/phpcs | ||
|
||
phpstan: | ||
name: PHPStan | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
|
||
- name: Install dependencies | ||
run: composer install --no-progress --no-interaction --prefer-dist | ||
|
||
- name: Run script | ||
run: vendor/bin/phpstan | ||
|
||
composer-validate: | ||
name: Composer validate | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
|
||
- name: Install dependencies | ||
run: composer install --no-progress --no-interaction --prefer-dist | ||
|
||
- name: Run script | ||
run: composer validate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/.DS_Store | ||
.idea/* | ||
.phpcs-cache | ||
composer.lock | ||
phpunit.xml | ||
var/ | ||
vendor/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,38 @@ | ||
# request-dto-resolver | ||
Symfony request resolver bundle | ||
Symfony Request DTO Resolver bundle | ||
=============================== | ||
Automatically parses Symfony HTTP request, validates parameters, hydrates DTO and passes it as an argument | ||
to your controller. | ||
|
||
Installation | ||
------------ | ||
|
||
Open a command console, switch to your project directory and execute: | ||
|
||
```console | ||
composer require macpaw/request-dto-resolver | ||
``` | ||
Your bundle now should be automatically added to the list of registered bundles. | ||
|
||
```php | ||
// config/bundles.php | ||
<?php | ||
return [ | ||
RequestDtoResolver\RequestDtoResolverBundle::class => ['all' => true], | ||
|
||
// ... | ||
]; | ||
``` | ||
If your application doesn't use Symfony Flex you need to manually add your bundle | ||
to the list of registered bundles in `config/bundles.php` file. | ||
|
||
|
||
Create bundle config | ||
-------------------- | ||
|
||
```yaml | ||
# config/packages/request_dto_resolver.yaml` | ||
request_dto_resolver: | ||
target_dto_interface: <target_dto_interface> | ||
``` | ||
You need to specify the interface which your target controller argument implements. | ||
See tests for example. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{ | ||
"name": "macpaw/request-dto-resolver", | ||
"description": "Request DTO resolver bundle", | ||
"homepage": "https://github.com/MacPaw/request-dto-resolver", | ||
"type": "symfony-bundle", | ||
"keywords": [ | ||
"request", | ||
"dto", | ||
"resolver" | ||
], | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=8.0", | ||
"symfony/form": "^6.4|^7.0", | ||
"symfony/framework-bundle": "^6.4|^7.0", | ||
"symfony/validator": "^6.4|^7.0" | ||
}, | ||
"require-dev": { | ||
"escapestudios/symfony2-coding-standard": "3.x-dev", | ||
"phpstan/phpstan": "^1.0", | ||
"phpunit/phpunit": "^10.0", | ||
"slevomat/coding-standard": "^8.0", | ||
"squizlabs/php_codesniffer": "^3.0", | ||
"symfony/yaml": "^6.4|^7.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"RequestDtoResolver\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"RequestDtoResolver\\Tests\\": "tests" | ||
} | ||
}, | ||
"scripts": { | ||
"cs": [ | ||
"vendor/bin/phpcs" | ||
], | ||
"cs-fix": [ | ||
"vendor/bin/phpcbf" | ||
], | ||
"phpstan": [ | ||
"vendor/bin/phpstan" | ||
], | ||
"phpunit": [ | ||
"vendor/bin/phpunit" | ||
] | ||
}, | ||
"config": { | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"> | ||
|
||
<arg name="basepath" value="."/> | ||
<arg name="cache" value=".phpcs-cache"/> | ||
<arg name="colors"/> | ||
<arg value="p"/> | ||
<arg name="extensions" value="php"/> | ||
<arg name="tab-width" value="4"/> | ||
<arg name="report-width" value="120"/> | ||
|
||
<rule ref="PSR12" /> | ||
<rule ref="Generic.PHP.ForbiddenFunctions"> | ||
<properties> | ||
<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"/> | ||
</properties> | ||
</rule> | ||
<rule ref="Squiz.WhiteSpace.FunctionSpacing"> | ||
<properties> | ||
<property name="spacing" value="1" /> | ||
<property name="spacingBeforeFirst" value="0" /> | ||
<property name="spacingAfterLast" value="0" /> | ||
</properties> | ||
</rule> | ||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"> | ||
<properties> | ||
<property name="ignoreBlankLines" value="false" /> | ||
</properties> | ||
</rule> | ||
|
||
<rule ref="Squiz.PHP.LowercasePHPFunctions"/> | ||
<rule ref="Generic.PHP.RequireStrictTypes"/> | ||
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/> | ||
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/> | ||
<rule ref="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/> | ||
<rule ref="Symfony.Formatting.BlankLineBeforeReturn"/> | ||
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"> | ||
<properties> | ||
<property name="searchAnnotations" value="true" /> | ||
</properties> | ||
</rule> | ||
<rule ref="SlevomatCodingStandard.Attributes.AttributeAndTargetSpacing"/> | ||
<rule ref="SlevomatCodingStandard.Attributes.RequireAttributeAfterDocComment"/> | ||
|
||
<file>src/</file> | ||
<file>tests/</file> | ||
<exclude-pattern>*/Resources/*</exclude-pattern> | ||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
parameters: | ||
level: 5 | ||
paths: | ||
- src | ||
- tests | ||
ignoreErrors: | ||
- | ||
message: '~Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\).~' | ||
count: 1 | ||
path: ./src/DependencyInjection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
cacheResult="false" | ||
beStrictAboutOutputDuringTests="true" | ||
> | ||
<php> | ||
<ini name="error_reporting" value="-1"/> | ||
<ini name="memory_limit" value="-1"/> | ||
<server name="APP_ENV" value="test" force="true"/> | ||
<server name="APP_DEBUG" value="0" force="true"/> | ||
<server name="SHELL_VERBOSITY" value="-1"/> | ||
<server name="SYMFONY_PHPUNIT_REMOVE" value=""/> | ||
<server name="SYMFONY_PHPUNIT_VERSION" value="10"/> | ||
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="integration"> | ||
<directory>tests/Integration</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
<exclude> | ||
<directory suffix="Exception.php">./src</directory> | ||
</exclude> | ||
</source> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RequestDtoResolver\Attribute; | ||
|
||
use Attribute; | ||
|
||
#[Attribute] | ||
class FormType | ||
{ | ||
public function __construct( | ||
private readonly string $class = '', | ||
) { | ||
} | ||
|
||
public function getClass(): string | ||
{ | ||
return $this->class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RequestDtoResolver\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
|
||
final class Configuration implements ConfigurationInterface | ||
{ | ||
public function getConfigTreeBuilder(): TreeBuilder | ||
{ | ||
$treeBuilder = new TreeBuilder('request_dto_resolver'); | ||
|
||
$treeBuilder->getRootNode() | ||
->children() | ||
->scalarNode('target_dto_interface')->cannotBeEmpty()->end() | ||
->end(); | ||
|
||
return $treeBuilder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RequestDtoResolver\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; | ||
use Symfony\Component\Config\FileLocator; | ||
|
||
class RequestDtoResolverExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container): void | ||
{ | ||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | ||
$loader->load('services.yaml'); | ||
|
||
$config = $this->processConfiguration(new Configuration(), $configs); | ||
$container->setParameter('request_dto_resolver.target_dto_interface', $config['target_dto_interface']); | ||
} | ||
} |
Oops, something went wrong.