PHPackages                             piotrpolak/conditional-routing-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. piotrpolak/conditional-routing-bundle

ActiveSymfony-bundle[API Development](/categories/api)

piotrpolak/conditional-routing-bundle
=====================================

Provides a way to selectively load Symfony bundle routes based on a set of user defined conditions.

1.0.0(7y ago)52.5k2MITPHPPHP &gt;=5.3.0

Since Oct 23Pushed 7y ago1 watchersCompare

[ Source](https://github.com/piotrpolak/conditional-routing-bundle)[ Packagist](https://packagist.org/packages/piotrpolak/conditional-routing-bundle)[ RSS](/packages/piotrpolak-conditional-routing-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

Symfony conditional-routing-bundle
==================================

[](#symfony-conditional-routing-bundle)

[![Build Status](https://camo.githubusercontent.com/0f89cabfc89a4bdebc812159051d330224b037bf2c000245a0393e988d24ab8f/68747470733a2f2f7472617669732d63692e6f72672f70696f7472706f6c616b2f636f6e646974696f6e616c2d726f7574696e672d62756e646c652e737667)](https://travis-ci.org/piotrpolak/conditional-routing-bundle)[![Code Climate](https://camo.githubusercontent.com/05ed9982f2deaedd36392bf1ff7b141ccdba9f52017697b59338f03c6c179bcc/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70696f7472706f6c616b2f636f6e646974696f6e616c2d726f7574696e672d62756e646c652f6261646765732f6770612e737667)](https://codeclimate.com/github/piotrpolak/conditional-routing-bundle)[![Test Coverage](https://camo.githubusercontent.com/36a021685a3cb6fa7c0694a58f978dd73c531dc28900ee97f0fb84e45b903caf/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f70696f7472706f6c616b2f636f6e646974696f6e616c2d726f7574696e672d62756e646c652f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/piotrpolak/conditional-routing-bundle/coverage)[![SensioLabsInsight](https://camo.githubusercontent.com/386d92e1ace780ea5b6f37d44b5299f49391330611317be10bc81feb61327f0f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31626337663837622d353034662d346265302d613538352d3063663564306134336665632f6d696e692e706e67)](https://insight.sensiolabs.com/projects/1bc7f87b-504f-4be0-a585-0cf5d0a43fec)

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
--------------

[](#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
------------

[](#installation)

### Install composer package

[](#install-composer-package)

```
composer require piotrpolak/conditional-routing-bundle

```

### Enable `PiotrPolakConditionalRoutingBundle` in the application kernel

[](#enable-piotrpolakconditionalroutingbundle-in-the-application-kernel)

```
// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new PiotrPolak\ConditionalRoutingBundle\PiotrPolakConditionalRoutingBundle(),
    // ...
);
```

### Include bundle routing

[](#include-bundle-routing)

Including `routing.yml` will enable the `ConditionalRouterLoader`.

```
# in app/config/routing.yml, without those lines ConditionalRouterLoader will not be enabled
conditional_routing:
    resource: "@PiotrPolakConditionalRoutingBundle/Resources/config/routing.yml"
    type:     yaml
```

> 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

[](#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

[](#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 of `RouteResolverInterface` easier.

```
