Single endpoint /validate

parent 2bf58d3f
...@@ -7,10 +7,14 @@ $password = isset($settings['app']['secure_endpoint_password']) ? $settings['app ...@@ -7,10 +7,14 @@ $password = isset($settings['app']['secure_endpoint_password']) ? $settings['app
// Application middleware // Application middleware
// e.g: $app->add(new \Slim\Csrf\Guard); // e.g: $app->add(new \Slim\Csrf\Guard);
$app->getContainer()->get('router') // $app->getContainer()->get('router')
->getNamedRoute('validate.base64') // ->getNamedRoute('validate.base64')
->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password)); // ->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') $app->getContainer()->get('router')
->getNamedRoute('validate.binary') ->getNamedRoute('validate')
->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password)); ->add(new Gr\Gov\Minedu\Osteam\Slim\AuthorizationGuard($username, $password));
...@@ -48,6 +48,34 @@ class App ...@@ -48,6 +48,34 @@ class App
]), 405); ]), 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 @@ ...@@ -2,17 +2,18 @@
$app->get('/validate', '\Gr\Gov\Minedu\Osteam\Slim\App:greet'); $app->get('/validate', '\Gr\Gov\Minedu\Osteam\Slim\App:greet');
$app->post('/validateBase64', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBase64') // $app->post('/validateBase64', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBase64')
->setName('validate.base64'); // ->setName('validate.base64');
$app->post('/validateBinary', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBinary') // $app->post('/validateBinary', '\Gr\Gov\Minedu\Osteam\Slim\App:validateBinary')
->setName('validate.binary'); // ->setName('validate.binary');
$app->post('/validate', '\Gr\Gov\Minedu\Osteam\Slim\App:validate')
->setName('validate');
$app->any('/[{anythingelse}]', function ($request, $response, $args) { $app->any('/[{anythingelse}]', function ($request, $response, $args) {
$this->logger->info("Void response, no action route was enabled"); $this->logger->info("Void response, no action route was enabled");
return $response->withJson([ return $response->withJson([
'message' => 'Your request is not valid', 'message' => 'Your request is not valid',
'in' => var_export($args, true) 'in' => var_export($args, true)
], 404 ], 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