Fuel\Event\EventTrait::on PHP Method

on() public method

Attaches a new event.
public on ( string $event, callable $handler, mixed $context = null, $priority ) : object
$event string event name
$handler callable event handler
$context mixed closure context
return object $this
    public function on($event, $handler, $context = null, $priority = 0)
    {
        // Check wether a priority is
        // given in place of a context.
        if (is_int($context)) {
            // Switch then around
            $priority = $context;
            $context = null;
        }
        // When the object is self binding
        if ($context === null and $this->_eventBindSelf) {
            // Set the context to $this
            $context = $this;
        }
        // Ensure there is a Container
        $this->_eventContainer or $this->_eventContainer = new Container();
        // Add the event
        $this->_eventContainer->on($event, $handler, $context, $priority);
        // Remain chainable
        return $this;
    }