/** * @param string $vendor * @param string $apiVersion * @param bool $debug */ public function __construct($vendor, $apiVersion, $debug = false) { if (!preg_match('#^' . Application::API_VERSION_REG_EXP . '$#', (string) $apiVersion)) { throw new \InvalidArgumentException('Api version is not valid'); } $this->vendor = $vendor; $this->apiVersion = $apiVersion; $this->debug = $debug; $this->setContainer(new Container()); $this->setRouter(new RouteCollection($this->getContainer())); $this->setEventEmitter(new EventEmitter()); $this->setHateoasConfig(new HateoasConfig($debug)); $this->setHateoasService(new HateoasService()); $this->setLoggerConfig(new LoggerConfig('phprest')); $this->setLoggerService(new LoggerService()); $this->setLogHandler(new LogHandler()); $this->setRouterStrategy(new RouterStrategy($this->getContainer())); $errorHandler = new Runner([new JsonXmlFormatter($this)]); $errorHandler->silenceAllErrors(false); $errorHandler->treatErrorsAsExceptions(true); $this->setErrorHandler($errorHandler); }