1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(endpoints): add Registry endpoints #565

This commit is contained in:
Awilum
2021-08-14 16:47:19 +03:00
parent 8d14c6a747
commit 806d8e159c
3 changed files with 79 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype\Endpoints;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use function count;
use function password_verify;
use function registry;
use function tokens;
class Registry extends Api
{
/**
* Get registry item.
*
* @param ServerRequestInterface $request PSR7 request.
* @param ResponseInterface $response PSR7 response.
*
* @return ResponseInterface Response.
*/
public function get(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Get Request Query Params
$requestQueryParams = $request->getQueryParams();
// Validate Api Request
if (
count($result = $this->validateApiRequest([
'request' => $request,
'api' => 'registry',
'params' => ['token', 'key'],
])) > 0
) {
return $this->getApiResponse($response, $this->getStatusCodeMessage($result['http_status_code']), $result['http_status_code']);
}
// Get registry data
$registryData = registry()->get($requestQueryParams['key'], $requestQueryParams['default'] ?? null);
return $this->getApiResponse($response, ['key' => $requestQueryParams['key'], 'value' => $registryData], 200);
}
}

View File

@@ -453,6 +453,7 @@ require_once ROOT_DIR . '/src/flextype/routes/endpoints/images.php';
require_once ROOT_DIR . '/src/flextype/routes/endpoints/content.php';
require_once ROOT_DIR . '/src/flextype/routes/endpoints/media.php';
require_once ROOT_DIR . '/src/flextype/routes/endpoints/tokens.php';
require_once ROOT_DIR . '/src/flextype/routes/endpoints/registry.php';
// Enable lazy CORS

View File

@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
/**
* Flextype (https://flextype.org)
* Founded by Sergey Romanenko and maintained by Flextype Community.
*/
namespace Flextype;
use Flextype\Endpoints\Registry;
/**
* Get registry item
*
* endpoint: GET /api/registry
*
* Query:
* key - [REQUIRED] - Unique identifier of the registry item key.
* token - [REQUIRED] - Valid public token.
* default - [OPTIONAL] - Default value for registry item key.
*
* Returns:
* An array of registry objects.
*/
app()->get('/api/registry', [Registry::class, 'get']);