options = $options; } public static function initWithPath(string $path): void { if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('%s does not exist', $path)); } self::init(require $path); } public static function init(array $options): void { self::$instance = new self($options); } public static function createServerRequest(): ServerRequestInterface { $serverRequest = self::getApp()->options['server_request']; return $serverRequest(); } public static function getServerRequestFactory(): ServerRequestFactoryInterface { $serverRequest = self::getApp()->options['server_request_factory']; return $serverRequest(); } public static function getResponseFactory(): ResponseFactoryInterface { $responseFactory = self::getApp()->options['response_factory']; return $responseFactory(); } public static function createContainer($definitions, $options): ContainerInterface { if (self::getApp()->container instanceof ContainerInterface) { throw new \LogicException('A container has already been built in ' . self::class); } self::getApp()->container = self::getApp()->options['container']($definitions, $options); return self::getContainer(); } public static function getContainer(): ContainerInterface { return self::getApp()->container; } public static function getCustomEnvironments(): array { return self::getApp()->options['custom_environments']; } private static function getApp(): self { if (self::$instance === null) { throw new \LogicException('Please call ::init() method before get ' . self::class); } return self::$instance; } }