コード例 #1
0
 /**
  * Forward PAMI event to EventManager.
  *
  * @param EventMessage $e PAMI event
  */
 public function handle(EventMessage $e)
 {
     $eventPrefix = 'event.';
     $eventName = $eventPrefix . $e->getName();
     $event = new PamiEvent();
     $event->setName($eventName);
     $event->setTarget($this->client);
     $event->setEvent($e);
     $this->client->getEventManager()->triggerEvent($event);
 }
コード例 #2
0
 /**
  * Create an object.
  *
  * @param ContainerInterface $container
  * @param string             $requestedName
  * @param null|array         $options
  *
  * @throws \RuntimeException
  * @throws \Interop\Container\Exception\NotFoundException
  * @throws ServiceNotFoundException                       if unable to resolve the service
  * @throws ServiceNotCreatedException                     if an exception is raised when
  *                                                        creating a service
  * @throws ContainerException                             if any other error occurs
  *
  * @return Client
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $options = null;
     $connectionName = $this->getName();
     if ($this->hasOptions($container, 'client', $this->getName())) {
         /** @var ClientOptions $options */
         $options = $this->getOptions($container, 'client');
         $connectionName = $options->getConnection() ?: $this->getName();
     }
     $connectionFactory = new ConnectionFactory($connectionName);
     /** @var Connection $connectionOptions */
     $connectionOptions = $connectionFactory->getOptions($container, 'connection');
     /** @var ClientImpl $connection */
     $connection = $container->get(sprintf('pami.connection.%s', $connectionName));
     $client = new Client($connectionOptions->getHost(), $connection);
     $client->setEventManager($this->createEventManager($container));
     if ($options) {
         $client->setParams($options->getParams());
     }
     $eventForwarder = new EventForwarder($client);
     $client->getConnection()->registerEventListener($eventForwarder);
     return $client;
 }
コード例 #3
0
 public function testSendActionStopped()
 {
     $pami = $this->getMockBuilder('PAMI\\Client\\Impl\\ClientImpl')->disableOriginalConstructor()->setMethods([])->getMock();
     $eventManager = $this->getMockBuilder('Zend\\EventManager\\EventManager')->setMethods(['triggerEventUntil'])->getMock();
     $action = $this->getMockBuilder('PAMI\\Message\\OutgoingMessage')->disableOriginalConstructor()->getMock();
     $response = $this->getMockBuilder('PAMI\\Message\\Response\\ResponseMessage')->disableOriginalConstructor()->getMock();
     $eventResults = $this->getMockBuilder('Zend\\EventManager\\ResponseCollection')->disableOriginalConstructor()->setMethods(['stopped', 'last'])->getMock();
     $eventResults->expects(static::once())->method('stopped')->willReturn(true);
     $eventResults->expects(static::once())->method('last')->willReturn($response);
     /* @var \PAMI\Client\Impl\ClientImpl $pami */
     $client = new Client('host', $pami);
     $client->setEventManager($eventManager);
     $eventManager->expects(static::exactly(1))->method('triggerEventUntil')->with(static::callback(function ($callback) use($response) {
         static::assertFalse($callback(null));
         static::assertFalse($callback('string'));
         static::assertFalse($callback([]));
         static::assertTrue($callback($response));
         return true;
     }), static::isInstanceOf(Event::class))->willReturn($eventResults);
     $result = $client->sendAction($action);
     static::assertSame($response, $result);
 }