Skip to content

Commit cbc846c

Browse files
Add route condition on new routing system (#1050)
| Q | A | --------------- | ----- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT The system works for the bc-layer usage. We just need to have two route names ```php new Index(routeName: '_sylius_admin_product_index', grid: 'sylius_admin_product'), ``` **bc-layer disabled** ![image](https://github.com/user-attachments/assets/b1dca027-fe04-4c8d-b675-6996733cc118) **bc-layer enabled** ![image](https://github.com/user-attachments/assets/e469f043-0bc9-4e0e-a135-7a4e3811fc7b)
2 parents 5fa87cd + c4c5dd5 commit cbc846c

File tree

23 files changed

+151
-1
lines changed

23 files changed

+151
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Sylius package.
5+
*
6+
* (c) Sylius Sp. z o.o.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Sylius\Component\Resource\Tests\Dummy;
15+
16+
use Sylius\Resource\Metadata\AsResource;
17+
use Sylius\Resource\Metadata\Create;
18+
use Sylius\Resource\Metadata\Index;
19+
use Sylius\Resource\Metadata\Show;
20+
use Sylius\Resource\Metadata\Update;
21+
22+
#[AsResource(alias: 'app.dummy', routeCondition: 'custom_condition')]
23+
#[Create]
24+
#[Update]
25+
#[Index]
26+
#[Show]
27+
final class DummyResourceWithRouteCondition
28+
{
29+
}

src/Component/spec/Symfony/Routing/Factory/OperationRouteFactorySpec.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,22 @@ function it_generates_routes_with_requirements(
307307

308308
$route->getRequirements()->shouldReturn(['type' => 'country|province|zone']);
309309
}
310+
311+
function it_generates_routes_with_condition(
312+
OperationRoutePathFactoryInterface $routePathFactory,
313+
): void {
314+
$operation = new Index(routeCondition: 'custom_condition');
315+
316+
$metadata = Metadata::fromAliasAndConfiguration('app.dummy', ['driver' => 'dummy_driver']);
317+
318+
$routePathFactory->createRoutePath($operation, 'dummies')->willReturn('/dummies')->shouldBeCalled();
319+
320+
$route = $this->create(
321+
$metadata,
322+
new ResourceMetadata(alias: 'app.dummy'),
323+
$operation,
324+
);
325+
326+
$route->getCondition()->shouldReturn('custom_condition');
327+
}
310328
}

src/Component/src/Metadata/Api/Delete.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'delete',
6365
name: $name,

src/Component/src/Metadata/Api/Get.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'get',
6365
name: $name,

src/Component/src/Metadata/Api/GetCollection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'get_collection',
6365
name: $name,

src/Component/src/Metadata/Api/Patch.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'patch',
6365
name: $name,

src/Component/src/Metadata/Api/Post.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'post',
6365
name: $name,

src/Component/src/Metadata/Api/Put.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(
2727
?string $routeName = null,
2828
?string $routePrefix = null,
2929
?array $routeRequirements = null,
30+
?string $routeCondition = null,
3031
?string $template = null,
3132
?string $shortName = null,
3233
?string $name = null,
@@ -58,6 +59,7 @@ public function __construct(
5859
routeName: $routeName,
5960
routePrefix: $routePrefix,
6061
routeRequirements: $routeRequirements,
62+
routeCondition: $routeCondition,
6163
template: $template,
6264
shortName: $shortName ?? 'put',
6365
name: $name,

src/Component/src/Metadata/ApplyStateMachineTransition.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function __construct(
2424
?string $path = null,
2525
?string $routeName = null,
2626
?string $routePrefix = null,
27+
?string $routeCondition = null,
2728
?string $template = null,
2829
?string $shortName = null,
2930
?string $name = null,
@@ -53,6 +54,7 @@ public function __construct(
5354
path: $path,
5455
routeName: $routeName,
5556
routePrefix: $routePrefix,
57+
routeCondition: $routeCondition,
5658
template: $template,
5759
shortName: $shortName ?? $stateMachineTransition ?? 'apply_state_machine_transition',
5860
name: $name,

src/Component/src/Metadata/AsResource.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function __construct(
2222
private ?string $formType = null,
2323
private ?string $templatesDir = null,
2424
private ?string $routePrefix = null,
25+
private ?string $routeCondition = null,
2526
private ?string $name = null,
2627
private ?string $pluralName = null,
2728
private ?string $applicationName = null,
@@ -44,6 +45,7 @@ public function toMetadata(): ResourceMetadata
4445
formType: $this->formType,
4546
templatesDir: $this->templatesDir,
4647
routePrefix: $this->routePrefix,
48+
routeCondition: $this->routeCondition,
4749
name: $this->name,
4850
pluralName: $this->pluralName,
4951
applicationName: $this->applicationName,

0 commit comments

Comments
 (0)