public function __invoke(ServiceManagerInterface $serviceManager, array $moreParams = [])
 {
     if (!isset($moreParams['buffer'])) {
         throw new Exception\UnexpectedValueException('Could not parse request.');
     }
     /** @var RequestParser $requestParser */
     $requestParser = $serviceManager->get('RequestParser');
     /** @var Request $request */
     $request = null;
     $requestParser->on(['state'], function (Event $event, $method, $path, $version) use(&$request) {
         $request = Request::create($path, $method);
         $event->getEventEmitter()->on(['header'], function (Event $e, $headerName, $headerValue) use($request) {
             /** @var Request $request */
             $name = \str_replace('-', '_', \strtoupper($headerName));
             if ($name === 'COOKIE') {
                 $cookieData = [];
                 parse_str($headerValue, $cookieData);
                 $request->setCookieParams(new ArrayObject($cookieData));
             } else {
                 $request->setHeader($name, $headerValue);
             }
         });
         $event->getEventEmitter()->on(['body'], function (Event $e, $body) use($request) {
             /** @var Request $request */
             if (!in_array($request->getMethod(), ['GET', 'HEAD']) && !empty($body)) {
                 $postData = [];
                 parse_str($body, $postData);
                 $request->setPostParams(new ArrayObject($postData));
             }
         });
     });
     $requestParser->parse($moreParams['buffer']);
     return $request;
 }
 public function __invoke(ServiceManagerInterface $serviceManager, array $moreParams = [])
 {
     $host = $moreParams[0];
     if (filter_var($host, FILTER_VALIDATE_IP | FILTER_FLAG_IPV6)) {
         return $serviceManager->get('UdpIp6Socket', $moreParams);
     }
     return $serviceManager->get('UdpIp4Socket', $moreParams);
 }
 public function __invoke(ServiceManagerInterface $serviceManager, array $configuration)
 {
     if (isset($configuration['invokables']) && (is_array($configuration['invokables']) || $configuration['invokables'] instanceof Traversable)) {
         foreach ($configuration['invokables'] as $serviceName => $invokable) {
             $serviceManager->registerInvokable($serviceName, $invokable);
         }
     }
     if (isset($configuration['singletons']) && (is_array($configuration['singletons']) || $configuration['singletons'] instanceof Traversable)) {
         foreach ($configuration['singletons'] as $serviceName => $singleton) {
             $serviceManager->registerSingleton($serviceName, $singleton);
         }
     }
     if (isset($configuration['aliases']) && (is_array($configuration['aliases']) || $configuration['aliases'] instanceof Traversable)) {
         foreach ($configuration['aliases'] as $serviceName => $alias) {
             $serviceManager->registerAlias($serviceName, $alias);
         }
     }
     if (isset($configuration['factories']) && (is_array($configuration['factories']) || $configuration['factories'] instanceof Traversable)) {
         foreach ($configuration['factories'] as $serviceName => $factory) {
             //$factory must be a callable if a string is passed attempt to instantiate.
             if (is_string($factory) && class_exists($factory)) {
                 $factory = new $factory();
             }
             $serviceManager->registerFactory($serviceName, $factory);
         }
     }
     if (isset($configuration['initializers']) && (is_array($configuration['initializers']) || $configuration['initializers'] instanceof Traversable)) {
         foreach ($configuration['initializers'] as $initializerName => $initializerConfig) {
             $initializerPriority = 0;
             $initializerClass = null;
             if (is_array($initializerConfig) && isset($initializerConfig['class'])) {
                 $initializerClass = $initializerConfig['class'];
                 if (isset($initializerConfig['priority'])) {
                     $initializerPriority = $initializerConfig['priority'];
                 }
             } else {
                 if (is_string($initializerConfig)) {
                     $initializerClass = $initializerConfig;
                 }
             }
             if ($initializerClass === null) {
                 continue;
             }
             $initializer = new $initializerClass();
             $serviceManager->registerInitializer($initializerName, $initializer, $initializerPriority);
         }
     }
 }