/var/www/vhosts/ihelp.ro/httpdocs/vendor/psy/psysh/src/Readline/Hoa
Edit: /var/www/vhosts/ihelp.ro/httpdocs/vendor/psy/psysh/src/Readline/Hoa/Event.php (6085B)
new self(),
self::KEY_SOURCE => null,
];
}
return self::$_register[$eventId][self::KEY_EVENT];
}
/**
* Declares a new object in the observable collection.
* Note: Hoa's libraries use `hoa://Event/anID` for their observable objects.
*/
public static function register(string $eventId, /* Source|string */ $source)
{
if (true === self::eventExists($eventId)) {
throw new EventException('Cannot redeclare an event with the same ID, i.e. the event '.'ID %s already exists.', 0, $eventId);
}
if (\is_object($source) && !($source instanceof EventSource)) {
throw new EventException('The source must implement \Hoa\Event\Source '.'interface; given %s.', 1, \get_class($source));
} else {
$reflection = new \ReflectionClass($source);
if (false === $reflection->implementsInterface('\Psy\Readline\Hoa\EventSource')) {
throw new EventException('The source must implement \Hoa\Event\Source '.'interface; given %s.', 2, $source);
}
}
if (!isset(self::$_register[$eventId][self::KEY_EVENT])) {
self::$_register[$eventId][self::KEY_EVENT] = new self();
}
self::$_register[$eventId][self::KEY_SOURCE] = $source;
}
/**
* Undeclares an object in the observable collection.
*
* If `$hard` is set to `true, then the source and its attached callables
* will be deleted.
*/
public static function unregister(string $eventId, bool $hard = false)
{
if (false !== $hard) {
unset(self::$_register[$eventId]);
} else {
self::$_register[$eventId][self::KEY_SOURCE] = null;
}
}
/**
* Attach an object to an event.
*
* It can be a callable or an accepted callable form (please, see the
* `Hoa\Consistency\Xcallable` class).
*/
public function attach($callable): self
{
$callable = Xcallable::from($callable);
$this->_callable[$callable->getHash()] = $callable;
return $this;
}
/**
* Detaches an object to an event.
*
* Please see `self::attach` method.
*/
public function detach($callable): self
{
unset($this->_callable[Xcallable::from($callable)->getHash()]);
return $this;
}
/**
* Checks if at least one callable is attached to an event.
*/
public function isListened(): bool
{
return !empty($this->_callable);
}
/**
* Notifies, i.e. send data to observers.
*/
public static function notify(string $eventId, EventSource $source, EventBucket $data)
{
if (false === self::eventExists($eventId)) {
throw new EventException('Event ID %s does not exist, cannot send notification.', 3, $eventId);
}
$data->setSource($source);
$event = self::getEvent($eventId);
foreach ($event->_callable as $callable) {
$callable($data);
}
}
/**
* Checks whether an event exists.
*/
public static function eventExists(string $eventId): bool
{
return
\array_key_exists($eventId, self::$_register) &&
self::$_register[$eventId][self::KEY_SOURCE] !== null;
}
}