Download the PHP package piotrpolak/conditional-routing-bundle without Composer
On this page you can find all versions of the php package piotrpolak/conditional-routing-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download piotrpolak/conditional-routing-bundle
More information about piotrpolak/conditional-routing-bundle
Files in piotrpolak/conditional-routing-bundle
Package conditional-routing-bundle
Short Description Provides a way to selectively load Symfony bundle routes based on a set of user defined conditions.
License MIT
Informations about the package conditional-routing-bundle
Symfony conditional-routing-bundle
Provides a way to load selected Symfony bundle routes based on a set of user defined conditions.
Solves the problem of redirecting (overwriting) Symfony application routes from a base bundle to another bundle.
Example usages
- Overwrite Symfony application routes for selected users and/or roles;
- Overwrite Symfony application routes based on the current time (e.g. switching monthly campaigns);
- Overwrite Symfony application routes based on session variable values;
- Overwrite Symfony application routes based on user role and HTTP domain.
Installation
Install composer package
Enable PiotrPolakConditionalRoutingBundle
in the application kernel
Include bundle routing
Including routing.yml
will enable the ConditionalRouterLoader
.
Symfony will only load the resource loader if you use it for at least one route. You can alternatively paste the contents of the above resource file directly in your
app/config/routing.yml
.
Implement your own route resolver
Route resolvers are the components that implement RouteResolverInterface
and decide which bundles' routing is
to be included at the request time.
A typical route resolver component is registered in the container configuration under the
conditional_loader.route_resolver
tag - you can register any number of route resolver components and all of them will
be taken in account when selecting the combination of bundles to be included.
Since you can pass any other component to the route resolver constructor (like @session
, @security.token_storage
...)
bundles can be picked using any user defined scenarios.
Example - date condition
The following example loads MyCampaign2016Bundle
routing based on the year condition. Note: MyCampaign2016Bundle
must first be enabled in AppKernel.php
.
Please note that
AbstractYamlRouteResolver
is just a helper that makes use ofRouteResolverInterface
easier.
Example - database value input
Reading the current bundle name from the database.
Example - loading routing of various types
Route resolver from the following example implements directly the RouteResolverInterface
and loads routing of both
YAML and XML types.
Compatibility
- PHP 5.4+
- Symfony 2.3-3.4
Precautions
If you are trying to generate a link to a route that is not currently active, Symfony will throw an error. To avoid situations like that please make sure all routes have their default behavior defined in one of you base bundles.
Development
Code should be checked using phpmd before being commited:
Testing
To test in an arbitrary version combination, please use (sudo
might be required to connect to the Docker daemon):
Known issues
Warming up the Symfony cache will nor remove the custom router matchers and generators as we are not able to predict the final combination of the router-enabled bundles (they are only known at the runtime).
A workaround to clean up the cache would be to add the following commands to your deploy scripts:
-
Symfony 2
- Symfony 3
All versions of conditional-routing-bundle with dependencies
symfony/yaml Version ~2.3|~3.4
symfony/routing Version ~2.3|~3.4
symfony/dependency-injection Version ~2.3|~3.4
symfony/config Version ~2.3|~3.4
symfony/http-kernel Version ~2.3|~3.4
symfony/framework-bundle Version ~2.3|~3.4