How to use

A callable is assigned to a hook using the Slim application’s hook() method:

  1. <?php
  2. $app = new \Slim\Slim();
  3. $app->hook('the.hook.name', function () {
  4. //Do something
  5. });

The first argument is the hook name, and the second argument is the callable. Each hook maintains a prioritylist of registered callables. By default, each callable assigned to a hook is given a priority of 10. You can giveyour callable a different priority by passing an integer as the third parameter of the hook() method:

  1. <?php
  2. $app = new \Slim\Slim();
  3. $app->hook('the.hook.name', function () {
  4. //Do something
  5. }, 5);

The example above assigns a priority of 5 to the callable. When the hook is called, it will sort all callablesassigned to it by priority (ascending). A callable with priority 1 will be invoked before a callable with priority 10.

Hooks do not pass arguments to their callables. If a callable needs to access the Slim application, you can injectthe application into the callback with the use keyword or with the Slim application’s static getInstance() method:

  1. <?php
  2. $app = new \Slim\Slim();
  3. $app->hook('the.hook.name', function () use ($app) {
  4. // Do something
  5. });