diff --git a/index.php b/index.php index f8f74c0a..14b9a206 100755 --- a/index.php +++ b/index.php @@ -44,7 +44,7 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s /** * Ensure vendor libraries exist */ -! is_file($flextype_autoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: composer install for flextype'); +! is_file($flextypeAutoload = __DIR__ . '/vendor/autoload.php') and exit('Please run: composer install for flextype'); /** * Register The Auto Loader @@ -55,7 +55,7 @@ version_compare($ver = PHP_VERSION, $req = FLEXTYPE_MINIMUM_PHP, '<') and exit(s * loading any of our classes later on. It feels nice to relax. * Register The Auto Loader */ -$flextype_loader = require_once $flextype_autoload; +$flextypeLoader = require_once $flextypeAutoload; /** * Bootstraps the Flextype diff --git a/src/flextype/Foundation/Entries/Fields/ParsersField.php b/src/flextype/Foundation/Entries/Fields/ParsersField.php index b2c7d7fb..48af99b3 100644 --- a/src/flextype/Foundation/Entries/Fields/ParsersField.php +++ b/src/flextype/Foundation/Entries/Fields/ParsersField.php @@ -15,59 +15,38 @@ if (flextype('registry')->get('flextype.settings.entries.fields.parsers.enabled' function processParsersField(): void { - if (flextype('entries')->getStorage('fetch.data.cache.enabled') === null) { + if (flextype('entries')->getStorage('fetch.data.cache.enabled') == null) { $cache = false; } else { $cache = (bool) flextype('entries')->getStorage('fetch.data.cache.enabled'); } - if (flextype('entries')->getStorage('fetch.data.parsers') === null) { - return; - } - - foreach (flextype('entries')->getStorage('fetch.data.parsers') as $parser_name => $parser_data) { - if (! in_array($parser_name, ['markdown', 'shortcode'])) { - continue; - } - - if (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.enabled') !== true) { - continue; - } - - if (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields') === null) { - continue; - } - - if (! is_array(flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields'))) { - continue; - } - - foreach (flextype('entries')->getStorage('fetch.data.parsers.' . $parser_name . '.fields') as $field) { - if (in_array($field, flextype('registry')->get('flextype.settings.entries.fields'))) { - continue; - } - - if ($parser_name === 'markdown') { - if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) { - flextype('entries')->setStorage( - 'fetch.data.' . $field, - flextype('markdown')->parse(flextype('entries')->getStorage('fetch.data.' . $field), $cache) - ); + if (flextype('entries')->getStorage('fetch.data.parsers') != null) { + foreach (flextype('entries')->getStorage('fetch.data.parsers') as $parserName => $parserData) { + if (in_array($parserName, ['markdown', 'shortcode'])) { + if (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.enabled') === true) { + if (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields') != null) { + if (is_array(flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields'))) { + foreach (flextype('entries')->getStorage('fetch.data.parsers.'.$parserName.'.fields') as $field) { + if (! in_array($field, flextype('registry')->get('flextype.settings.entries.fields'))) { + if ($parserName == 'markdown') { + if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) { + flextype('entries')->setStorage('fetch.data.'.$field, + flextype('markdown')->parse(flextype('entries')->getStorage('fetch.data.'.$field), $cache)); + } + } + if ($parserName == 'shortcode') { + if (arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) { + flextype('entries')->setStorage('fetch.data.'.$field, + flextype('shortcode')->process(flextype('entries')->getStorage('fetch.data.'.$field), $cache)); + } + } + } + } + } + } } } - - if ($parser_name !== 'shortcode') { - continue; - } - - if (! arrays(flextype('entries')->getStorage('fetch.data'))->has($field)) { - continue; - } - - flextype('entries')->setStorage( - 'fetch.data.' . $field, - flextype('shortcode')->process(flextype('entries')->getStorage('fetch.data.' . $field), $cache) - ); } } } diff --git a/src/flextype/Foundation/Helpers/FlextypeHelper.php b/src/flextype/Foundation/Helpers/FlextypeHelper.php index c8f5c0b4..fd690438 100644 --- a/src/flextype/Foundation/Helpers/FlextypeHelper.php +++ b/src/flextype/Foundation/Helpers/FlextypeHelper.php @@ -14,12 +14,12 @@ if (! function_exists('flextype')) { * Get the available Flextype Application instance * or try to get Dependency Injection Container if $container is not null. */ - function flextype($container_name = null, $container = []) + function flextype($containerName = null, $container = []) { - if (is_null($container_name)) { + if (is_null($containerName)) { return Flextype::getInstance($container); } - return Flextype::getInstance($container)->container($container_name); + return Flextype::getInstance($container)->container($containerName); } } diff --git a/src/flextype/Foundation/Media/MediaFiles.php b/src/flextype/Foundation/Media/MediaFiles.php index b8748b81..049acf65 100644 --- a/src/flextype/Foundation/Media/MediaFiles.php +++ b/src/flextype/Foundation/Media/MediaFiles.php @@ -62,27 +62,27 @@ class MediaFiles */ public function upload(array $file, string $folder) { - $upload_folder = PATH['project'] . '/uploads/' . $folder . '/'; - $upload_metadata_folder = PATH['project'] . '/uploads/.meta/' . $folder . '/'; + $uploadFolder = PATH['project'] . '/uploads/' . $folder . '/'; + $uploadMetadataFolder = PATH['project'] . '/uploads/.meta/' . $folder . '/'; - if (! filesystem()->directory($upload_folder)->exists()) { - filesystem()->directory($upload_folder)->create(0755, true); + if (! filesystem()->directory($uploadFolder)->exists()) { + filesystem()->directory($uploadFolder)->create(0755, true); } - if (! filesystem()->directory($upload_metadata_folder)->exists()) { - filesystem()->directory($upload_metadata_folder)->create(0755, true); + if (! filesystem()->directory($uploadMetadataFolder)->exists()) { + filesystem()->directory($uploadMetadataFolder)->create(0755, true); } - $accept_file_types = flextype('registry')->get('flextype.settings.media.accept_file_types'); - $max_file_size = flextype('registry')->get('flextype.settings.media.max_file_size'); - $safe_names = flextype('registry')->get('flextype.settings.media.safe_names'); - $max_image_width = flextype('registry')->get('flextype.settings.media.max_image_width'); - $max_image_height = flextype('registry')->get('flextype.settings.media.max_image_height'); + $acceptFileTypes = flextype('registry')->get('flextype.settings.media.accept_file_types'); + $maxFileSize = flextype('registry')->get('flextype.settings.media.max_file_size'); + $safeNames = flextype('registry')->get('flextype.settings.media.safe_names'); + $maxImageWidth = flextype('registry')->get('flextype.settings.media.max_image_width'); + $maxImageHeight = flextype('registry')->get('flextype.settings.media.max_image_height'); $exact = false; $chmod = 0644; $filename = null; - $exif_data = []; + $exifData = []; // Tests if a successful upload has been made. if ( @@ -100,16 +100,16 @@ class MediaFiles and isset($file['size']) ) { // Test if an uploaded file is an allowed file type, by extension. - if (strpos($accept_file_types, strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) !== false) { + if (strpos($acceptFileTypes, strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) !== false) { // Validation rule to test if an uploaded file is allowed by file size. if ( ($file['error'] !== UPLOAD_ERR_INI_SIZE) and ($file['error'] === UPLOAD_ERR_OK) - and ($file['size'] <= $max_file_size) + and ($file['size'] <= $maxFileSize) ) { // Validation rule to test if an upload is an image and, optionally, is the correct size. if (in_array(mime_content_type($file['tmp_name']), ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) { - if ($this->validateImage($file, $max_image_width, $max_image_height, $exact) === false) { + if ($this->validateImage($file, $maxImageWidth, $maxImageHeight, $exact) === false) { return false; } } @@ -124,17 +124,17 @@ class MediaFiles $filename = $file['name']; } - if ($safe_names === true) { + if ($safeNames === true) { // Remove spaces from the filename $filename = flextype('slugify')->slugify(pathinfo($filename)['filename']) . '.' . pathinfo($filename)['extension']; } - if (! is_dir($upload_folder) or ! is_writable(realpath($upload_folder))) { - throw new RuntimeException("Directory {$upload_folder} must be writable"); + if (! is_dir($uploadFolder) or ! is_writable(realpath($uploadFolder))) { + throw new RuntimeException("Directory {$uploadFolder} must be writable"); } // Make the filename into a complete path - $filename = realpath($upload_folder) . DIRECTORY_SEPARATOR . $filename; + $filename = realpath($uploadFolder) . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($file['tmp_name'], $filename)) { // Set permissions on filename chmod($filename, $chmod); @@ -167,13 +167,13 @@ class MediaFiles // destroy $img->destroy(); - $exif_data = []; + $exifData = []; try { $headers = @exif_read_data($filename); if ($headers !== false) { foreach ($headers['COMPUTED'] as $header => $value) { - $exif_data[$header] = $value; + $exifData[$header] = $value; } } } catch (RuntimeException $e) { @@ -187,11 +187,11 @@ class MediaFiles 'type' => mime_content_type($filename), 'filesize' => filesystem()->file($filename)->size(), 'uploaded_on' => time(), - 'exif' => $exif_data, + 'exif' => $exifData, ]; filesystem() - ->file($upload_metadata_folder . basename($filename) . '.yaml') + ->file($uploadMetadataFolder . basename($filename) . '.yaml') ->put(flextype('yaml')->encode($metadata)); // Return new file path @@ -228,12 +228,12 @@ class MediaFiles $result['url'] = 'project/uploads/' . $path; if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { - $full_url = flextype('registry')->get('flextype.settings.url'); + $fullUrl = flextype('registry')->get('flextype.settings.url'); } else { - $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); + $fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } - $result['full_url'] = $full_url . '/project/uploads/' . $path; + $result['full_url'] = $fullUrl . '/project/uploads/' . $path; } $result = filter($result, $options); @@ -264,12 +264,12 @@ class MediaFiles $result[$basename]['url'] = 'project/uploads/' . $path . '/' . $basename; if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { - $full_url = flextype('registry')->get('flextype.settings.url'); + $fullUrl = flextype('registry')->get('flextype.settings.url'); } else { - $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); + $fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } - $result[$basename]['full_url'] = $full_url . '/project/uploads/' . $path . '/' . $basename; + $result[$basename]['full_url'] = $fullUrl . '/project/uploads/' . $path . '/' . $basename; } $result = filter($result, $options); @@ -281,17 +281,17 @@ class MediaFiles * Move file * * @param string $id Unique identifier of the file. - * @param string $new_id New Unique identifier of the file. + * @param string $newID New Unique identifier of the file. * * @return bool True on success, false on failure. * * @access public */ - public function move(string $id, string $new_id): bool + public function move(string $id, string $newID): bool { - if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) { - return filesystem()->file($this->getFileLocation($id))->move($this->getFileLocation($new_id)) && - filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($new_id)); + if (! filesystem()->file($this->getFileLocation($newID))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists()) { + return filesystem()->file($this->getFileLocation($id))->move($this->getFileLocation($newID)) && + filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->move(flextype('media_files_meta')->getFileMetaLocation($newID)); } return false; @@ -331,20 +331,20 @@ class MediaFiles * Copy file * * @param string $id Unique identifier of the file. - * @param string $new_id New Unique identifier of the file. + * @param string $newID New Unique identifier of the file. * * @return bool True on success, false on failure. * * @access public */ - public function copy(string $id, string $new_id): bool + public function copy(string $id, string $newID): bool { - if (! filesystem()->file($this->getFileLocation($new_id))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists()) { - filesystem()->file($this->getFileLocation($id))->copy($this->getFileLocation($new_id)); - filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($new_id)); + if (! filesystem()->file($this->getFileLocation($newID))->exists() && ! filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists()) { + filesystem()->file($this->getFileLocation($id))->copy($this->getFileLocation($newID)); + filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($id))->copy(flextype('media_files_meta')->getFileMetaLocation($newID)); - return filesystem()->file($this->getFileLocation($new_id))->exists() && - filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($new_id))->exists(); + return filesystem()->file($this->getFileLocation($newID))->exists() && + filesystem()->file(flextype('media_files_meta')->getFileMetaLocation($newID))->exists(); } return false; @@ -367,7 +367,7 @@ class MediaFiles /** * Validate Image */ - protected function validateImage($file, $max_image_width, $max_image_height, $exact) + protected function validateImage($file, $maxImageWidth, $maxImageHeight, $exact) { try { // Get the width and height from the uploaded image @@ -381,22 +381,22 @@ class MediaFiles return false; } - if (! $max_image_width) { + if (! $maxImageWidth) { // No limit, use the image width - $max_image_width = $width; + $maxImageWidth = $width; } - if (! $max_image_height) { + if (! $maxImageHeight) { // No limit, use the image height - $max_image_height = $height; + $maxImageHeight = $height; } if ($exact) { // Check if dimensions match exactly - return $width === $max_image_width and $height === $max_image_height; + return $width === $maxImageWidth and $height === $maxImageHeight; } // Check if size is within maximum dimensions - return $width <= $max_image_width and $height <= $max_image_height; + return $width <= $maxImageWidth and $height <= $maxImageHeight; } } diff --git a/src/flextype/Foundation/Media/MediaFilesMeta.php b/src/flextype/Foundation/Media/MediaFilesMeta.php index d537b9f0..2142cc48 100644 --- a/src/flextype/Foundation/Media/MediaFilesMeta.php +++ b/src/flextype/Foundation/Media/MediaFilesMeta.php @@ -32,12 +32,12 @@ class MediaFilesMeta */ public function update(string $id, string $field, string $value): bool { - $file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); + $fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); - if (arrays($file_data)->has($field)) { - $file_data = arrays($file_data)->set($field, $value); + if (arrays($fileData)->has($field)) { + $fileData = arrays($fileData)->set($field, $value); - return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray())); + return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray())); } return false; @@ -56,12 +56,12 @@ class MediaFilesMeta */ public function add(string $id, string $field, string $value): bool { - $file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); + $fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); - if (! arrays($file_data)->has($field)) { - $file_data = arrays($file_data)->set($field, $value); + if (! arrays($fileData)->has($field)) { + $fileData = arrays($fileData)->set($field, $value); - return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray())); + return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray())); } return false; @@ -79,12 +79,12 @@ class MediaFilesMeta */ public function delete(string $id, string $field): bool { - $file_data = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); + $fileData = flextype('yaml')->decode(filesystem()->file($this->getFileMetaLocation($id))->get()); - if (arrays($file_data)->has($field)) { - $file_data = arrays($file_data)->delete($field); + if (arrays($fileData)->has($field)) { + $fileData = arrays($fileData)->delete($field); - return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($file_data->toArray())); + return (bool) filesystem()->file($this->getFileMetaLocation($id))->put(flextype('yaml')->encode($fileData->toArray())); } return false; diff --git a/src/flextype/Foundation/Media/MediaFolders.php b/src/flextype/Foundation/Media/MediaFolders.php index a5e43a44..e707ed85 100644 --- a/src/flextype/Foundation/Media/MediaFolders.php +++ b/src/flextype/Foundation/Media/MediaFolders.php @@ -42,12 +42,12 @@ class MediaFolders $result['url'] = 'project/uploads/' . $path; if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') !== '') { - $full_url = flextype('registry')->get('flextype.settings.url'); + $fullUrl = flextype('registry')->get('flextype.settings.url'); } else { - $full_url = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); + $fullUrl = Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } - $result['full_url'] = $full_url . '/project/uploads/' . $path; + $result['full_url'] = $fullUrl . '/project/uploads/' . $path; } $result = filter($result, $options); @@ -102,20 +102,20 @@ class MediaFolders * Move folder * * @param string $id Unique identifier of the folder. - * @param string $new_id New Unique identifier of the folder. + * @param string $newID New Unique identifier of the folder. * * @return bool True on success, false on failure. * * @access public */ - public function move(string $id, string $new_id): bool + public function move(string $id, string $newID): bool { if ( - (filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false && - filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false) + (filesystem()->directory($this->getDirectoryLocation($newID))->exists() === false && + filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists() === false) ) { - return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($new_id)) && - filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id)); + return filesystem()->directory($this->getDirectoryLocation($id))->move($this->getDirectoryLocation($newID)) && + filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id))->move(flextype('media_folders_meta')->getDirectoryMetaLocation($newID)); } return false; @@ -125,27 +125,27 @@ class MediaFolders * Copy folder * * @param string $id Unique identifier of the folder. - * @param string $new_id New Unique identifier of the folder. + * @param string $newID New Unique identifier of the folder. * * @return bool True on success, false on failure. * * @access public */ - public function copy(string $id, string $new_id): bool + public function copy(string $id, string $newID): bool { if ( - (filesystem()->directory($this->getDirectoryLocation($new_id))->exists() === false && - filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists() === false) + (filesystem()->directory($this->getDirectoryLocation($newID))->exists() === false && + filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists() === false) ) { filesystem() ->directory($this->getDirectoryLocation($id)) - ->copy($this->getDirectoryLocation($new_id)); + ->copy($this->getDirectoryLocation($newID)); filesystem() ->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($id)) - ->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id)); + ->copy(flextype('media_folders_meta')->getDirectoryMetaLocation($newID)); - return filesystem()->directory($this->getDirectoryLocation($new_id))->exists() && - filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($new_id))->exists(); + return filesystem()->directory($this->getDirectoryLocation($newID))->exists() && + filesystem()->directory(flextype('media_folders_meta')->getDirectoryMetaLocation($newID))->exists(); } return false; diff --git a/src/flextype/Foundation/Plugins.php b/src/flextype/Foundation/Plugins.php index b6182ca9..acf91b2c 100755 --- a/src/flextype/Foundation/Plugins.php +++ b/src/flextype/Foundation/Plugins.php @@ -72,82 +72,82 @@ class Plugins $locale = flextype('registry')->get('flextype.settings.locale'); // Get plugins list - $plugins_list = $this->getPluginsList(); + $pluginsList = $this->getPluginsList(); // Get plugins Cache ID - $plugins_cache_id = $this->getPluginsCacheID($plugins_list); + $pluginsCacheID = $this->getPluginsCacheID($pluginsList); // If Plugins List isnt empty then continue - if (count($plugins_list) <= 0) { + if (count($pluginsList) <= 0) { return; } // Get plugins from cache or scan plugins folder and create new plugins cache item - if (flextype('cache')->has($plugins_cache_id)) { - flextype('registry')->set('plugins', flextype('cache')->get($plugins_cache_id)); + if (flextype('cache')->has($pluginsCacheID)) { + flextype('registry')->set('plugins', flextype('cache')->get($pluginsCacheID)); if (flextype('cache')->has($locale)) { I18n::add(flextype('cache')->get($locale), $locale); } else { // Save plugins dictionary - $dictionary = $this->getPluginsDictionary($plugins_list, $locale); + $dictionary = $this->getPluginsDictionary($pluginsList, $locale); flextype('cache')->set($locale, $dictionary[$locale]); } } else { // Init plugin configs $plugins = []; - $default_plugin_settings = []; - $project_plugin_settings = []; - $default_plugin_manifest = []; + $defaultPluginSettings = []; + $projectPluginSettings = []; + $defaultPluginManifest = []; // Go through... - foreach ($plugins_list as $plugin) { + foreach ($pluginsList as $plugin) { // Set plugin settings directory - $project_plugin_settings_dir = PATH['project'] . '/config/plugins/' . $plugin['dirname']; + $projectPluginSettingsDir = PATH['project'] . '/config/plugins/' . $plugin['dirname']; // Set default plugin settings and manifest files - $default_plugin_settings_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; - $default_plugin_manifest_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; + $defaultPluginSettingsFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $defaultPluginManifestFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; // Set project plugin settings file - $project_plugin_settings_file = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $projectPluginSettingsFile = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; // Create project plugin settings directory - ! filesystem()->directory($project_plugin_settings_dir)->exists() and filesystem()->directory($project_plugin_settings_dir)->create(0755, true); + ! filesystem()->directory($projectPluginSettingsDir)->exists() and filesystem()->directory($projectPluginSettingsDir)->create(0755, true); // Check if default plugin settings file exists - if (! filesystem()->file($default_plugin_settings_file)->exists()) { + if (! filesystem()->file($defaultPluginSettingsFile)->exists()) { throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin settings - failed!'); } // Get default plugin settings content - $default_plugin_settings_file_content = filesystem()->file($default_plugin_settings_file)->get(); - $default_plugin_settings = flextype('yaml')->decode($default_plugin_settings_file_content); + $defaultPluginSettingsFileContent = filesystem()->file($defaultPluginSettingsFile)->get(); + $defaultPluginSettings = flextype('yaml')->decode($defaultPluginSettingsFileContent); // Create project plugin settings file - ! filesystem()->file($project_plugin_settings_file)->exists() and filesystem()->file($project_plugin_settings_file)->put($default_plugin_settings_file_content); + ! filesystem()->file($projectPluginSettingsFile)->exists() and filesystem()->file($projectPluginSettingsFile)->put($defaultPluginSettingsFileContent); // Get project plugin settings content - $project_plugin_settings_file_content = filesystem()->file($project_plugin_settings_file)->get(); + $projectPluginSettingsFileContent = filesystem()->file($projectPluginSettingsFile)->get(); - if (trim($project_plugin_settings_file_content) === '') { - $project_plugin_settings = []; + if (trim($projectPluginSettingsFileContent) === '') { + $projectPluginSettings = []; } else { - $project_plugin_settings = flextype('yaml')->decode($project_plugin_settings_file_content); + $projectPluginSettings = flextype('yaml')->decode($projectPluginSettingsFileContent); } // Check if default plugin manifest file exists - if (! filesystem()->file($default_plugin_manifest_file)->exists()) { + if (! filesystem()->file($defaultPluginManifestFile)->exists()) { throw new RuntimeException('Load ' . $plugin['dirname'] . ' plugin manifest - failed!'); } // Get default plugin manifest content - $default_plugin_manifest_file_content = filesystem()->file($default_plugin_manifest_file)->get(); - $default_plugin_manifest = flextype('yaml')->decode($default_plugin_manifest_file_content); + $defaultPluginManifestFileContent = filesystem()->file($defaultPluginManifestFile)->get(); + $defaultPluginManifest = flextype('yaml')->decode($defaultPluginManifestFileContent); // Merge plugin settings and manifest data - $plugins[$plugin['dirname']]['manifest'] = $default_plugin_manifest; - $plugins[$plugin['dirname']]['settings'] = array_replace_recursive($default_plugin_settings, $project_plugin_settings); + $plugins[$plugin['dirname']]['manifest'] = $defaultPluginManifest; + $plugins[$plugin['dirname']]['settings'] = array_replace_recursive($defaultPluginSettings, $projectPluginSettings); // Check if is not set plugin priority if (! isset($plugins[$plugin['dirname']]['settings']['priority'])) { @@ -163,8 +163,8 @@ class Plugins $plugins = arrays($plugins)->sortBy('_priority', 'DESC')->toArray(); // ... and delete tmp _priority field for sorting - foreach ($plugins as $plugin_name => $plugin_data) { - $plugins[$plugin_name] = arrays($plugins)->delete($plugin_name . '._priority')->toArray(); + foreach ($plugins as $pluginName => $pluginData) { + $plugins[$pluginName] = arrays($plugins)->delete($pluginName . '._priority')->toArray(); } // Get Valid Plugins Dependencies @@ -172,10 +172,10 @@ class Plugins // Save plugins list flextype('registry')->set('plugins', $plugins); - flextype('cache')->set($plugins_cache_id, $plugins); + flextype('cache')->set($pluginsCacheID, $plugins); // Save plugins dictionary - $dictionary = $this->getPluginsDictionary($plugins_list, $locale); + $dictionary = $this->getPluginsDictionary($pluginsList, $locale); flextype('cache')->set($locale, $dictionary[$locale]); } @@ -187,21 +187,21 @@ class Plugins /** * Get plugins dictionary * - * @param array $plugins_list Plugins list + * @param array $pluginsList Plugins list * * @access private */ - public function getPluginsDictionary(array $plugins_list, string $locale): array + public function getPluginsDictionary(array $pluginsList, string $locale): array { - foreach ($plugins_list as $plugin) { - $language_file = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml'; + foreach ($pluginsList as $plugin) { + $languageFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/lang/' . $locale . '.yaml'; - if (! filesystem()->file($language_file)->exists()) { + if (! filesystem()->file($languageFile)->exists()) { continue; } - if (($content = filesystem()->file($language_file)->get()) === false) { - throw new RuntimeException('Load file: ' . $language_file . ' - failed!'); + if (($content = filesystem()->file($languageFile)->get()) === false) { + throw new RuntimeException('Load file: ' . $languageFile . ' - failed!'); } $translates = flextype('yaml')->decode($content); @@ -215,32 +215,32 @@ class Plugins /** * Get plugins Cache ID * - * @param array $plugins_list Plugins list + * @param array $pluginsList Plugins list * * @access private */ - public function getPluginsCacheID(array $plugins_list): string + public function getPluginsCacheID(array $pluginsList): string { // Plugin cache id - $_plugins_cache_id = ''; + $_pluginsCacheID = ''; // Go through... - if (is_array($plugins_list) && count($plugins_list) > 0) { - foreach ($plugins_list as $plugin) { - $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['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; + if (is_array($pluginsList) && count($pluginsList) > 0) { + foreach ($pluginsList as $plugin) { + $defaultPluginSettingsFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/settings.yaml'; + $defaultPluginManifestFile = PATH['project'] . '/plugins/' . $plugin['dirname'] . '/plugin.yaml'; + $projectPluginSettingsFile = PATH['project'] . '/config/plugins/' . $plugin['dirname'] . '/settings.yaml'; - $f1 = filesystem()->file($default_plugin_settings_file)->exists() ? filemtime($default_plugin_settings_file) : ''; - $f2 = filesystem()->file($default_plugin_manifest_file)->exists() ? filemtime($default_plugin_manifest_file) : ''; - $f3 = filesystem()->file($project_plugin_settings_file)->exists() ? filemtime($project_plugin_settings_file) : ''; + $f1 = filesystem()->file($defaultPluginSettingsFile)->exists() ? filemtime($defaultPluginSettingsFile) : ''; + $f2 = filesystem()->file($defaultPluginManifestFile)->exists() ? filemtime($defaultPluginManifestFile) : ''; + $f3 = filesystem()->file($projectPluginSettingsFile)->exists() ? filemtime($projectPluginSettingsFile) : ''; - $_plugins_cache_id .= $f1 . $f2 . $f3; + $_pluginsCacheID .= $f1 . $f2 . $f3; } } // Create Unique Cache ID for Plugins - return md5('plugins' . PATH['project'] . '/plugins/' . $_plugins_cache_id); + return md5('plugins' . PATH['project'] . '/plugins/' . $_pluginsCacheID); } /** @@ -253,33 +253,33 @@ class Plugins public function getValidPluginsDependencies(array $plugins): array { // Set verified plugins array - $verified_plugins = []; + $verifiedPlugins = []; // Set non verfied plugins - $non_verified_plugins = $plugins; + $nonVerifiedPlugins = $plugins; // Go through plugins list and verify them. - foreach ($plugins as $plugin_name => &$plugin_data) { + foreach ($plugins as $pluginName => &$pluginData) { // Set verified true by default $verified = true; // If there is any dependencies for this plugin - if (isset($plugin_data['manifest']['dependencies'])) { + if (isset($pluginData['manifest']['dependencies'])) { // Go through plugin dependencies - foreach ($plugin_data['manifest']['dependencies'] as $dependency => $constraints) { + foreach ($pluginData['manifest']['dependencies'] as $dependency => $constraints) { // Verify flextype version if ($dependency === 'flextype') { if (! Semver::satisfies(flextype('registry')->get('flextype.manifest.version'), $constraints)) { $verified = false; // Remove plugin where it is require this dependency - foreach ($plugins as $_plugin_name => $_plugin_data) { - if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) { + foreach ($plugins as $_plugin_name => $_pluginData) { + if (! $_pluginData['manifest']['dependencies'][$pluginName]) { continue; } unset($plugins[$_plugin_name]); - unset($verified_plugins[$_plugin_name]); + unset($verifiedPlugins[$_plugin_name]); } } } else { @@ -288,13 +288,13 @@ class Plugins $verified = false; // Remove plugin where it is require this dependency - foreach ($plugins as $_plugin_name => $_plugin_data) { - if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) { + foreach ($plugins as $_plugin_name => $_pluginData) { + if (! $_pluginData['manifest']['dependencies'][$pluginName]) { continue; } unset($plugins[$_plugin_name]); - unset($verified_plugins[$_plugin_name]); + unset($verifiedPlugins[$_plugin_name]); } } else { $version = $plugins[$dependency]['manifest']['version']; @@ -302,13 +302,13 @@ class Plugins $verified = false; // Remove plugin where it is require this dependency - foreach ($plugins as $_plugin_name => $_plugin_data) { - if (! $_plugin_data['manifest']['dependencies'][$plugin_name]) { + foreach ($plugins as $_plugin_name => $_pluginData) { + if (! $_pluginData['manifest']['dependencies'][$pluginName]) { continue; } unset($plugins[$_plugin_name]); - unset($verified_plugins[$_plugin_name]); + unset($verifiedPlugins[$_plugin_name]); } } } @@ -321,16 +321,16 @@ class Plugins continue; } - $verified_plugins[$plugin_name] = $plugin_data; + $verifiedPlugins[$pluginName] = $pluginData; } // Show alert if dependencies are not installed properly - $diff = array_diff_key($non_verified_plugins, $verified_plugins); + $diff = array_diff_key($nonVerifiedPlugins, $verifiedPlugins); if (count($diff) > 0) { echo 'Dependencies need to be installed properly for this plugins:'; echo '