Slim API
This commit is contained in:
@ -1,35 +1,8 @@
|
||||
<?php
|
||||
include_once realpath(dirname(__DIR__, 2) . '/bootstrap/autoload.php');
|
||||
|
||||
$get = $_GET;
|
||||
$post = $_POST;
|
||||
|
||||
function get_keys() {
|
||||
$filename = realpath('./keys');
|
||||
$keys = [];
|
||||
if ($filename !== false) {
|
||||
$keys = json_decode(trim(file_get_contents($filename)));
|
||||
}
|
||||
return $keys;
|
||||
}
|
||||
function validate_key($keys, $key) {
|
||||
if (array_search($key, $keys) !== false) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$keys = get_keys();
|
||||
|
||||
$key = $get['API_KEY'];
|
||||
if (!validate_key($keys, $key)) {
|
||||
throw new Exception('Error en la identificacion.');
|
||||
}
|
||||
|
||||
$p = $get['page'] ?? $get['p'];
|
||||
$a = $get['action'] ?? $get['a'];
|
||||
if ($p == 'precios' and $a == 'importar') {
|
||||
echo json_encode($post);
|
||||
} else {
|
||||
echo route_api();
|
||||
}
|
||||
$__environment = 'api';
|
||||
include_once implode(DIRECTORY_SEPARATOR, [
|
||||
dirname(__DIR__, 2),
|
||||
'setup',
|
||||
'app.php'
|
||||
]);
|
||||
$app->run();
|
||||
|
Reference in New Issue
Block a user