1. Go to this page and download the library: Download earc/event-tree library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
earc / event-tree example snippets
use eArc\Core\Configuration;
use eArc\DI\DI;
DI::init();
Configuration::build();
use eArc\Observer\Interfaces\ListenerInterface;
use eArc\Observer\Interfaces\EventInterface;
class MyListener implements ListenerInterface
{
public function process(EventInterface $event): void
{
// The listener logic goes here...
}
}
use eArc\EventTree\TreeEvent;
class MyEvent extends TreeEvent
{
// Code to handle information specific for your event...
}
use eArc\EventTree\Propagation\PropagationType;
$event = new MyEvent(new PropagationType());
use eArc\Observer\Interfaces\ListenerInterface;
use eArc\Observer\Interfaces\EventInterface;
use eArc\EventTree\Interfaces\SortableListenerInterface;
class MyListener implements ListenerInterface, SortableListenerInterface
{
public function process(EventInterface $event): void
{
// The listener logic goes here...
}
public static function getPatience() : float
{
return -12.7;
}
}
use eArc\Observer\Interfaces\ListenerInterface;
use eArc\Observer\Interfaces\EventInterface;
use eArc\EventTree\Interfaces\PhaseSpecificListenerInterface;
use eArc\EventTree\Interfaces\Transformation\ObserverTreeInterface;
class MyListener implements ListenerInterface, PhaseSpecificListenerInterface
{
public function process(EventInterface $event): void
{
// The listener logic goes here...
}
public static function getPhase() : int
{
// Listening to the phases destination and beyond only.
// Keep in mind it is only one pipe. It is a bit field not a boolean.
return ObserverTreeInterface::PHASE_DESTINATION | ObserverTreeInterface::PHASE_BEYOND;
}
}
use eArc\Observer\Interfaces\ListenerInterface;
use eArc\Observer\Interfaces\EventInterface;
class MyListener implements ListenerInterface
{
public function process(EventInterface $event): void
{
// ...
$event->getHandler()->kill();
// ...
}
}
// ...
$event->getHandler()->forward();
// ...
// ...
$event->getHandler()->terminate();
// ...
// ...
$event->getHandler()->tie();
// ...
use eArc\EventTree\TreeEvent;
use eArc\EventTree\Propagation\PropagationType;
interface ImportInformationInterface
{
public function getRunnerId(): int;
public function addWarning(Exception $exception);
public function getWarnings(): array;
public function getImported(): array;
public function getChanged(): array;
}
class ImportInformation implements ImportInformationInterface
{
protected $runnerId;
protected $warnings = [];
protected $imported = [];
protected $changed = [];
//...
}
class AppRouterEvent extends TreeEvent
{
protected $runtimeInformation;
public function __construct(PropagationType $propagationType)
{
parent::__construct($propagationType);
$this->runtimeInformation = di_get(ImportInformation::class);
}
public function getRI(): ImportInformationInterface {/*...*/}
}