protected static function callInstance(IService $instance, $method, array $exceptionMappings = []) { try { $result = json_encode(["result" => $instance->{$method}((new Input())->getData())]); header("Content-Length: " . strlen($result)); echo $result; } catch (\Exception $exception) { $exceptionClass = get_class($exception); $httpCode = isset($exceptionMappings[$exceptionClass]) ? $exceptionMappings[$exceptionClass] : 500; $instance->fail($httpCode, $exception->getMessage()); } }
/** * @param IService * @return Container */ public function setService(IService $service) { $this->updating(); $this->services[$service->getEntityClass()] = $service; return $this; }