1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-07 21:56:33 +02:00

feat(endpoints): add cache endpoints

This commit is contained in:
Awilum
2022-05-02 21:44:30 +03:00
parent 2bc66d6f34
commit 9497bd26c4
4 changed files with 97 additions and 1 deletions

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype\Endpoints;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use function count;
use function filesystem;
class Cache extends Api
{
/**
* Clear cache.
*
* @param ServerRequestInterface $request PSR7 request.
* @param ResponseInterface $response PSR7 response.
*
* @return ResponseInterface Response.
*/
public function clear(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
{
// Validate Api Request
if (
count($result = $this->validateApiRequest([
'request' => $request,
'api' => 'cache',
'params' => ['token', 'access_token'],
])) > 0
) {
return $this->getApiResponse($response, $this->getStatusCodeMessage($result['http_status_code']), $result['http_status_code']);
}
// Clear cache
filesystem()->directory(PATH['tmp'])->delete();
// Return success response
return $this->getApiResponse($response, [], 204);
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
/**
* Flextype - Hybrid Content Management System with the freedom of a headless CMS
* and with the full functionality of a traditional CMS!
*
* Copyright (c) Sergey Romanenko (https://awilum.github.io)
*
* Licensed under The MIT License.
*
* For full copyright and license information, please see the LICENSE
* Redistributions of files must retain the above copyright notice.
*/
namespace Flextype;
use Flextype\Endpoints\Cache;
use function app;
/**
* Clear cache.
*
* endpoint: POST /api/v0/cache/clear
*
* Body:
* token - [REQUIRED] - Valid public token.
* access_token - [REQUIRED] - Valid private access token.
*
* Returns:
* Empty body with HTTP status 204
*/
app()->post('/api/v0/cache/clear', [Cache::class, 'clear'])->setName('cache.clear');

View File

@@ -3,7 +3,8 @@
declare(strict_types=1);
// Add endpoints routes
require_once __DIR__ . '/endpoints/utils.php';
require_once __DIR__ . '/endpoints/tokens.php';
require_once __DIR__ . '/endpoints/cache.php';
require_once __DIR__ . '/endpoints/entries.php';
require_once __DIR__ . '/endpoints/registry.php';

View File

@@ -668,3 +668,9 @@ api:
# Set to true to enable Tokens API
enabled: true
# Cache API
tokens:
# Set to true to enable Cache API
enabled: true