$outputHandler->addContent('<ul>'); for ($n = 0; $n < 10; $n++) { $outputHandler->addContent('<li>' . $n . '</li>'); } $outputHandler->addContent('</ul>'); })->attachEventHandler('onDisplayOutput', function () use($outputHandler) { $outputHandler->setHtmlMode(ENT_XHTML); })->attachEventHandler('onBeforeDisplayOutput', function () use($outputHandler) { $outputHandler->setEncoding('ISO-8859-1'); })->attachEventHandler('onBeforeDisplayOutput', function () use($outputHandler) { foreach ($outputHandler->content as $line => $content) { $outputHandler->content[$line] = htmlentities($content, $outputHandler->getHtmlMode(), $outputHandler->getEncoding()); } })->attachEventHandler('onDisplayOutput', function () use($outputHandler, $em) { //execute onBeforeDisplayOutput event $em->triggerEvent('onBeforeDisplayOutput'); $outputHandler->display('<br />'); }, 100)->attachEventHandler('onDisplayOutput', function () use($outputHandler) { echo 'Attach after but execute before'; }, 5000); Logger::getInstance()->addMessage('attaching complete'); Logger::getInstance()->addMessage('triggering start'); //assign output $em->triggerEvent('onAssignOutput'); //display output $em->triggerEvent('onDisplayOutput'); $em->triggerEvent('onUnknown'); Logger::getInstance()->addMessage('triggering complete'); echo "<pre>"; echo Logger::getInstance()->toText(); echo "</pre>";
} class CustomObject { function anEventCallbackAsMethod($e) { echo __FUNCTION__ . ': Some logic'; } } echo 'attach aggregate'; $em->attachEventHandler(new CustomEventAggregate()); $em->attachEventHandler('another.events', array('anEventCallbackAsFunction')); $em->attachEventHandler('another.events', array(new CustomObject(), 'anEventCallbackAsMethod')); print_r($em->getEventHandlers()); echo '<b>trigger custom.eventName.foo</b>'; $em->triggerEvent('custom.eventName.foo', [], function ($responses) { print_r($responses); return false; }); echo '<b>trigger custom.eventName.bar</b>'; $em->triggerEvent('custom.eventName.bar', [], function ($responses) { print_r($responses); return false; }); echo '<b>trigger another.events</b>'; $em->triggerEvent('another.events', [], function ($responses) { print_r($responses); return false; }); echo '</pre>'; echo "<pre>"; echo Logger::getInstance()->toText(); echo "</pre>";