Skip to content

Commit

Permalink
refactor #681 Argument parser refactoring (loic425)
Browse files Browse the repository at this point in the history
This PR was merged into the poc-new-resource-metadata branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | n
| Related tickets | 
| License         | MIT


Commits
-------

08696b9 Configure repository arguments
5ff2ff9 expression language refactoring
618b8f3 Variables collection fix and adding missing specs
b1d141b Fix argument parser spec
3d5d01c Add specs on request & token variables
d1ba068 Fix missing variables
10002b7 Test argument parser with PHPUnit (to check variables)
ddef382 Add variables collection on routing argument parser
d4bf7ff Fix coding standard
eb8694e Fix Psalm errors
3436da4 New argument parser for routing
da9ebdc Fix Phpspec tests
  • Loading branch information
lchrusciel authored Apr 7, 2023
2 parents 933c462 + da9ebdc commit ed14316
Show file tree
Hide file tree
Showing 41 changed files with 615 additions and 369 deletions.
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<errorLevel type="suppress">
<file name="src/Component/Tests/Reflection/ClassInfoTraitTest.php" />
<file name="src/Component/Tests/Reflection/ClassReflectionTest.php" />
<file name="src/Component/Tests/Symfony/ExpressionLanguage/ArgumentParserTest.php" />
<file name="src/Bundle/Validator/Constraints/UniqueWithinCollectionConstraint.php" />
<file name="src/Bundle/Validator/Constraints/Enabled.php" />
<file name="src/Bundle/Validator/Constraints/Disabled.php" />
Expand Down
1 change: 1 addition & 0 deletions src/Bundle/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<import resource="services/context.xml" />
<import resource="services/controller.xml" />
<import resource="services/dispatcher.xml" />
<import resource="services/expression_language.xml" />
<import resource="services/form.xml" />
<import resource="services/helper.xml" />
<import resource="services/listener.xml" />
Expand Down
59 changes: 59 additions & 0 deletions src/Bundle/Resources/config/services/expression_language.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
This file is part of the Sylius package.
(c) Paweł Jędrzejewski
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
-->

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius.resource_factory.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" />
<service id="sylius.repository.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" />
<service id="sylius.routing.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" />

<service id="sylius.expression_language.variables.token" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\TokenVariables">
<argument type="service" id="security.token_storage" />
<tag name="sylius.resource_factory_variables" />
<tag name="sylius.repository_variables" />
</service>

<service id="sylius.expression_language.variables.request" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\RequestVariables">
<argument type="service" id="request_stack" />
<tag name="sylius.resource_factory_variables" />
<tag name="sylius.repository_variables" />
</service>

<service id="sylius.expression_language.variables_collection.factory" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\VariablesCollection">
<argument type="tagged_iterator" tag="sylius.resource_factory_variables" />
</service>

<service id="sylius.expression_language.variables_collection.repository" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\VariablesCollection">
<argument type="tagged_iterator" tag="sylius.repository_variables" />
</service>

<service id="sylius.expression_language.variables_collection.routing" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\VariablesCollection">
<argument type="tagged_iterator" tag="sylius.routing_variables" />
</service>

<service id="sylius.expression_language.argument_parser.factory" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\ArgumentParser">
<argument type="service" id="sylius.resource_factory.expression_language" />
<argument type="service" id="sylius.expression_language.variables_collection.factory" />
</service>

<service id="sylius.expression_language.argument_parser.repository" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\ArgumentParser">
<argument type="service" id="sylius.repository.expression_language" />
<argument type="service" id="sylius.expression_language.variables_collection.repository" />
</service>

<service id="sylius.expression_language.argument_parser.routing" class="Sylius\Component\Resource\Symfony\ExpressionLanguage\ArgumentParser">
<argument type="service" id="sylius.routing.expression_language" />
<argument type="service" id="sylius.expression_language.variables_collection.routing" />
</service>
</services>
</container>
8 changes: 1 addition & 7 deletions src/Bundle/Resources/config/services/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,9 @@
</service>
<service id="Sylius\Component\Resource\Symfony\Routing\Factory\OperationRouteFactoryInterface" alias="sylius.routing.factory.operation_route" />

<service id="sylius.routing.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" />

<service id="sylius.routing.argument_parser" class="Sylius\Component\Resource\Symfony\Routing\ArgumentParser">
<argument type="service" id="sylius.routing.expression_language" />
</service>

<service id="sylius.routing.redirect_handler" class="Sylius\Component\Resource\Symfony\Routing\RedirectHandler">
<argument type="service" id="router" />
<argument type="service" id="sylius.routing.argument_parser" />
<argument type="service" id="sylius.expression_language.argument_parser.routing" />
</service>
</services>
</container>
12 changes: 2 additions & 10 deletions src/Bundle/Resources/config/services/state.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="sylius.resource_factory.expression_language" class="Symfony\Component\ExpressionLanguage\ExpressionLanguage" />

<service id="sylius.resource_factory.argument_parser" class="Sylius\Component\Resource\Factory\ArgumentParser">
<argument type="service" id="sylius.resource_factory.expression_language" />
<argument type="service" id="request_stack" />
<argument type="service" id="security.token_storage" on-invalid="null" />
</service>
<service id="Sylius\Component\Resource\Factory\ArgumentParserInterface" alias="sylius.resource_factory.argument_parser" />

<service id="sylius.state.provider" class="Sylius\Component\Resource\State\Provider">
<argument type="tagged_locator" tag="sylius.state_provider" />
</service>
Expand All @@ -38,7 +29,7 @@

<service id="sylius.state.factory" class="Sylius\Component\Resource\State\Factory">
<argument type="tagged_locator" tag="sylius.resource_factory" />
<argument type="service" id="sylius.resource_factory.argument_parser" />
<argument type="service" id="sylius.expression_language.argument_parser.factory" />
</service>
<service id="Sylius\Component\Resource\State\FactoryInterface" alias="sylius.state.factory" />

Expand Down Expand Up @@ -81,6 +72,7 @@
<service id="Sylius\Component\Resource\Symfony\Request\State\Provider">
<argument type="tagged_locator" tag="sylius.repository" />
<argument type="service" id="sylius.repository_argument_resolver.request" />
<argument type="service" id="sylius.expression_language.argument_parser.repository" />
<tag name="sylius.state_provider" />
</service>

Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?bool $read = null,
?bool $write = null,
?bool $validate = null,
Expand All @@ -58,6 +59,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
read: $read,
write: $write,
validate: $validate,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/GetCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Api/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/BulkDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct(
string|callable|null $processor = null,
string|callable|null $responder = null,
string|callable|null $repository = null,
?array $repositoryArguments = null,
?string $repositoryMethod = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -51,6 +52,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
read: $read,
write: $write,
formType: $formType,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
string|callable|null $processor = null,
string|callable|null $responder = null,
string|callable|null $repository = null,
?array $repositoryArguments = null,
?string $repositoryMethod = null,
string|callable|false|null $factory = null,
private ?string $factoryMethod = null,
Expand Down Expand Up @@ -65,6 +66,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?bool $read = null,
?bool $write = null,
?bool $validate = null,
Expand All @@ -55,6 +56,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
read: $read,
write: $write,
validate: $validate,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/HttpOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -55,6 +56,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -55,6 +56,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
14 changes: 14 additions & 0 deletions src/Component/Metadata/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
protected ?string $repositoryMethod = null,
protected ?array $repositoryArguments = null,
protected ?string $grid = null,
protected ?bool $read = null,
protected ?bool $write = null,
Expand Down Expand Up @@ -179,6 +180,19 @@ public function withRepositoryMethod(string $repositoryMethod): self
return $self;
}

public function getRepositoryArguments(): ?array
{
return $this->repositoryArguments;
}

public function withRepositoryArguments(array $repositoryArguments): self
{
$self = clone $this;
$self->repositoryArguments = $repositoryArguments;

return $self;
}

public function getGrid(): ?string
{
return $this->grid;
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand All @@ -55,6 +56,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 2 additions & 0 deletions src/Component/Metadata/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function __construct(
string|callable|null $responder = null,
string|callable|null $repository = null,
?string $repositoryMethod = null,
?array $repositoryArguments = null,
?string $grid = null,
?bool $read = null,
?bool $write = null,
Expand Down Expand Up @@ -59,6 +60,7 @@ public function __construct(
responder: $responder,
repository: $repository,
repositoryMethod: $repositoryMethod,
repositoryArguments: $repositoryArguments,
grid: $grid,
read: $read,
write: $write,
Expand Down
2 changes: 1 addition & 1 deletion src/Component/State/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

use Psr\Container\ContainerInterface;
use Sylius\Component\Resource\Context\Context;
use Sylius\Component\Resource\Factory\ArgumentParserInterface;
use Sylius\Component\Resource\Factory\FactoryInterface as ResourceFactoryInterface;
use Sylius\Component\Resource\Metadata\FactoryAwareOperationInterface;
use Sylius\Component\Resource\Metadata\Operation;
use Sylius\Component\Resource\Symfony\ExpressionLanguage\ArgumentParserInterface;
use Webmozart\Assert\Assert;

final class Factory implements FactoryInterface
Expand Down
Loading

0 comments on commit ed14316

Please sign in to comment.