fire() public method

Triggers / Dispatches a new event to the registered event handlers if they have been registered.
public fire ( string $event, mixed $payload, boolean $halt = false ) : mixed
$event string Identification of the event.
$payload mixed Data that is going to be sent to the event handler.
$halt boolean The output of the event handler will be used in a conditional inside the context of where the event is being fired. This means that, if the event handler returns false, it will probably stop the action being executed, for example, "saving".
return mixed Event handler return. The importance of this return is determined by $halt
 public function testShouldReturnTrueIfThereIsNoExternalDispatcher()
 {
     // Arrange
     $dispatcher = m::mock(EventTriggerInterface::class);
     $service = new EventTriggerService();
     // Act
     $dispatcher->shouldReceive('fire')->never();
     // Assertion
     /* without calling registerEventDispatcher */
     $this->assertTrue($service->fire('foobar', ['answer' => 23], true));
 }
Example #2
0
 /**
  * Triggers an event. May return if that event had success.
  *
  * @param string $event  Identification of the event.
  * @param mixed  $entity Event payload.
  * @param bool   $halt   True if the return of the event handler will be used in a conditional.
  *
  * @return mixed Event handler return.
  */
 protected function fireEvent(string $event, $entity, bool $halt = false)
 {
     $event = "mongolid.{$event}: " . get_class($entity);
     $this->eventService ? $this->eventService : ($this->eventService = Ioc::make(EventTriggerService::class));
     return $this->eventService->fire($event, $entity, $halt);
 }