コード例 #1
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;
 }