'PUT', 'basePathWithoutHost' => '/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r', 'path' => '/fake', 'apiPackage' => 'OpenAPIServer\Api', 'classname' => 'AbstractFakeApi', 'userClassname' => 'FakeApi', 'operationId' => 'testCodeInjectEndRnNR', 'authMethods' => [ ], ], ]; /** * Class constructor * * @param ContainerInterface|array $container Either a ContainerInterface or an associative array of app settings * @throws InvalidArgumentException when no container is provided that implements ContainerInterface */ public function __construct($container = []) { $this->slimApp = new App($container); $basicAuth = new HttpBasicAuthentication([ "secure" => false, "authenticator" => function ($arguments) { $user = $arguments["user"]; $password = $arguments["password"]; return false; } ]); foreach ($this->operations as $operation) { $callback = function ($request, $response, $arguments) use ($operation) { $message = "How about extending {$operation['classname']} by {$operation['apiPackage']}\\{$operation['userClassname']} class implementing {$operation['operationId']} as a {$operation['httpMethod']} method?"; throw new \Exception($message); return $response->withStatus(501)->write($message); }; $middlewares = []; if (class_exists("\\{$operation['apiPackage']}\\{$operation['userClassname']}")) { $callback = "\\{$operation['apiPackage']}\\{$operation['userClassname']}:{$operation['operationId']}"; } foreach ($operation['authMethods'] as $authMethod) { if ($authMethod['type'] === 'http') { $middlewares[] = $basicAuth; } } $this->addRoute( [$operation['httpMethod']], "{$operation['basePathWithoutHost']}{$operation['path']}", $callback, $middlewares )->setName($operation['operationId']); } } /** * Add route with multiple methods * * @param string[] $methods Numeric array of HTTP method names * @param string $pattern The route URI pattern * @param callable|string $callable The route callback routine * @param array|null $middlewares List of middlewares * * @return Slim\Interfaces\RouteInterface * * @throws InvalidArgumentException if the route pattern isn't a string */ public function addRoute($methods, $pattern, $callable, $middlewares = []) { $route = $this->slimApp->map($methods, $pattern, $callable); foreach ($middlewares as $middleware) { $route->add($middleware); } return $route; } /** * Returns Slim Framework instance * @return App */ public function getSlimApp() { return $this->slimApp; } }