You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpNotFoundException;
use Slim\Factory\AppFactory;
try{
require 'Config/vendor/autoload.php';
/**
* Instantiate App
*/
$app = AppFactory::create();
// Add Routing Middleware
$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
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
try {
$app->get('/', function (Request $request, Response $response) {
$parameters = $request->getQueryParams();
if (empty($parameters['method'])){
throw new TypeError("No method specified");
}else{
$method = $parameters['method'];
}
unset($parameters['method']);
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
foreach ($listGateway as $gateway){
if (method_exists($gateway, $method)) {
$response->getBody()->write(print_r((new $gateway)->$method($parameters)));
}
}
$temp = array('response' => "Rien", 'test' => "Test Ici");
foreach ($temp as $key => $value) {
$response->getBody()->write($key."=>".$value);//'"'.$key.'": "'.$value.'"');
}
//return $response;
return $response->withHeader('Content-type', 'application/json');
});
}catch (TypeError $t){
echo "Error, wrong parameters key, or no parameters write : ".$t->getMessage();
}
// Run app
$app->run();
}catch (HttpNotFoundException $e) {
echo "Error, not Found : " . $e->getMessage();
}