Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Events and listeners: ezpEvent

The in-process event bus of Exponential compared with Symfony's EventDispatcher, Laravel events, Django signals and Spring application events - notify and filter events, registering listeners in site.ini, the events the…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/web-framework-developers/events-and-listeners.md

On this page

Events and listeners: ezpEvent

This page is for developers who subscribe to framework events (Symfony's EventDispatcher, Laravel's Event::listen, Django signals, Rails ActiveSupport::Notifications, Spring @EventListener). Exponential has a small in-process event bus, ezpEvent (kernel/private/classes/ezpevent.php), with two kinds of events: notify events tell listeners that something happened, filter events pass a value through listeners that may change it (Events (ezpEvent)).

Contents

  1. The API
  2. Registering listeners
  3. Events the kernel emits
  4. Rules for listeners
  5. Events, workflows or notifications?
  6. Compared with other frameworks

The API

$events = ezpEvent::getInstance();
$events->attach( 'content/cache', array( 'expDemoListener', 'onContentCache' ) );  // or 'expDemoListener::onContentCache'
$events->notify( 'expdemo/item/stored', array( $itemID ) );                       // tell listeners
$html = $events->filter( 'expdemo/item/html', $html );                             // let listeners change a value

Your own extension can emit its own events with the same calls, so other extensions can hook into it.

Registering listeners

# extension/expdemo/settings/site.ini.append.php
<?php /* #?ini charset="utf-8"?
[Event]
Listeners[]=content/cache@expDemoListener::onContentCache
Listeners[]=response/output@expDemoListener::filterOutput
*/ ?>
  • site.ini [Event] Listeners[] entries are attached for web requests.
  • site.ini [RunnableSettings] Listeners[] entries are attached for commands, cronjob parts and views in every context, the command line included, once per process (Events around run()).
  • site.ini marks [Event] as private API that might change; the kernel's own extensions (ezformtoken) rely on it.

Events the kernel emits

EventKindWhen
request/preinput, request/inputnotifyearly in a web request, with the URI
response/preoutput, response/outputfilterthe final output of a web request
content/viewfilterthe result of a content view
content/view/cachekeysfilterthe keys of the content view cache
content/cache, content/cache/all, content/cache/versionnotifycontent view caches cleared
content/class/cache, content/section/cache, content/state/cachenotifycaches of classes, sections, states cleared
content/state/assignnotifyan object state was assigned
content/edit/access, content/download/access, collaboration/item/accessfilteraccess decisions the kernel asks listeners about
httpcache/store/headersfilterthe headers the HTTP cache keeps with a page
image/alias, image/removeAliases, image/purgeAliasesnotifyimage variations created or removed
session/regenerate, session/destroy, session/gc, session/cleanupnotifysession life cycle
runnable/<kind>/before, runnable/<kind>/afternotify, filteraround every class-based command, cronjob part and view

The list was taken from the calls of ezpEvent::getInstance()->notify() and filter() in kernel/ and lib/; search for them to see the parameters each passes. Setup > RAD's survey lists the events too.

Rules for listeners

  • A filter listener must return the value it was given, changed or not; one that forgets destroys the value.
  • Registrations must be idempotent. Under Velocity a listener attached once per request in a long-lived worker accumulates. Register in settings, or attach in code only once per process.
  • Keep listeners fast. They run inside the request; send slow work to a queue (Queues).
  • Name listeners as Class::method strings so they can be configured.

Events, workflows or notifications?

NeedUse
React in code to a kernel event, always, synchronouslyan ezpEvent listener
Run steps before or after publishing, checkout and other operations, possibly waiting (approval, payment, date), switchable by administratorsa workflow on a trigger (Workflows and triggers)
Tell users by mail about new content or collaboration itemsthe notification system (Notifications)
Real-time messages to browsersVelocity's WebSockets and Server-Sent Events (Velocity WebSockets)

There is no built-in "model saved" event for your own eZPersistentObject classes; emit your own event from your store() or service method.

Compared with other frameworks

FrameworkConceptExponential
Symfonyevent subscribers with priorities, stoppable eventslisteners in Listeners[] order; no stopping, no priorities
Laravelevents and listeners, queued listenerslisteners; queue the work yourself with expqueue
Djangosignals (post_save)kernel events and workflows on content operations
Railscallbacks, notificationsthe same
Springapplication events, @TransactionalEventListenerlisteners; no transaction phases

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x