Skip to content

Filters

John David Manning edited this page Dec 24, 2015 · 2 revisions

Summary

Filters are SECC's form of middle ware. They are classes that are attached to a route and perform logic that returns a boolean value that decides whether the route can be accessed successfully or not.

Creating A Filter

The recommended way to create a filter is using the LACE interface. Use the command filter make:name. This will create a new class in the app/models/filters directory with the specified name and some boiler plate code. All filters need to be under the SECC\Models\Filters namespace in order to be called.

Usage

All filters must contain a main() method. This method must return a true or false value in order to be executed on a route. It may contain any logic you wish to perform prior to executing the route.

Attaching Filters To Routes

To attach a filter to route, open the route's json file and add the "filters" key. The value must be an array. You can attach as many filters as you want to a route's filters array and all filters will need to return true before the route is executed. If you want to attach the premade CSRF filter to a route, your route json file should look like the following...

    {
        "name": "name",  
        "path": "path",  
        "controller": "controller",  
        "method": "method",
        "filters": ["CSRF"]
    }  

Deleting Filters

The recommended way to delete a filter is to use LACE. Use the command filter delete:name. You will of course need to clean up any routes that are making use of the filter. If a route is attempting to call a filter that doesn't exist your application will throw an exception.