registerEventDispatcher() public method

Registers a object that will have the responsibility of firing events to the rest of the application.
public registerEventDispatcher ( Mongolid\Event\EventTriggerInterface $dispatcher ) : void
$dispatcher Mongolid\Event\EventTriggerInterface Event trigger object.
return void
 public function testShouldSendTheEventsToTheExternalDispatcher()
 {
     // Arrange
     $dispatcher = m::mock(EventTriggerInterface::class);
     $service = new EventTriggerService();
     // Act
     $dispatcher->shouldReceive('fire')->once()->with('foobar', ['answer' => 23], true)->andReturn(true);
     // Assertion
     $service->registerEventDispatcher($dispatcher);
     $this->assertTrue($service->fire('foobar', ['answer' => 23], true));
 }
 /**
  * Register MongoDbConnector within the application.
  *
  * @return void
  */
 public function registerConnector()
 {
     $config = $this->app->make('config');
     MongolidIoc::setContainer($this->app);
     $connectionString = $this->buildConnectionString();
     $connection = new Connection($connectionString);
     $pool = new Pool();
     $eventService = new EventTriggerService();
     $eventService->registerEventDispatcher($this->app->make(LaravelEventTrigger::class));
     $pool->addConnection($connection);
     $this->app->instance(Pool::class, $pool);
     $this->app->instance(EventTriggerService::class, $eventService);
     $this->app->bind(CacheComponentInterface::class, function ($app) {
         return new LaravelCacheComponent($app[CacheRepository::class], $app[Serializer::class]);
     });
     $connection->defaultDatabase = $config->get('database.mongodb.default.database', 'mongolid');
 }
Beispiel #3
0
 /**
  * Sets the event trigger for Mongolid events.
  *
  * @param EventTriggerInterface $eventTrigger External event trigger.
  *
  * @return void
  */
 public function setEventTrigger(EventTriggerInterface $eventTrigger)
 {
     $this->init();
     $eventService = new EventTriggerService();
     $eventService->registerEventDispatcher($eventTrigger);
     $this->container->instance(EventTriggerService::class, $eventService);
 }