/** * The beef of the server * @param string $payload * @param Transport\Input $input * @param Transport\Output $output */ public function handle($payload = null, Transport\Input $input = null, Transport\Output $output = null) { $this->setupErrorHandler(); $this->input = $input ?: new Transport\BasicInput(); $this->output = $output ?: new Transport\BasicOutput(); $payload = $payload ?: $this->input->getPayload(); $request = new Request($payload); $response = new Response(); $worker = new Worker($this->service, $this->functions); try { $request->parse(); foreach ($request->getMessages() as $message) { $response->add($worker->handle($message), $message->id); } } catch (\Exception $e) { $mid = isset($message) && isset($message->id) ? $message->id : null; $response->add($e, $mid); } $response->setBatch($request->isBatch()); $this->output->out($response); $this->restoreErrorHandler(); }