Commit 5fa87cd
authored
Add condition option on legacy routing (#1048)
| Q | A
| --------------- | -----
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Related tickets |
| License | MIT
To create a bc-layer for the legacy routes in Sylius E-commerce project,
I need to add some route conditions to existing routes.
On simple route, I'm able to create this condition:
```yaml
sylius_admin_product_create_simple:
path: /products/new/simple
methods: [GET, POST]
condition: "context.isSyliusRoutingBcLayerEnabled() || context.isSyliusRoutingBcLayerEnabled('admin_product')"
# ...
```
But I also need to add this condition on multiple routing definition
like this following one and that's the reason of this PR.
```yaml
sylius_admin_product:
resource: |
alias: sylius.product
condition: "context.isSyliusRoutingBcLayerEnabled() || context.isSyliusRoutingBcLayerEnabled('admin_product')"
# ...
type: sylius.resource
```
To bring more context, here is the RequestContext we will implement on
Sylius core to create the bc-layer
```php
namespace Sylius\Bundle\CoreBundle\Routing;
use Symfony\Component\Routing\RequestContext as BaseRequestContext;
final class RequestContext extends BaseRequestContext
{
public function __construct(
BaseRequestContext $decorated,
private array $bcLayerConfig,
) {
// ...
}
public function isSyliusRoutingBcLayerEnabled(?string $key = null): bool
{
if (null === $key) {
return $this->bcLayerConfig['enabled'] ?? false;
}
return $this->bcLayerConfig['routes'][$key]['enabled'] ?? false;
}
}
```File tree
3 files changed
+188
-79
lines changed- src/Bundle
- Routing
- spec/Routing
3 files changed
+188
-79
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
183 | 185 | | |
184 | 186 | | |
185 | 187 | | |
| |||
0 commit comments