Skip to content

symple-developer/init-controller-bundle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Symple Initializable Controller

The Symple Initializable Controller Bundle permits initialization of Symfony controllers before invocation of action methods.

Content:

Requirements

Installation

The suggested installation method is via composer:

php composer.phar require symple-dev/init-controller-bundle:1.0.*

Configuration

You can enable or disable Symple Initializable Controller in app/config.yml (default enabled):

init_controller:
    enabled: true

Usage

Initializable Controller Interface

Implement the interface Symple\Bundle\InitControllerBundle\Controller\InitControllerInterface in your Controller.

<?php
namespace Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symple\Bundle\InitControllerBundle\Controller\InitControllerInterface;

class MyController extends Controller implements InitControllerInterface
{
    // ...
}

Init Annotation

The annotation @Symple\Bundle\InitControllerBundle\Annotation\Init tells that this method should be invoked before some action method (on kernel.controller event).

Available configuration options:

  • priority - integer value for invocation ordering (the greatest will be first), default 0
  • args - array of method arguments (optional)

Note: that @Init annotation can be applied to public methods only.

<?php
namespace Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symple\Bundle\InitControllerBundle\Annotation\Init;
use Symple\Bundle\InitControllerBundle\Controller\InitControllerInterface;

class MyController extends Controller implements InitControllerInterface
{
    /**
     * @Init(priority = 200)
     */
    public function initialize1()
    {
        // do something
    }
    
    /**
     * @Init(priority = 100, args = {123, true})
     */
    public function initialize2($int, $bool = false)
    {
        // do something
    }
    
    public function indexAction()
    {
        // ...
    }
}

In this example following methods will be invoked before indexAction (or another action method):

  1. initialize1();
  2. initialize2(123, true);

You can apply multiple @Init annotations to the same method.

About

Symple Initializable Controller

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages