Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Core\Event\Listener Class Reference

Public Member Functions

 __construct (Listenable $source, Array $ids)
 
 addIds (Array $ids)
 
 attach ($listenerId, $callable)
 
 detach ($listenerId, $callable)
 
 detachAll ($listenerId)
 
 listenerExists ($listenerId)
 
 fire ($listenerId, Bucket $data)
 

Protected Attributes

 $_source = null
 
 $_listen = null
 

Detailed Description

Class .

A contrario of events, listeners are synchronous, identified at use and useful for close interactions between one or some components.

Definition at line 393 of file Event.php.

Constructor & Destructor Documentation

Hoa\Core\Event\Listener::__construct ( Listenable  $source,
Array  $ids 
)

Build a listener.

Parameters
\Hoa\Core\Event\Listenable$sourceSource (for Bucket).
array$idsAccepted ID.
Returns
void

Definition at line 418 of file Event.php.

419  {
420  $this->_source = $source;
421  $this->addIds($ids);
422 
423  return;
424  }
addIds(Array $ids)
Definition: Event.php:432

Here is the call graph for this function:

Member Function Documentation

Hoa\Core\Event\Listener::addIds ( Array  $ids)

Add acceptable ID (or reset).

Parameters
array$idsAccepted ID.
Returns
void

Definition at line 432 of file Event.php.

433  {
434  foreach ($ids as $id) {
435  $this->_listen[$id] = [];
436  }
437 
438  return;
439  }

Here is the caller graph for this function:

Hoa\Core\Event\Listener::attach (   $listenerId,
  $callable 
)

Attach a callable to a listenable component.

Parameters
string$listenerIdListener ID.
mixed$callableCallable.
Returns
Exceptions

Definition at line 449 of file Event.php.

450  {
451  if (false === $this->listenerExists($listenerId)) {
452  throw new Core\Exception(
453  'Cannot listen %s because it is not defined.',
454  0,
455  $listenerId
456  );
457  }
458 
459  $callable = xcallable($callable);
460  $this->_listen[$listenerId][$callable->getHash()] = $callable;
461 
462  return $this;
463  }
listenerExists($listenerId)
Definition: Event.php:498

Here is the call graph for this function:

Hoa\Core\Event\Listener::detach (   $listenerId,
  $callable 
)

Detach a callable from a listenable component.

Parameters
string$listenerIdListener ID.
mixed$callableCallable.
Returns

Definition at line 472 of file Event.php.

473  {
474  unset($this->_callable[$listenerId][xcallable($callable)->getHash()]);
475 
476  return $this;
477  }
Hoa\Core\Event\Listener::detachAll (   $listenerId)

Detach all callables from a listenable component.

Parameters
string$listenerIdListener ID.
Returns

Definition at line 485 of file Event.php.

486  {
487  unset($this->_callable[$listenerId]);
488 
489  return $this;
490  }
Hoa\Core\Event\Listener::fire (   $listenerId,
Bucket  $data 
)

Send/fire a bucket to a listener.

Parameters
string$listenerIdListener ID.
\Hoa\Core\Event\Bucket$dataData.
Returns
array
Exceptions

Definition at line 511 of file Event.php.

512  {
513  if (false === $this->listenerExists($listenerId)) {
514  throw new Core\Exception(
515  'Cannot fire on %s because it is not defined.',
516  1
517  );
518  }
519 
520  $data->setSource($this->_source);
521  $out = [];
522 
523  foreach ($this->_listen[$listenerId] as $callable) {
524  $out[] = $callable($data);
525  }
526 
527  return $out;
528  }
listenerExists($listenerId)
Definition: Event.php:498

Here is the call graph for this function:

Hoa\Core\Event\Listener::listenerExists (   $listenerId)

Check if a listener exists.

Parameters
string$listenerIdListener ID.
Returns
bool

Definition at line 498 of file Event.php.

499  {
500  return array_key_exists($listenerId, $this->_listen);
501  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Core\Event\Listener::$_listen = null
protected

Definition at line 407 of file Event.php.

Hoa\Core\Event\Listener::$_source = null
protected

Definition at line 400 of file Event.php.


The documentation for this class was generated from the following file: