Ejemplo n.º 1
0
 protected function injectRequestIntoResponder()
 {
     if ($this->responder->getRequest()) {
         return;
     }
     $request = $this->getRequest();
     $this->responder->setRequest($request);
 }
 /**
  * Create service with name
  *
  * @param ServiceLocatorInterface $controllers
  * @param string                  $name
  * @param string                  $requestedName
  * @return TwilioController
  * @throws ServiceNotCreatedException if listener specified is not a ListenerAggregate
  */
 public function createServiceWithName(ServiceLocatorInterface $controllers, $name, $requestedName)
 {
     $services = $this->resolveServiceLocator($controllers);
     $config = $this->resolveConfig($services, $name, $requestedName);
     $listener = $this->getListener($services, $config['listener']);
     if (!$listener instanceof ListenerAggregateInterface) {
         throw new ServiceNotCreatedException(sprintf('%s expects that the "listener" reference a service that implements ' . 'Zend\\EventManager\\ListenerAggregateInterface; received %s', __METHOD__, is_object($listener) ? get_class($listener) : gettype($listener)));
     }
     $resourceIdentifiers = array(get_class($listener));
     $events = $services->get('EventManager');
     $events->attach($listener);
     $events->setIdentifiers($resourceIdentifiers);
     $responder = new Responder();
     $responder->setEventManager($events);
     $identifier = $requestedName;
     $controllerClass = isset($config['controller_class']) ? $config['controller_class'] : 'Synrg\\Twilio\\Controller\\TwilioController';
     $controller = new $controllerClass($identifier);
     if (!$controller instanceof TwilioController) {
         throw new ServiceNotCreatedException(sprintf('"%s" must be an implementation of Synrg\\Twilio\\Controller\\TwilioController', $controllerClass));
     }
     $controller->setResponder($responder);
     return $controller;
 }