|
|
@ -2,10 +2,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
use Slim\Exception\HttpNotFoundException;
|
|
|
|
|
|
|
|
use Slim\Factory\AppFactory;
|
|
|
|
use Slim\Factory\AppFactory;
|
|
|
|
|
|
|
|
|
|
|
|
try{
|
|
|
|
|
|
|
|
require 'Config/vendor/autoload.php';
|
|
|
|
require 'Config/vendor/autoload.php';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -24,11 +23,14 @@ try{
|
|
|
|
* @param bool $logErrorDetails -> Display error details in error log
|
|
|
|
* @param bool $logErrorDetails -> Display error details in error log
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
|
|
|
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Add a route for the API
|
|
|
|
|
|
|
|
*/
|
|
|
|
$app->get('/', function (Request $request, Response $response) {
|
|
|
|
$app->get('/', function (Request $request, Response $response) {
|
|
|
|
$parameters = $request->getQueryParams();
|
|
|
|
$parameters = $request->getQueryParams();
|
|
|
|
if (empty($parameters['method'])){
|
|
|
|
if (empty($parameters['method'])){
|
|
|
|
throw new TypeError("No method specified");
|
|
|
|
throw new TypeErrorMethod($request);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
$method = $parameters['method'];
|
|
|
|
$method = $parameters['method'];
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -36,7 +38,7 @@ try{
|
|
|
|
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
|
|
|
|
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
|
|
|
|
foreach ($listGateway as $gateway){
|
|
|
|
foreach ($listGateway as $gateway){
|
|
|
|
if (method_exists($gateway, $method)) {
|
|
|
|
if (method_exists($gateway, $method)) {
|
|
|
|
$response->getBody()->write(print_r((new $gateway)->$method($parameters)));
|
|
|
|
$response->getBody()->write(json_encode((new $gateway)->$method($parameters)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$temp = array(0 => array("id" => "1",
|
|
|
|
$temp = array(0 => array("id" => "1",
|
|
|
@ -49,14 +51,7 @@ try{
|
|
|
|
$response->getBody()->write(json_encode($temp));
|
|
|
|
$response->getBody()->write(json_encode($temp));
|
|
|
|
return $response->withHeader('Content-type', 'application/json');
|
|
|
|
return $response->withHeader('Content-type', 'application/json');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}catch (TypeError $t){
|
|
|
|
|
|
|
|
echo "Error, wrong parameters key, or no parameters write : ".$t->getMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Run app
|
|
|
|
// Run app
|
|
|
|
$app->run();
|
|
|
|
$app->run();
|
|
|
|
}catch (HttpNotFoundException $e) {
|
|
|
|
|
|
|
|
echo "Error, not Found : " . $e->getMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|