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:
54
src/flextype/core/Endpoints/Cache.php
Normal file
54
src/flextype/core/Endpoints/Cache.php
Normal 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);
|
||||
}
|
||||
}
|
35
src/flextype/routes/endpoints/cache.php
Normal file
35
src/flextype/routes/endpoints/cache.php
Normal 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');
|
@@ -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';
|
||||
|
||||
|
@@ -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
|
Reference in New Issue
Block a user