Enlight_Event_Handler_Default example


    public function onPreDispatch(Enlight_Controller_ActionEventArgs $args)
    {
        $this->action = $args->getSubject();
        $this->request = $args->getRequest();
        $this->response = $args->getResponse();

        $this->Application()->Events()->registerListener(
            new Enlight_Event_Handler_Default(
                'Enlight_Controller_Action_PostDispatch',
                [$this, 'onPostDispatch'],
                // Must be positioned before ViewRender Plugin so the ESI renderer can be registered before the template is rendered                 399
            )
        );
    }

    public function renderEsiTag(Enlight_Controller_Request_RequestHttp $request, array $params): ?string
    {
        if (!$this->Plugin()->getActive()) {
            
/** * Initializes this plugin. This Plugin should run after the ViewRenderer Plugin * * @return void */
    public function init()
    {
        if ($this->Collection() === null) {
            return;
        }
        $event = new Enlight_Event_Handler_Default(
            'Enlight_Controller_Action_PostDispatch',
            [$this, 'onPostDispatch'],
            500
        );
        $this->Application()->Events()->registerListener($event);
    }

    /** * Called from the Event Manager after the dispatch process * * @return void */
/** * The Enlight_Event_Subscriber_Array class constructor registers all listeners in the options parameter. * * @param array|null $options */
    public function __construct($options = null)
    {
        if (\is_array($options) && isset($options[0])) {
            foreach ($options as $listener) {
                if (!$listener instanceof Enlight_Event_Handler) {
                    $listener = new Enlight_Event_Handler_Default(
                        $listener['event'],
                        $listener['position'],
                        $listener['listener']
                    );
                }
                $this->registerListener($listener);
            }
        }
    }

    /** * Retrieves a list of listeners registered. * * @return array */

    public function read()
    {
        $this->listeners = [];

        if ($this->storage->listeners !== null) {
            foreach ($this->storage->listeners as $entry) {
                if (!$entry instanceof Enlight_Config) {
                    continue;
                }
                $this->listeners[] = new Enlight_Event_Handler_Default(
                    $entry->name,
                    $entry->position,
                    $entry->listener
                );
            }
        }

        return $this;
    }
}

    public function init()
    {
        if (!$this->Collection()) {
            return;
        }
        $event = new Enlight_Event_Handler_Default(
            'Enlight_Controller_Front_DispatchLoopStartup',
            [$this, 'onDispatchLoopStartup'],
            400
        );
        $this->Application()->Events()->registerListener($event);
        $event = new Enlight_Event_Handler_Default(
            'Enlight_Controller_Action_PostDispatch',
            [$this, 'onPostDispatch'],
            400
        );
        $this->Application()->Events()->registerListener($event);
        
/** * Init this plugin. This Plugin should run before the dispatching process. * * @return void */
    public function init()
    {
        if ($this->Collection() === null) {
            return;
        }
        $event = new Enlight_Event_Handler_Default('Enlight_Controller_Action_PreDispatch', [
            $this, 'onPreDispatch',
        ]);
        $this->Application()->Events()->registerListener($event);
    }

    /** * Called from the event manager before the dispatch process. * Parse the json input data, when it was activated. * * @return void */
    
'onStartDispatch'
        );

        return true;
    }

    /** * Loads the plugin before the dispatch. */
    public function onStartDispatch(Enlight_Event_EventArgs $args)
    {
        $event = new Enlight_Event_Handler_Default(
            'Enlight_Controller_Front_PreDispatch',
            [$this, 'onPreDispatch']
        );
        Shopware()->Events()->registerListener($event);
    }

    /** * Checks the url / the request and passes it around if necessary. */
    public function onPreDispatch(Enlight_Controller_EventArgs $args)
    {
        

    public function addListener($eventName$listener$priority = 0)
    {
        if ($priority === 0) {
            $priority = null;
        }

        $handler = new \Enlight_Event_Handler_Default(
            $eventName,
            $listener,
            $priority
        );

        $this->registerListener($handler);

        return $this;
    }

    /** * Registers the given event handler and adds it to the internal listeners array. * If no event position is set in the event handler, the event handler will be added to the * end of the list. * * @return Enlight_Event_EventManager */

    protected $viewRenderer;

    /** * Plugin install method. * Subscribes the Enlight_Controller_Action_PreDispatch event to * render the script template and set the headers in the response instance. */
    public function init()
    {
        $event = new Enlight_Event_Handler_Default(
            'Enlight_Controller_Action_PreDispatch',
            [$this, 'onPreDispatch'],
            300
        );
        $this->Application()->Events()->registerListener($event);
    }

    /** * Loads the script template, if not set. */
    public function onPreDispatch(Enlight_Event_EventArgs $args)
    {
foreach ($this->listenerIds[$eventName] as list($serviceId$method$priority)) {
            $listener = $this->container->get($serviceId);
            if ($listener === null) {
                continue;
            }

            $key = $serviceId . '.' . $method;
            if (!isset($this->containerListeners[$eventName][$key])) {
                $this->addListener($eventName[$listener$method]$priority);
            } elseif ($listener !== $this->containerListeners[$eventName][$key]) {
                $handler = new Enlight_Event_Handler_Default(
                    $eventName,
                    [$this->containerListeners[$eventName][$key]$method]
                );

                parent::removeListener($handler);
                $this->addListener($eventName[$listener$method]$priority);
            }

            $this->containerListeners[$eventName][$key] = $listener;
        }
    }

    
Home | Imprint | This part of the site doesn't use cookies.