issues within PHP projects and libraries bring communities together since 2009 • Strives for greater interoperability for PHP projects • Consists of a Core Committee, Secretaries and Member Project Representatives • PSR = PHP Standards Recommendation • If you’ve ever used PHP seriously in the last 5 years, you’ve already used PSRs
just wanted to let you know” • Object enhancement - “Something is about to happen, add/modify before I do it” • Collection - “Give me all your things, I may do something with it” • Alternative Chain - “Something is about to happen, check if somebody can do it” • Event Sourcing - out-of-scope
an object or a call-by-reference array ◦ a string as identifier - some add a final class Events { const BEFORE_INSERT = ‘beforeInsert’; } ◦ Could have arguments / properties via new EventArgs() • Listener ◦ Some call it observers, or subscribers ◦ Do something now or maybe later (deferred) • Listener Provider ◦ Collects all listeners • Event Dispatcher - send the message ◦ Executes registered listeners in the callers code (Emitter) ◦ Want to do with the results?
a PHP object ◦ No strings, no FQDN of Classes, no “anonymous” events with just arguments ◦ No “event name” ◦ Inheritance of classes / interfaces “built-in” already via PHP core • Separate dispatching and listener registration • Immutability cannot be ensured by interfaces ◦ Return the event object that is given back again to the caller
after processing, returns it back. interface EventDispatcherInterface { /** * @param object $event * The object to process. * * @return object * The Event that was passed, now modified by listeners. */ public function dispatch( object $event); }
the system and injects them into the dispatcher interface ListenerProviderInterface { /** * @return iterable[callable] * An iterable (array, iterator, or generator) of callables. Each * callable MUST be type-compatible with $event. */ public function getListenersForEvent( object $event) : iterable; }
convention” providers possible onRequestStart(RequestStartEvent $evt) • Gather all available listeners at compile time? Done. • Libraries can build dependency concepts or priority / ordering concepts (0-100 vs. “after plugin XYZ”) • Collect multiple providers together in one (AggregateProvider)
class MyTemplateNameModifierEvent { private $templateName; public function __construct(string $templateName) { $this->templateName = $templateName; } public function getTemplateName() : string; public function setTemplateName(string $templateName) : void; }
something else - but only for the late night visitors class MyListener { public function lateNightTemplate(MyTemplateNameModifierEvent $evt) { if (date(‘G’) >= 18) { $evt->setTemplateName(‘tmpl/LateNight.html’); } return $evt; } }
can use one generic EventDispatcher, and pull in sources from all kinds of places • So extensions can actually just hook into Symfony components the same way as in TYPO3 • TYPO3 has all available events documented and objectified • Old “hooks” will just become listeners
what kind of information an event contains • I know what I can change for a mutable event • I know that it’s the same concept for all the PHP libraries I use (hopefully)
& ReactPHP have PoCs • Use events for things there are no good solutions yet ◦ Authentication chains can be built as events • Check out the blog series on PSR-14 by @Crell ◦ make sure to follow him on Twitter and Steemit (https://steemit.com/@crell/)