Documentation

Plugins

Presentation

It is possible to request the execution of plugins, before and/or after the execution of the application controllers. Technically, plugins are controllers with special methods, which can modify the request before passing it on to the next plugin or to the designated controller. You can chain plugins before the controller, and other plugins after.

The source files for plugins are stored in the controllers directory of the application.

The same object can have both plugin and controller roles.

Configuration

The configuration of pre-plugins and post-plugins is done using the temma.json file (see the configuration documentation). It is possible to configure global plugins, which will be executed for all requests:

{
    "plugins": {
        // list of pre-plugins */
        "_pre": [
            "AuthenticationPlugin",
            "CmsController"
        ],
        // list of post-plugins
        "_post": [
            "CleanSessionPlugin"
        ]
    }
}

Plugins are executed following the order in which they are declared.

It is possible to configure plugins that will only run for certain controllers:

{
    "plugins": {
        // plugins systematically executed for all controllers
        "_pre": ["AuthenticationPlugin", "CmsController"],
        "_post": ["CleanSessionPlugin"],

        // plugins called only for the homepage controller
        "Homepage": {
            // plugins executed before the controller
            "_pre": ["SomePlugin", "AnotherPlugin"],
            // plugins executed after the controller
            "_post": ["LastPlugin"]
        },

        // plugins called only for the display controller
        "Display": {
            "_post": ["CheckOutputPlugin"]
        }
    }
}

It is even possible to define plugins that will only be called for certain actions:

{
    "plugins": {
        // plugins called only for the homepage controller
        "Homepage": {
            // plugins executed before the controller
            "_pre": ["SomePlugin", "AnotherPlugin"],
            // plugins executed after the controller
            "_post": ["LastPlugin"],

            // plugins for the show action
            "show": {
                // plugins executed before the action
                "_pre": ["SpecialPlugin"],
                // plugins executed after the action
                "_post": ["FooPlugin"]
            },

            // plugins for the remove action
            "remove": {
                // plugins executed before the action
                "_pre": ["BarPlugin"]
            }
        }
    }
}
Previous: Model
Next: Custom plugins

Table of Contents