Single endpoint /validate

parent 2bf58d3f
......@@ -7,10 +7,14 @@ $password = isset($settings['app']['secure_endpoint_password']) ? $settings['app
// Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard);
$app->getContainer()->get('router')
->getNamedRoute('validate.base64')
->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password));
// $app->getContainer()->get('router')
// ->getNamedRoute('validate.base64')
// ->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password));
// $app->getContainer()->get('router')
// ->getNamedRoute('validate.binary')
// ->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password));
$app->getContainer()->get('router')
->getNamedRoute('validate.binary')
->getNamedRoute('validate')
->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password));
......@@ -48,6 +48,34 @@ class App
]), 405);
}
/**
* Έλεγχος.
*
* @param Psr\Http\Message\ServerRequestInterface $req
* @param Psr\Http\Message\ResponseInterface $res
* @param array $args
* @throws \Exception
* @return Response
*/
public function validate($req, $res, $args)
{
$media_type = $req->getMediaType();
switch ($media_type) {
case 'multipart/form-data':
return $this->validateBinary($req, $res, $args);
break;
case 'application/json':
return $this->validateBase64($req, $res, $args);
break;
default:
return $res->withJson(array_merge($this->coreResponseData(false), [
'message' => "Unhandled media type [" . $media_type . ']'
]), 415);
break;
}
}
/**
* Έλεγχος.
*
......
......@@ -2,17 +2,18 @@
$app->get('/validate', '\Gr\Gov\Minedu\Osteam\Slim\App:greet');
$app->post('/validateBase64', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBase64')
->setName('validate.base64');
$app->post('/validateBinary', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBinary')
->setName('validate.binary');
// $app->post('/validateBase64', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBase64')
// ->setName('validate.base64');
// $app->post('/validateBinary', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBinary')
// ->setName('validate.binary');
$app->post('/validate', '\Gr\Gov\Minedu\Osteam\Slim\App:validate')
->setName('validate');
$app->any('/[{anythingelse}]', function ($request, $response, $args) {
$this->logger->info("Void response, no action route was enabled");
return $response->withJson([
'message' => 'Your request is not valid',
'in' => var_export($args, true)
], 404
);
'message' => 'Your request is not valid',
'in' => var_export($args, true)
], 404);
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment