/** * 构造方法 */ public function __construct(Request $request = null) { $request = $request ?: Request::createFromGlobals(); $content = $request->getContent(); try { $options = Serializer::parse($content); } catch (\InvalidArgumentException $e) { $options = array(); } parent::__construct($options); }
/** * handle event via request */ public function handle(EventListenerInterface $listener) { if (!$listener->getListeners()) { return; } $content = $this->request->getContent(); try { $options = Serializer::parse($content); } catch (\InvalidArgumentException $e) { $options = array(); } foreach ($listener->getListeners() as $namespace => $callable) { $event = new $namespace($options); if ($event->isValid()) { $listener->trigger($namespace, $event); break; } } }
/** * Send Request */ public function send($asArray = true) { $options = array(); // query if (!empty($this->query)) { $options['query'] = $this->query; } // body if (!empty($this->body)) { $options['body'] = $this->body; } // ssl cert if ($this->sslCert && $this->sslKey) { $options['cert'] = $this->sslCert; $options['ssl_key'] = $this->sslKey; } $response = (new Client())->request($this->method, $this->uri, $options); $contents = $response->getBody()->getContents(); if (!$asArray) { return $contents; } $array = Serializer::parse($contents); return new ArrayCollection($array); }