Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Latest commit

 

History

History
172 lines (142 loc) · 4.13 KB

route.md

File metadata and controls

172 lines (142 loc) · 4.13 KB

Route

You can use route attributes for checking the feature state in controllers. This is per default activated. You can enable or disable it via the config.

# config.yml

flagception:
    features:      
        feature_123:
            default: true
        
    # Use route attributes? (optional)
    routing_metadata:
    
        # Enable controller annotation (default: true)
        enable: true

If route metadata is enabled, you can define the feature name in your route attributes. A NotFoundHttpException will be thrown if you request an action or class with inactive feature flag.

// src/AppBundle/Controller/BlogController.php
// src/Controller/BlogController.php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class BlogController extends Controller
{
    /**
     * @Route("/blog/{page}", defaults={"_feature": "feature_123"})
     */
    public function listAction($page)
    {
        // ...
    }

    /**
     * @Route("/blog/{slug}")
     */
    public function showAction($slug)
    {
        // ...
    }
}

or via yml

# app/config/routing.yml
blog_list:
    path:      /blog/{page}
    defaults:  { _controller: AppBundle:Blog:list, _feature: 'feature_789' }  

# Symfony 3.4 / 4.0
blog_list:
    path:       /blog/{page}
    controller: AppBundle:Blog:list
    defaults:   { _feature: 'feature_789' }  
    
blog_show:

or via xml

<!-- app/config/routing.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing
        http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="blog_list" path="/blog/{page}">
        <default key="_controller">AppBundle:Blog:list</default>
        <default key="_feature">feature_123</default>
    </route>

    <!-- Symfony 3.4 / 4.0 -->
    <route id="blog_list" path="/blog/{page}">
        <controller>AppBundle:Blog:list</controller>
        <default key="_feature">feature_123</default>
    </route>

    <!-- ... -->
</routes>

To check for multiple features, pass them as an array to the route definition.

// src/AppBundle/Controller/BlogController.php
// src/Controller/BlogController.php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class BlogController extends Controller
{
    /**
     * @Route("/blog/{page}", defaults={"_feature": {"feature_123", "feature_456"}})
     */
    public function listAction($page)
    {
        // ...
    }

    /**
     * @Route("/blog/{slug}")
     */
    public function showAction($slug)
    {
        // ...
    }
}

or via yml

# app/config/routing.yml
blog_list:
    path:      /blog/{page}
    defaults:  { _controller: AppBundle:Blog:list, _feature: ['feature_456', 'feature_789'] }

# Symfony 3.4 / 4.0
blog_list:
    path:       /blog/{page}
    controller: AppBundle:Blog:list
    defaults:   { _feature: ['feature_456', 'feature_789'] }

blog_show:

or via xml

<!-- app/config/routing.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://symfony.com/schema/routing
        http://symfony.com/schema/routing/routing-1.0.xsd">

    <route id="blog_list" path="/blog/{page}">
        <default key="_controller">AppBundle:Blog:list</default>
        <default key="_feature">
            <list>
                <string>feature_123</string>
                <string>feature_456</string>
            </list>
        </default>
    </route>

    <!-- Symfony 3.4 / 4.0 -->
    <route id="blog_list" path="/blog/{page}">
        <controller>AppBundle:Blog:list</controller>
        <default key="_feature">
            <list>
                <string>feature_123</string>
                <string>feature_456</string>
            </list>
        </default>
    </route>

    <!-- ... -->
</routes>