mirror of
https://github.com/flextype/flextype.git
synced 2025-08-10 15:14:20 +02:00
feat(core): Flextype Solid Core - next round #458
This commit is contained in:
@@ -54,7 +54,7 @@ $flextype->get('/api/entries', function (Request $request, Response $response) u
|
||||
$token = $query['token'];
|
||||
$filter = $query['filter'] ?? null;
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries token
|
||||
if (validate_entries_token($token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
@@ -148,7 +148,7 @@ $flextype->post('/api/entries', function (Request $request, Response $response)
|
||||
$id = $post_data['id'];
|
||||
$data = $post_data['data'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
@@ -252,7 +252,7 @@ $flextype->patch('/api/entries', function (Request $request, Response $response)
|
||||
$id = $post_data['id'];
|
||||
$data = $post_data['data'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
@@ -356,7 +356,7 @@ $flextype->put('/api/entries', function (Request $request, Response $response) u
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
@@ -461,7 +461,7 @@ $flextype->put('/api/entries/copy', function (Request $request, Response $respon
|
||||
$id = $post_data['id'];
|
||||
$new_id = $post_data['new_id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
@@ -564,7 +564,7 @@ $flextype->delete('/api/entries', function (Request $request, Response $response
|
||||
$access_token = $post_data['access_token'];
|
||||
$id = $post_data['id'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.entries.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.entries.enabled')) {
|
||||
// Validate entries and access token
|
||||
if (validate_entries_token($token) && validate_access_token($access_token)) {
|
||||
$entries_token_file_path = PATH['project'] . '/tokens/entries/' . $token . '/token.yaml';
|
||||
|
@@ -51,7 +51,7 @@ $flextype->get('/api/files', function (Request $request, Response $response) use
|
||||
$path = $query['path'];
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate delivery token
|
||||
if (validate_files_token($token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -149,7 +149,7 @@ $flextype->post('/api/files', function (Request $request, Response $response) us
|
||||
$folder = $post_data['folder'];
|
||||
$file = $_FILES['file'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -253,7 +253,7 @@ $flextype->put('/api/files', function (Request $request, Response $response) use
|
||||
$path = $post_data['path'];
|
||||
$new_path = $post_data['new_path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -356,7 +356,7 @@ $flextype->put('/api/files/copy', function (Request $request, Response $response
|
||||
$path = $post_data['path'];
|
||||
$new_path = $post_data['new_path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -457,7 +457,7 @@ $flextype->delete('/api/files', function (Request $request, Response $response)
|
||||
$access_token = $post_data['access_token'];
|
||||
$path = $post_data['path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -556,7 +556,7 @@ $flextype->patch('/api/files/meta', function (Request $request, Response $respon
|
||||
$field = $post_data['field'];
|
||||
$value = $post_data['value'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -661,7 +661,7 @@ $flextype->post('/api/files/meta', function (Request $request, Response $respons
|
||||
$field = $post_data['field'];
|
||||
$value = $post_data['value'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
@@ -765,7 +765,7 @@ $flextype->delete('/api/files/meta', function (Request $request, Response $respo
|
||||
$path = $post_data['path'];
|
||||
$field = $post_data['field'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.files.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.files.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_files_token($token) && validate_access_token($access_token)) {
|
||||
$files_token_file_path = PATH['project'] . '/tokens/files/' . $token . '/token.yaml';
|
||||
|
@@ -60,7 +60,7 @@ $flextype->get('/api/folders', function (Request $request, Response $response) u
|
||||
$collection = false;
|
||||
}
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) {
|
||||
// Validate delivery token
|
||||
if (validate_folders_token($token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
@@ -156,7 +156,7 @@ $flextype->post('/api/folders', function (Request $request, Response $response)
|
||||
$access_token = $post_data['access_token'];
|
||||
$path = $post_data['path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_folders_token($token) && validate_access_token($access_token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
@@ -257,7 +257,7 @@ $flextype->put('/api/folders/copy', function (Request $request, Response $respon
|
||||
$path = $post_data['path'];
|
||||
$new_path = $post_data['new_path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_folders_token($token) && validate_access_token($access_token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
@@ -360,7 +360,7 @@ $flextype->put('/api/folders', function (Request $request, Response $response) u
|
||||
$path = $post_data['path'];
|
||||
$new_path = $post_data['new_path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_folders_token($token) && validate_access_token($access_token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
@@ -459,7 +459,7 @@ $flextype->delete('/api/folders', function (Request $request, Response $response
|
||||
$access_token = $post_data['access_token'];
|
||||
$path = $post_data['path'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.folders.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.folders.enabled')) {
|
||||
// Validate files and access token
|
||||
if (validate_folders_token($token) && validate_access_token($access_token)) {
|
||||
$folders_token_file_path = PATH['project'] . '/tokens/folders/' . $token . '/token.yaml';
|
||||
|
@@ -49,7 +49,7 @@ $flextype->get('/api/images/{path:.+}', function (Request $request, Response $re
|
||||
// Set variables
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.images.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.images.enabled')) {
|
||||
// Validate delivery image token
|
||||
if (validate_images_token($token)) {
|
||||
$delivery_images_token_file_path = PATH['project'] . '/tokens/images/' . $token . '/token.yaml';
|
||||
|
@@ -48,7 +48,7 @@ $flextype->get('/api/registry', function (Request $request, Response $response)
|
||||
$id = $query['id'];
|
||||
$token = $query['token'];
|
||||
|
||||
if ($flextype['registry']->get('flextype.settings.api.registry.enabled')) {
|
||||
if ($flextype->container('registry')->get('flextype.settings.api.registry.enabled')) {
|
||||
// Validate token
|
||||
if (validate_registry_token($token)) {
|
||||
$registry_token_file_path = PATH['project'] . '/tokens/registry/' . $token . '/token.yaml';
|
||||
@@ -63,9 +63,9 @@ $flextype->get('/api/registry', function (Request $request, Response $response)
|
||||
}
|
||||
|
||||
// Fetch registry
|
||||
if ($flextype['registry']->has($id)) {
|
||||
if ($flextype->container('registry')->has($id)) {
|
||||
$response_data['data']['key'] = $id;
|
||||
$response_data['data']['value'] = $flextype['registry']->get($id);
|
||||
$response_data['data']['value'] = $flextype->container('registry')->get($id);
|
||||
|
||||
// Set response code
|
||||
$response_code = 200;
|
||||
|
@@ -32,15 +32,18 @@ class Cors
|
||||
*/
|
||||
public function init() : void
|
||||
{
|
||||
if (! $this->flextype->container('registry')->get('flextype.settings.cors.enabled')) {
|
||||
|
||||
$flextype = $this->flextype;
|
||||
|
||||
if (! $flextype->container('registry')->get('flextype.settings.cors.enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->flextype->options('/{routes:.+}', function ($request, $response) {
|
||||
$flextype->options('/{routes:.+}', function ($request, $response) {
|
||||
return $response;
|
||||
});
|
||||
|
||||
$this->flextype->add(function ($req, $res, $next) use ($flextype) {
|
||||
$flextype->add(function ($req, $res, $next) use ($flextype) {
|
||||
$response = $next($req, $res);
|
||||
|
||||
// Set variables
|
||||
|
@@ -28,7 +28,7 @@ function processParsersField($flextype) : void
|
||||
if (isset($flextype->container('entries')->entry['parsers'][$parser_name]['fields'])) {
|
||||
if (is_array($flextype->container('entries')->entry['parsers'][$parser_name]['fields'])) {
|
||||
foreach ($flextype->container('entries')->entry['parsers'][$parser_name]['fields'] as $field) {
|
||||
if (! in_array($field, $flextype['registry']->get('flextype.settings.entries.fields'))) {
|
||||
if (! in_array($field, $flextype->container('registry')->get('flextype.settings.entries.fields'))) {
|
||||
if ($parser_name == 'markdown') {
|
||||
if (Arrays::has($flextype->container('entries')->entry, $field)) {
|
||||
Arrays::set($flextype->container('entries')->entry, $field, $flextype->markdown->parse(Arrays::get($flextype->container('entries')->entry, $field), $cache));
|
||||
|
@@ -13,6 +13,6 @@ if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcode
|
||||
|
||||
// Shortcode: [registry_get name="item-name" default="default-value"]
|
||||
$flextype->container('shortcode')->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) {
|
||||
return $flextype['registry']->get($s->getParameter('name'), $s->getParameter('default'));
|
||||
return $flextype->container('registry')->get($s->getParameter('name'), $s->getParameter('default'));
|
||||
});
|
||||
}
|
||||
|
@@ -14,8 +14,8 @@ if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcode
|
||||
|
||||
// Shortcode: [url]
|
||||
$flextype->container('shortcode')->addHandler('url', function () use ($flextype) {
|
||||
if ($flextype['registry']->has('flextype.settings.url') && $flextype['registry']->get('flextype.settings.url') !== '') {
|
||||
return $flextype['registry']->get('flextype.settings.url');
|
||||
if ($flextype->container('registry')->has('flextype.settings.url') && $flextype->container('registry')->get('flextype.settings.url') !== '') {
|
||||
return $flextype->container('registry')->get('flextype.settings.url');
|
||||
}
|
||||
|
||||
return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl();
|
||||
|
Reference in New Issue
Block a user