Yuriy Belenko da9f2f7c9b
[php-slim4] Move config to a separate file (#6971)
* Move config into separated file

* Restrict access from web to config folder

* Exclude config folder from code base

* Update documentation

* Refresh samples

* Fix misplaced pathes
2020-08-29 00:27:03 +08:00

67 lines
2.0 KiB
PHP

<?php
/**
* OpenAPI Petstore
* PHP version 7.2
*
* @package OpenAPIServer
* @author OpenAPI Generator team
* @link https://github.com/openapitools/openapi-generator
*/
/**
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
* The version of the OpenAPI document: 1.0.0
* Generated by: https://github.com/openapitools/openapi-generator.git
*/
/**
* NOTE: This class is auto generated by the openapi generator program.
* https://github.com/openapitools/openapi-generator
*/
require_once __DIR__ . '/vendor/autoload.php';
use OpenAPIServer\SlimRouter;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;
use OpenAPIServer\Mock\OpenApiDataMocker;
// load config file
$config = [];
if (is_array($prodConfig = @include(__DIR__ . '/config/prod/config.inc.php'))) {
$config = $prodConfig;
} elseif (is_array($devConfig = @include(__DIR__ . '/config/dev/config.inc.php'))) {
$config = $devConfig;
} else {
throw new InvalidArgumentException('Config file missed or broken.');
}
$router = new SlimRouter($config);
$app = $router->getSlimApp();
/**
* The routing middleware should be added before the ErrorMiddleware
* Otherwise exceptions thrown from it will not be handled
*/
$app->addRoutingMiddleware();
/**
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
* which can be replaced by a callable of your choice.
* Note: This middleware should be added last. It will not handle any exceptions/errors
* for middleware added after it.
*/
$app->addErrorMiddleware(
$config['slimSettings']['displayErrorDetails'] ?? false,
$config['slimSettings']['logErrors'] ?? true,
$config['slimSettings']['logErrorDetails'] ?? true
);
$app->run();