From bac3e40b66459138c32d70206927b6f58dfe0952 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 14 Aug 2020 14:45:12 +0300 Subject: [PATCH] feat(core): Flextype Solid Core - next round #458 --- src/flextype/app/Endpoints/entries.php | 12 ++++++------ src/flextype/app/Endpoints/files.php | 16 ++++++++-------- src/flextype/app/Endpoints/folders.php | 10 +++++----- src/flextype/app/Endpoints/images.php | 2 +- src/flextype/app/Endpoints/registry.php | 6 +++--- src/flextype/app/Foundation/Cors.php | 9 ++++++--- .../Foundation/Entries/Fields/ParsersField.php | 2 +- .../Parsers/Shortcodes/RegistryShortcode.php | 2 +- .../Support/Parsers/Shortcodes/UrlShortcode.php | 4 ++-- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/flextype/app/Endpoints/entries.php b/src/flextype/app/Endpoints/entries.php index 3a1ffa38..75492911 100644 --- a/src/flextype/app/Endpoints/entries.php +++ b/src/flextype/app/Endpoints/entries.php @@ -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'; diff --git a/src/flextype/app/Endpoints/files.php b/src/flextype/app/Endpoints/files.php index d8fcf685..461054e8 100644 --- a/src/flextype/app/Endpoints/files.php +++ b/src/flextype/app/Endpoints/files.php @@ -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'; diff --git a/src/flextype/app/Endpoints/folders.php b/src/flextype/app/Endpoints/folders.php index 19974903..70a7c01f 100644 --- a/src/flextype/app/Endpoints/folders.php +++ b/src/flextype/app/Endpoints/folders.php @@ -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'; diff --git a/src/flextype/app/Endpoints/images.php b/src/flextype/app/Endpoints/images.php index eabe7b66..baefe5b8 100644 --- a/src/flextype/app/Endpoints/images.php +++ b/src/flextype/app/Endpoints/images.php @@ -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'; diff --git a/src/flextype/app/Endpoints/registry.php b/src/flextype/app/Endpoints/registry.php index fa5d8e78..b1901d41 100644 --- a/src/flextype/app/Endpoints/registry.php +++ b/src/flextype/app/Endpoints/registry.php @@ -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; diff --git a/src/flextype/app/Foundation/Cors.php b/src/flextype/app/Foundation/Cors.php index 4ff32e47..ceb886b7 100644 --- a/src/flextype/app/Foundation/Cors.php +++ b/src/flextype/app/Foundation/Cors.php @@ -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 diff --git a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php index 4e701a41..a23b24f2 100644 --- a/src/flextype/app/Foundation/Entries/Fields/ParsersField.php +++ b/src/flextype/app/Foundation/Entries/Fields/ParsersField.php @@ -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)); diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php index fcc3c3b9..85e9ae40 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php @@ -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')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php index 53e2aa45..b268f992 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php @@ -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();