From 6bce7a9841bdae97d9fcf9bf39978f51fc039c44 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sun, 26 Apr 2020 22:39:34 +0300 Subject: [PATCH] refactor(core): new `project` folder instead of `site` BREAKING CHANGES - rename `site` into `project` - use new constant PATH['project'] instead of constant PATH['site'] --- src/flextype/bootstrap.php | 8 ++-- src/flextype/config/settings.yaml | 2 +- src/flextype/core/Cache/Cache.php | 2 +- src/flextype/core/Entries/Entries.php | 6 +-- src/flextype/core/Plugins/Plugins.php | 48 +++++++++---------- src/flextype/dependencies.php | 4 +- src/flextype/endpoints/delivery/entries.php | 4 +- src/flextype/endpoints/delivery/registry.php | 4 +- src/flextype/endpoints/images/images.php | 6 +-- src/flextype/endpoints/management/entries.php | 26 +++++----- 10 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/flextype/bootstrap.php b/src/flextype/bootstrap.php index 3fbbbd23..b6108fba 100755 --- a/src/flextype/bootstrap.php +++ b/src/flextype/bootstrap.php @@ -39,16 +39,16 @@ $registry = new Registry(); * Load flextype settings * * 1. Set settings files paths. - * 2. Load flextype default and flextype custom site settings files. + * 2. Load flextype default and flextype custom project settings files. * 3. Merge settings. * 4. Store settings in the flextype registry. */ $flextype_manifest_file_path = PATH['config'] . '/flextype.yaml'; $default_flextype_settings_file_path = PATH['config'] . '/settings.yaml'; -$custom_flextype_settings_file_path = PATH['site'] . '/config/settings.yaml'; +$custom_flextype_settings_file_path = PATH['project'] . '/config/settings.yaml'; // Create config dir -! Filesystem::has(PATH['site'] . '/config/') and Filesystem::createDir(PATH['site'] . '/config/'); +! Filesystem::has(PATH['project'] . '/config/') and Filesystem::createDir(PATH['project'] . '/config/'); // Set settings if Flextype Default settings config files exist if (! Filesystem::has($default_flextype_settings_file_path)) { @@ -88,7 +88,7 @@ if (($flextype_manifest_content = Filesystem::read($flextype_manifest_file_path) } } -// Merge flextype default settings with custom site settings. +// Merge flextype default settings with custom project settings. $flextype_settings = array_replace_recursive($default_flextype_settings, $custom_flextype_settings, $flextype_manifest); // Store flextype merged settings in the flextype registry. diff --git a/src/flextype/config/settings.yaml b/src/flextype/config/settings.yaml index ca1f9771..27ec7a12 100644 --- a/src/flextype/config/settings.yaml +++ b/src/flextype/config/settings.yaml @@ -1,4 +1,4 @@ -# Set the timezone to be used on the website. +# Set the timezone to be used on the project. # For a list of valid timezone settings, see: # http://php.net/manual/en/timezones.php timezone: UTC diff --git a/src/flextype/core/Cache/Cache.php b/src/flextype/core/Cache/Cache.php index 04486b04..266c14f2 100755 --- a/src/flextype/core/Cache/Cache.php +++ b/src/flextype/core/Cache/Cache.php @@ -67,7 +67,7 @@ class Cache $this->now = time(); // Create cache key to allow invalidate all cache on configuration changes. - $this->key = ($this->flextype['registry']->get('flextype.settings.cache.prefix') ?? 'flextype') . '-' . md5(PATH['site'] . 'Flextype::VERSION'); + $this->key = ($this->flextype['registry']->get('flextype.settings.cache.prefix') ?? 'flextype') . '-' . md5(PATH['project'] . 'Flextype::VERSION'); // Get Cache Driver $this->driver = $this->getCacheDriver(); diff --git a/src/flextype/core/Entries/Entries.php b/src/flextype/core/Entries/Entries.php index 94fc48ed..2c232c4a 100755 --- a/src/flextype/core/Entries/Entries.php +++ b/src/flextype/core/Entries/Entries.php @@ -386,7 +386,7 @@ class Entries // Get entry uid // 1. Remove entries path // 2. Remove left and right slashes - $uid = ltrim(rtrim(str_replace(PATH['site'] . '/entries/', '', $current_entry['path']), '/'), '/'); + $uid = ltrim(rtrim(str_replace(PATH['project'] . '/entries/', '', $current_entry['path']), '/'), '/'); // For each founded entry we should create $entries array. $entry = $this->fetch($uid); @@ -642,7 +642,7 @@ class Entries */ public function getFileLocation(string $id) : string { - return PATH['site'] . '/entries/' . $id . '/entry' . '.' . $this->flextype->registry->get('flextype.settings.entries.extension'); + return PATH['project'] . '/entries/' . $id . '/entry' . '.' . $this->flextype->registry->get('flextype.settings.entries.extension'); } /** @@ -656,6 +656,6 @@ class Entries */ public function getDirLocation(string $id) : string { - return PATH['site'] . '/entries/' . $id; + return PATH['project'] . '/entries/' . $id; } } diff --git a/src/flextype/core/Plugins/Plugins.php b/src/flextype/core/Plugins/Plugins.php index dd45774b..52080d8d 100755 --- a/src/flextype/core/Plugins/Plugins.php +++ b/src/flextype/core/Plugins/Plugins.php @@ -100,24 +100,24 @@ class Plugins $plugin_settings = []; $plugin_manifest = []; $default_plugin_settings = []; - $site_plugin_settings = []; + $project_plugin_settings = []; $default_plugin_manifest = []; // Go through... foreach ($plugins_list as $plugin) { // Set plugin settings directory - $site_plugin_settings_dir = PATH['site'] . '/config/plugins/' . $plugin['dirname']; + $project_plugin_settings_dir = PATH['project'] . '/config/plugins/' . $plugin['dirname']; // Set default plugin settings and manifest files - $default_plugin_settings_file = PATH['site'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; - $default_plugin_manifest_file = PATH['site'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; + $default_plugin_settings_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; - // Set site plugin settings file - $site_plugin_settings_file = PATH['site'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; + // Set project plugin settings file + $project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; - // Create site plugin settings directory - ! Filesystem::has($site_plugin_settings_dir) and Filesystem::createDir($site_plugin_settings_dir); + // Create project plugin settings directory + ! Filesystem::has($project_plugin_settings_dir) and Filesystem::createDir($project_plugin_settings_dir); // Check if default plugin settings file exists if (! Filesystem::has($default_plugin_settings_file)) { @@ -128,16 +128,16 @@ class Plugins $default_plugin_settings_file_content = Filesystem::read($default_plugin_settings_file); $default_plugin_settings = $this->flextype['serializer']->decode($default_plugin_settings_file_content, 'yaml'); - // Create site plugin settings file - ! Filesystem::has($site_plugin_settings_file) and Filesystem::write($site_plugin_settings_file, $default_plugin_settings_file_content); + // Create project plugin settings file + ! Filesystem::has($project_plugin_settings_file) and Filesystem::write($project_plugin_settings_file, $default_plugin_settings_file_content); - // Get site plugin settings content - $site_plugin_settings_file_content = Filesystem::read($site_plugin_settings_file); + // Get project plugin settings content + $project_plugin_settings_file_content = Filesystem::read($project_plugin_settings_file); - if (trim($site_plugin_settings_file_content) === '') { - $site_plugin_settings = []; + if (trim($project_plugin_settings_file_content) === '') { + $project_plugin_settings = []; } else { - $site_plugin_settings = $this->flextype['serializer']->decode($site_plugin_settings_file_content, 'yaml'); + $project_plugin_settings = $this->flextype['serializer']->decode($project_plugin_settings_file_content, 'yaml'); } // Check if default plugin manifest file exists @@ -151,7 +151,7 @@ class Plugins // Merge plugin settings and manifest data $plugins[$plugin['dirname']]['manifest'] = $default_plugin_manifest; - $plugins[$plugin['dirname']]['settings'] = array_replace_recursive($default_plugin_settings, $site_plugin_settings); + $plugins[$plugin['dirname']]['settings'] = array_replace_recursive($default_plugin_settings, $project_plugin_settings); // Check if is not set plugin priority if (! isset($plugins[$plugin['dirname']]['settings']['priority'])) { @@ -200,7 +200,7 @@ class Plugins private function getPluginsDictionary(array $plugins_list, string $locale) : array { foreach ($plugins_list as $plugin) { - $language_file = PATH['site'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml'; + $language_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml'; if (! Filesystem::has($language_file)) { continue; @@ -233,20 +233,20 @@ class Plugins // Go through... if (is_array($plugins_list) && count($plugins_list) > 0) { foreach ($plugins_list as $plugin) { - $default_plugin_settings_file = PATH['site'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; - $default_plugin_manifest_file = PATH['site'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; - $site_plugin_settings_file = PATH['config'] . '/site/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $default_plugin_settings_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; + $project_plugin_settings_file = PATH['config'] . '/project/plugins/' . $plugin['dirname'] . '/settings.yaml'; $f1 = Filesystem::has($default_plugin_settings_file) ? filemtime($default_plugin_settings_file) : ''; $f2 = Filesystem::has($default_plugin_manifest_file) ? filemtime($default_plugin_manifest_file) : ''; - $f3 = Filesystem::has($site_plugin_settings_file) ? filemtime($site_plugin_settings_file) : ''; + $f3 = Filesystem::has($project_plugin_settings_file) ? filemtime($project_plugin_settings_file) : ''; $_plugins_cache_id .= $f1 . $f2 . $f3; } } // Create Unique Cache ID for Plugins - $plugins_cache_id = md5('plugins' . PATH['site'] . '/plugins/' . $_plugins_cache_id); + $plugins_cache_id = md5('plugins' . PATH['project'] . '/plugins/' . $_plugins_cache_id); // Return plugin cache id return $plugins_cache_id; @@ -310,7 +310,7 @@ class Plugins // Get Plugins List $plugins_list = []; - foreach (Filesystem::listContents(PATH['site'] . '/plugins/') as $plugin) { + foreach (Filesystem::listContents(PATH['project'] . '/plugins/') as $plugin) { if ($plugin['type'] !== 'dir') { continue; } @@ -337,7 +337,7 @@ class Plugins continue; } - include_once PATH['site'] . '/plugins/' . $plugin_name . '/bootstrap.php'; + include_once PATH['project'] . '/plugins/' . $plugin_name . '/bootstrap.php'; } } } diff --git a/src/flextype/dependencies.php b/src/flextype/dependencies.php index 0183c4bf..32864e89 100644 --- a/src/flextype/dependencies.php +++ b/src/flextype/dependencies.php @@ -143,7 +143,7 @@ $flextype['images'] = static function ($container) { // Set source filesystem $source = new Filesystem( - new Local(PATH['site'] . '/uploads/entries/') + new Local(PATH['project'] . '/uploads/entries/') ); // Set cache filesystem @@ -153,7 +153,7 @@ $flextype['images'] = static function ($container) { // Set watermarks filesystem $watermarks = new Filesystem( - new Local(PATH['site'] . '/watermarks') + new Local(PATH['project'] . '/watermarks') ); // Set image manager diff --git a/src/flextype/endpoints/delivery/entries.php b/src/flextype/endpoints/delivery/entries.php index d4689e42..07409b93 100644 --- a/src/flextype/endpoints/delivery/entries.php +++ b/src/flextype/endpoints/delivery/entries.php @@ -26,7 +26,7 @@ $api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound' */ function validate_delivery_entries_token($token) : bool { - return Filesystem::has(PATH['site'] . '/tokens/delivery/entries/' . $token . '/token.yaml'); + return Filesystem::has(PATH['project'] . '/tokens/delivery/entries/' . $token . '/token.yaml'); } /** @@ -56,7 +56,7 @@ $app->get('/api/delivery/entries', function (Request $request, Response $respons // Validate delivery token if (validate_delivery_entries_token($token)) { - $delivery_entries_token_file_path = PATH['site'] . '/tokens/delivery/entries/' . $token. '/token.yaml'; + $delivery_entries_token_file_path = PATH['project'] . '/tokens/delivery/entries/' . $token. '/token.yaml'; // Set delivery token file if ($delivery_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_entries_token_file_path), 'yaml')) { diff --git a/src/flextype/endpoints/delivery/registry.php b/src/flextype/endpoints/delivery/registry.php index 2875ab8f..cf607873 100644 --- a/src/flextype/endpoints/delivery/registry.php +++ b/src/flextype/endpoints/delivery/registry.php @@ -25,7 +25,7 @@ $api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound' */ function validate_delivery_registry_token($token) : bool { - return Filesystem::has(PATH['site'] . '/tokens/delivery/registry/' . $token . '/token.yaml'); + return Filesystem::has(PATH['project'] . '/tokens/delivery/registry/' . $token . '/token.yaml'); } /** @@ -53,7 +53,7 @@ $app->get('/api/delivery/registry', function (Request $request, Response $respon // Validate delivery token if (validate_delivery_registry_token($token)) { - $delivery_registry_token_file_path = PATH['site'] . '/tokens/delivery/registry/' . $token . '/token.yaml'; + $delivery_registry_token_file_path = PATH['project'] . '/tokens/delivery/registry/' . $token . '/token.yaml'; // Set delivery token file if ($delivery_registry_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_registry_token_file_path), 'yaml')) { diff --git a/src/flextype/endpoints/images/images.php b/src/flextype/endpoints/images/images.php index 5433bd6e..34849713 100644 --- a/src/flextype/endpoints/images/images.php +++ b/src/flextype/endpoints/images/images.php @@ -20,7 +20,7 @@ use function header; */ function validate_images_token($token) : bool { - return Filesystem::has(PATH['site'] . '/tokens/images/' . $token . '/token.yaml'); + return Filesystem::has(PATH['project'] . '/tokens/images/' . $token . '/token.yaml'); } /** @@ -55,7 +55,7 @@ $app->get('/api/images/{path:.+}', function (Request $request, Response $respons // Validate delivery image token if (validate_images_token($token)) { - $delivery_images_token_file_path = PATH['site'] . '/tokens/images/' . $token . '/token.yaml'; + $delivery_images_token_file_path = PATH['project'] . '/tokens/images/' . $token . '/token.yaml'; // Set delivery token file if ($delivery_images_token_file_data = $flextype['serializer']->decode(Filesystem::read($delivery_images_token_file_path), 'yaml')) { @@ -68,7 +68,7 @@ $app->get('/api/images/{path:.+}', function (Request $request, Response $respons // Update calls counter Filesystem::write($delivery_images_token_file_path, $flextype['serializer']->encode(array_replace_recursive($delivery_images_token_file_data, ['calls' => $delivery_images_token_file_data['calls'] + 1]), 'yaml')); - if (Filesystem::has(PATH['site'] . '/uploads/entries/' . $args['path'])) { + if (Filesystem::has(PATH['project'] . '/uploads/entries/' . $args['path'])) { header('Access-Control-Allow-Origin: *'); return $flextype['images']->getImageResponse($args['path'], $_GET); diff --git a/src/flextype/endpoints/management/entries.php b/src/flextype/endpoints/management/entries.php index 3645cc29..8f01daa8 100644 --- a/src/flextype/endpoints/management/entries.php +++ b/src/flextype/endpoints/management/entries.php @@ -26,7 +26,7 @@ $api_sys_messages['NotFound'] = ['sys' => ['type' => 'Error', 'id' => 'NotFound' */ function validate_management_entries_token($token) : bool { - return Filesystem::has(PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'); + return Filesystem::has(PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'); } /** @@ -34,7 +34,7 @@ function validate_management_entries_token($token) : bool */ function validate_access_token($token) : bool { - return Filesystem::has(PATH['site'] . '/tokens/access/' . $token . '/token.yaml'); + return Filesystem::has(PATH['project'] . '/tokens/access/' . $token . '/token.yaml'); } /** @@ -62,7 +62,7 @@ $app->get('/api/management/entries', function (Request $request, Response $respo if ($flextype['registry']->get('flextype.settings.api.management.entries.enabled')) { // Validate management token if (validate_management_entries_token($token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token. '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token. '/token.yaml'; // Set management token file if ($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) { @@ -134,8 +134,8 @@ $app->post('/api/management/entries', function (Request $request, Response $resp // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; - $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file if (($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) && @@ -219,8 +219,8 @@ $app->patch('/api/management/entries', function (Request $request, Response $res // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; - $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file if (($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) && @@ -304,8 +304,8 @@ $app->put('/api/management/entries', function (Request $request, Response $respo // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; - $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file if (($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) && @@ -390,8 +390,8 @@ $app->put('/api/management/entries/copy', function (Request $request, Response $ // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; - $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file if (($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) && @@ -474,8 +474,8 @@ $app->delete('/api/management/entries', function (Request $request, Response $re // Validate management and access token if (validate_management_entries_token($token) && validate_access_token($access_token)) { - $management_entries_token_file_path = PATH['site'] . '/tokens/management/entries/' . $token . '/token.yaml'; - $access_token_file_path = PATH['site'] . '/tokens/access/' . $access_token . '/token.yaml'; + $management_entries_token_file_path = PATH['project'] . '/tokens/management/entries/' . $token . '/token.yaml'; + $access_token_file_path = PATH['project'] . '/tokens/access/' . $access_token . '/token.yaml'; // Set management and access token file if (($management_entries_token_file_data = $flextype['serializer']->decode(Filesystem::read($management_entries_token_file_path), 'yaml')) &&