From 5a344b6c528d2cddfe52f26609913923b642d23c Mon Sep 17 00:00:00 2001 From: Awilum Date: Thu, 7 Jul 2022 14:41:30 +0300 Subject: [PATCH] refactor(core): code updates and improvements - doctrine --- src/flextype/bootstrap/after-plugins.php | 2 +- src/flextype/bootstrap/before-plugins.php | 2 +- src/flextype/core/Actions.php | 6 +- .../core/Cache/Drivers/Phparray/Config.php | 18 +- .../core/Cache/Drivers/Phparray/Driver.php | 68 ++-- .../core/Cache/Drivers/Phparray/Item.php | 6 +- .../core/Console/Commands/AboutCommand.php | 29 +- .../Commands/Cache/CacheClearCommand.php | 30 +- .../Cache/CacheClearConfigCommand.php | 28 +- .../Commands/Cache/CacheClearDataCommand.php | 28 +- .../Cache/CacheClearRoutesCommand.php | 28 +- .../Commands/Cache/CacheDeleteCommand.php | 37 +- .../Cache/CacheDeleteMultipleCommand.php | 43 ++- .../Commands/Cache/CacheGetCommand.php | 11 +- .../Cache/CacheGetMultipleCommand.php | 16 +- .../Commands/Cache/CacheHasCommand.php | 35 +- .../Commands/Cache/CacheSetCommand.php | 37 +- .../Cache/CacheSetMultipleCommand.php | 44 ++- .../Commands/Entries/EntriesCopyCommand.php | 43 ++- .../Commands/Entries/EntriesCreateCommand.php | 42 ++- .../Commands/Entries/EntriesDeleteCommand.php | 42 ++- .../Commands/Entries/EntriesFetchCommand.php | 118 ++++--- .../Commands/Entries/EntriesHasCommand.php | 36 +- .../Commands/Entries/EntriesMoveCommand.php | 42 ++- .../Commands/Entries/EntriesUpdateCommand.php | 49 +-- .../Commands/Tokens/TokensCreateCommand.php | 48 +-- .../Commands/Tokens/TokensDeleteCommand.php | 42 ++- .../Commands/Tokens/TokensFetchCommand.php | 120 ++++--- .../Commands/Tokens/TokensGenerateCommand.php | 17 +- .../Tokens/TokensGenerateHashCommand.php | 19 +- .../Commands/Tokens/TokensHasCommand.php | 36 +- .../Commands/Tokens/TokensUpdateCommand.php | 49 +-- .../Tokens/TokensVerifyHashCommand.php | 39 ++- src/flextype/core/Console/FlextypeConsole.php | 51 ++- src/flextype/core/Endpoints/Api.php | 13 +- src/flextype/core/Endpoints/Cache.php | 4 +- src/flextype/core/Endpoints/Entries.php | 6 +- src/flextype/core/Endpoints/Registry.php | 4 +- src/flextype/core/Endpoints/Tokens.php | 19 +- .../Directives/ExpressionsDirective.php | 14 +- .../Entries/Directives/MarkdownDirective.php | 16 +- .../core/Entries/Directives/PhpDirective.php | 12 +- .../Directives/ShortcodesDirective.php | 16 +- .../Entries/Directives/TextileDirective.php | 18 +- .../Entries/Directives/TypesDirective.php | 16 +- .../Entries/Expressions/ActionsExpression.php | 11 +- .../Expressions/CollectionExpression.php | 21 +- .../Entries/Expressions/ConstExpression.php | 13 +- .../Entries/Expressions/CsrfExpression.php | 11 +- .../Entries/Expressions/EntriesExpression.php | 19 +- .../Entries/Expressions/FieldExpression.php | 11 +- .../Expressions/FilesystemExpression.php | 22 +- .../Entries/Expressions/I18nExpression.php | 11 +- .../Entries/Expressions/ParsersExpression.php | 11 +- .../Expressions/RegistryExpression.php | 11 +- .../Expressions/SerializersExpression.php | 11 +- .../Entries/Expressions/SlugifyExpression.php | 11 +- .../Entries/Expressions/StringsExpression.php | 13 +- .../Entries/Expressions/UrlExpression.php | 36 +- .../Entries/Expressions/VarExpression.php | 11 +- src/flextype/core/Flextype.php | 10 +- src/flextype/core/I18n.php | 34 +- .../core/Middlewares/CsrfMiddleware.php | 20 +- .../core/Middlewares/WhoopsMiddleware.php | 24 +- src/flextype/core/Parsers/Markdown.php | 8 +- src/flextype/core/Parsers/Parsers.php | 4 +- src/flextype/core/Parsers/Shortcodes.php | 35 +- .../core/Parsers/Shortcodes/CalcShortcode.php | 9 +- .../Parsers/Shortcodes/ConstShortcode.php | 14 +- .../Parsers/Shortcodes/EntriesShortcode.php | 41 +-- .../core/Parsers/Shortcodes/EvalShortcode.php | 15 +- .../Parsers/Shortcodes/FieldShortcode.php | 11 +- .../Shortcodes/FilesystemShortcode.php | 21 +- .../core/Parsers/Shortcodes/I18nShortcode.php | 18 +- .../core/Parsers/Shortcodes/IfShortcode.php | 11 +- .../Parsers/Shortcodes/MarkdownShortcode.php | 11 +- .../core/Parsers/Shortcodes/PhpShortcode.php | 14 +- .../core/Parsers/Shortcodes/RawShortcode.php | 4 +- .../Parsers/Shortcodes/RegistryShortcode.php | 21 +- .../Parsers/Shortcodes/StringsShortcode.php | 318 +++++++++--------- .../Parsers/Shortcodes/TextileShortcode.php | 11 +- .../core/Parsers/Shortcodes/TypeShortcode.php | 11 +- .../Parsers/Shortcodes/UnlessShortcode.php | 11 +- .../core/Parsers/Shortcodes/UrlShortcode.php | 33 +- .../core/Parsers/Shortcodes/UuidShortcode.php | 13 +- .../core/Parsers/Shortcodes/VarShortcode.php | 27 +- .../core/Parsers/Shortcodes/WhenShortcode.php | 11 +- src/flextype/core/Parsers/Textile.php | 17 +- src/flextype/core/Plugins.php | 40 +-- src/flextype/core/Serializers/Frontmatter.php | 31 +- src/flextype/core/Serializers/Json.php | 14 +- src/flextype/core/Serializers/Json5.php | 18 +- src/flextype/core/Serializers/Neon.php | 8 +- src/flextype/core/Serializers/PhpArray.php | 18 +- src/flextype/core/Serializers/Serializers.php | 4 +- src/flextype/core/Serializers/Yaml.php | 14 +- src/flextype/core/Whoops.php | 42 ++- src/flextype/defines.php | 9 +- src/flextype/flextype.php | 54 ++- src/flextype/helpers/collection.php | 25 +- src/flextype/helpers/finder.php | 8 +- src/flextype/helpers/helpers.php | 2 +- src/flextype/helpers/i18n.php | 17 +- src/flextype/helpers/image.php | 25 +- src/flextype/helpers/services.php | 6 +- src/flextype/helpers/tokens.php | 15 +- src/flextype/helpers/upload.php | 20 +- src/flextype/helpers/url.php | 52 ++- src/flextype/macros/collection.php | 1 + src/flextype/macros/macros.php | 2 +- src/flextype/routes/endpoints/cache.php | 6 +- src/flextype/routes/endpoints/entries.php | 6 +- src/flextype/routes/endpoints/registry.php | 6 +- src/flextype/routes/endpoints/tokens.php | 12 +- src/flextype/routes/routes.php | 2 +- src/flextype/settings.yaml | 4 - 116 files changed, 1503 insertions(+), 1357 deletions(-) diff --git a/src/flextype/bootstrap/after-plugins.php b/src/flextype/bootstrap/after-plugins.php index 2c293f5b..045da62f 100644 --- a/src/flextype/bootstrap/after-plugins.php +++ b/src/flextype/bootstrap/after-plugins.php @@ -6,4 +6,4 @@ use function Glowy\Filesystem\filesystem; if (filesystem()->file(FLEXTYPE_PATH_PROJECT . '/bootstrap/after-plugins.php')->exists()) { require_once FLEXTYPE_PATH_PROJECT . '/bootstrap/after-plugins.php'; -} \ No newline at end of file +} diff --git a/src/flextype/bootstrap/before-plugins.php b/src/flextype/bootstrap/before-plugins.php index 1076671e..d52f678b 100644 --- a/src/flextype/bootstrap/before-plugins.php +++ b/src/flextype/bootstrap/before-plugins.php @@ -6,4 +6,4 @@ use function Glowy\Filesystem\filesystem; if (filesystem()->file(FLEXTYPE_PATH_PROJECT . '/bootstrap/before-plugins.php')->exists()) { require_once FLEXTYPE_PATH_PROJECT . '/bootstrap/before-plugins.php'; -} \ No newline at end of file +} diff --git a/src/flextype/core/Actions.php b/src/flextype/core/Actions.php index e267725a..e574e789 100644 --- a/src/flextype/core/Actions.php +++ b/src/flextype/core/Actions.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -67,4 +67,4 @@ class Actions extends Collection public function __wakeup(): void { } -} \ No newline at end of file +} diff --git a/src/flextype/core/Cache/Drivers/Phparray/Config.php b/src/flextype/core/Cache/Drivers/Phparray/Config.php index dad6a9e7..8645c89b 100644 --- a/src/flextype/core/Cache/Drivers/Phparray/Config.php +++ b/src/flextype/core/Cache/Drivers/Phparray/Config.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,20 +18,10 @@ declare(strict_types=1); namespace Phpfastcache\Drivers\Phparray; -use Phpfastcache\Config\IOConfigurationOptionInterface; use Phpfastcache\Config\IOConfigurationOption; +use Phpfastcache\Config\IOConfigurationOptionInterface; class Config extends IOConfigurationOption implements IOConfigurationOptionInterface { - /** - * @param string $cacheFileExtension - * @return self - * @throws PhpfastcacheInvalidConfigurationException - */ - public function setCacheFileExtension(string $cacheFileExtension): static - { - $this->cacheFileExtension = 'php'; - return $this; - } -} \ No newline at end of file +} diff --git a/src/flextype/core/Cache/Drivers/Phparray/Driver.php b/src/flextype/core/Cache/Drivers/Phparray/Driver.php index 38aef0d1..bd7c5160 100644 --- a/src/flextype/core/Cache/Drivers/Phparray/Driver.php +++ b/src/flextype/core/Cache/Drivers/Phparray/Driver.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,17 +16,25 @@ declare(strict_types=1); namespace Phpfastcache\Drivers\Phparray; -use Exception; use FilesystemIterator; use Phpfastcache\Cluster\AggregatablePoolInterface; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Core\Pool\IO\IOHelperTrait; use Phpfastcache\Core\Item\ExtendedCacheItemInterface; +use Phpfastcache\Core\Pool\IO\IOHelperTrait; use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; use Phpfastcache\Exceptions\PhpfastcacheIOException; use Phpfastcache\Exceptions\PhpfastcacheLogicException; use Phpfastcache\Util\Directory; +use Throwable; + +use function clearstatcache; +use function dirname; +use function file_exists; use function Flextype\serializers; +use function is_dir; +use function is_writable; +use function mkdir; +use function rmdir; +use function unlink; /** * @method Config getConfig() @@ -39,8 +47,9 @@ class Driver implements AggregatablePoolInterface { use IOHelperTrait; + private static string $ext = 'php'; + /** - * @return bool * @throws PhpfastcacheIOException * @throws PhpfastcacheInvalidArgumentException */ @@ -49,35 +58,32 @@ class Driver implements AggregatablePoolInterface return is_writable($this->getPath()) || mkdir($concurrentDirectory = $this->getPath(), $this->getDefaultChmod(), true) || is_dir($concurrentDirectory); } - /** - * @return bool - */ protected function driverConnect(): bool { return true; } /** - * @param ExtendedCacheItemInterface $item * @return ?array + * * @throws PhpfastcacheIOException */ protected function driverRead(ExtendedCacheItemInterface $item): ?array { - $filePath = $this->getFilePath($item->getKey(), true); + $filePath = $this->getFilePath($item->getKey(), true) . '.' . 'php'; - try { - $content = $this->readFile($filePath); - } catch (PhpfastcacheIOException) { - return null; - } + $value = null; - return $this->decode($content); + set_error_handler(static function () {}); + + $value = include $filePath; + + restore_error_handler(); + + return ! is_bool($value) ? $value : null; } /** - * @param ExtendedCacheItemInterface $item - * @return bool * @throws PhpfastcacheIOException * @throws PhpfastcacheInvalidArgumentException * @throws PhpfastcacheLogicException @@ -86,19 +92,17 @@ class Driver implements AggregatablePoolInterface { $this->assertCacheItemType($item, Item::class); - $filePath = $this->getFilePath($item->getKey()); - $data = $this->encode($this->driverPreWrap($item)); + $filePath = $this->getFilePath($item->getKey()) . '.' . 'php'; + $data = $this->driverPreWrap($item); try { return $this->writeFile($filePath, serializers()->phparray()->encode($data), $this->getConfig()->isSecureFileManipulation(), $this->getConfig()->isSecureFileManipulation()); - } catch (Exception) { + } catch (Throwable) { return false; } } /** - * @param ExtendedCacheItemInterface $item - * @return bool * @throws PhpfastcacheIOException * @throws PhpfastcacheInvalidArgumentException */ @@ -106,13 +110,14 @@ class Driver implements AggregatablePoolInterface { $this->assertCacheItemType($item, Item::class); - $filePath = $this->getFilePath($item->getKey(), true); - if (\file_exists($filePath) && @\unlink($filePath)) { - \clearstatcache(true, $filePath); - $dir = \dirname($filePath); - if (!(new FilesystemIterator($dir))->valid()) { - \rmdir($dir); + $filePath = $this->getFilePath($item->getKey(), true) . '.' . 'php';; + if (file_exists($filePath) && @unlink($filePath)) { + clearstatcache(true, $filePath); + $dir = dirname($filePath); + if (! (new FilesystemIterator($dir))->valid()) { + rmdir($dir); } + return true; } @@ -120,8 +125,7 @@ class Driver implements AggregatablePoolInterface } /** - * @return bool - * @throws \Phpfastcache\Exceptions\PhpfastcacheIOException + * @throws PhpfastcacheIOException * @throws PhpfastcacheInvalidArgumentException */ protected function driverClear(): bool diff --git a/src/flextype/core/Cache/Drivers/Phparray/Item.php b/src/flextype/core/Cache/Drivers/Phparray/Item.php index 14c819c8..823d0438 100644 --- a/src/flextype/core/Cache/Drivers/Phparray/Item.php +++ b/src/flextype/core/Cache/Drivers/Phparray/Item.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -27,4 +27,4 @@ class Item implements ExtendedCacheItemInterface { return Driver::class; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/AboutCommand.php b/src/flextype/core/Console/Commands/AboutCommand.php index e8447b42..6c6cd707 100644 --- a/src/flextype/core/Console/Commands/AboutCommand.php +++ b/src/flextype/core/Console/Commands/AboutCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,14 +19,19 @@ namespace Flextype\Console\Commands; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; -use function Thermage\breakline; + +use function array_keys; +use function Flextype\registry; +use function get_loaded_extensions; +use function implode; +use function phpversion; use function Thermage\anchor; +use function Thermage\breakline; use function Thermage\div; -use function Thermage\span; use function Thermage\hr; use function Thermage\renderToString; -use function Flextype\registry; + +use const PHP_EOL; class AboutCommand extends Command { @@ -40,18 +45,17 @@ class AboutCommand extends Command { $output->write( renderToString( - - hr('[b]Flextype[/b]', 'my-1') . + hr('[b]Flextype[/b]', 'my-1') . div('[b][color=success]Version[/color][/b]: ' . registry()->get('flextype.manifest.version'), '') . div('[b][color=success]Author[/color][/b]', '') . div('[b][color=success] Name[/color][/b]: ' . registry()->get('flextype.manifest.author.name'), '') . div('[b][color=success] Email[/color][/b]: ' . registry()->get('flextype.manifest.author.email'), '') . div('[b][color=success] Url[/color][/b]: ' . anchor(registry()->get('flextype.manifest.author.url'))->href(registry()->get('flextype.manifest.author.url')), 'clearfix') . breakline() . - hr('[b]Plugins[/b]', 'my-1') . + hr('[b]Plugins[/b]', 'my-1') . div('[b][color=success]Enabled[/color][/b]: ' . implode(', ', array_keys(registry()->get('plugins'))), '') . - hr('[b]Constants[/b]', 'my-1') . + hr('[b]Constants[/b]', 'my-1') . div('[b][color=success]FLEXTYPE_PROJECT_NAME[/color][/b]: ' . FLEXTYPE_PROJECT_NAME, '') . div('[b][color=success]FLEXTYPE_ROOT_DIR[/color][/b]: ' . FLEXTYPE_ROOT_DIR, '') . div('[b][color=success]FLEXTYPE_PATH_PROJECT[/color][/b]: ' . FLEXTYPE_PATH_PROJECT, '') . @@ -61,12 +65,11 @@ class AboutCommand extends Command hr('[b]PHP Information[/b]', 'my-1') . div('[b][color=success]PHP Version[/color][/b]: ' . phpversion(), '') . div('[b][color=success]PHP Modules[/color][/b]: ' . implode(', ', get_loaded_extensions()), '') - + . PHP_EOL - ) ); return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php index 1cd3a45e..b1328018 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheClearCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,10 +19,10 @@ namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; + +use function Glowy\Filesystem\filesystem; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Filesystem\filesystem; class CacheClearCommand extends Command { @@ -40,16 +40,20 @@ class CacheClearCommand extends Command if (filesystem()->directory($path)->delete()) { $output->write( renderToString( - div('All items were successfully cleared from the cache.', - 'color-success px-2 py-1') + div( + 'All items were successfully cleared from the cache.', + 'color-success px-2 py-1' + ) ) ); $result = Command::SUCCESS; } else { $output->write( renderToString( - div('Cache wasn\'t cleared.', - 'color-danger px-2 py-1') + div( + 'Cache wasn\'t cleared.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -57,13 +61,15 @@ class CacheClearCommand extends Command } else { $output->write( renderToString( - div('Cache directory ' . $path . ' doesn\'t exist.', - 'color-danger px-2 py-1') + div( + 'Cache directory ' . $path . ' doesn\'t exist.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; } - + return $result; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php index ea1bcac4..32522b97 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheClearConfigCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,10 +19,10 @@ namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputOption; + +use function Glowy\Filesystem\filesystem; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Filesystem\filesystem; class CacheClearConfigCommand extends Command { @@ -40,16 +40,20 @@ class CacheClearConfigCommand extends Command if (filesystem()->directory($configPath)->delete()) { $output->write( renderToString( - div('Config were successfully cleared from the cache.', - 'color-success px-2 py-1') + div( + 'Config were successfully cleared from the cache.', + 'color-success px-2 py-1' + ) ) ); $result = Command::SUCCESS; } else { $output->write( renderToString( - div('Config cache wasn\'t cleared.', - 'color-danger px-2 py-1') + div( + 'Config cache wasn\'t cleared.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -57,8 +61,10 @@ class CacheClearConfigCommand extends Command } else { $output->write( renderToString( - div('Config cache directory ' . $configPath . ' doesn\'t exist.', - 'color-danger px-2 py-1') + div( + 'Config cache directory ' . $configPath . ' doesn\'t exist.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -66,4 +72,4 @@ class CacheClearConfigCommand extends Command return $result; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php index c145915b..146c7792 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheClearDataCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,10 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Console\Input\InputOption; + +use function Glowy\Filesystem\filesystem; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Filesystem\filesystem; class CacheClearDataCommand extends Command { @@ -43,16 +43,20 @@ class CacheClearDataCommand extends Command if (filesystem()->directory($routesData)->delete()) { $output->write( renderToString( - div('Data were successfully cleared from the cache.', - 'color-success px-2 py-1') + div( + 'Data were successfully cleared from the cache.', + 'color-success px-2 py-1' + ) ) ); $result = Command::SUCCESS; } else { $output->write( renderToString( - div('Data cache wasn\'t cleared.', - 'color-danger px-2 py-1') + div( + 'Data cache wasn\'t cleared.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -60,8 +64,10 @@ class CacheClearDataCommand extends Command } else { $output->write( renderToString( - div('Data cache directory ' . $routesData . ' doesn\'t exist.', - 'color-danger px-2 py-1') + div( + 'Data cache directory ' . $routesData . ' doesn\'t exist.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -69,4 +75,4 @@ class CacheClearDataCommand extends Command return $result; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php b/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php index 6b53e571..89a646ad 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheClearRoutesCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,10 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Console\Input\InputOption; + +use function Glowy\Filesystem\filesystem; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Filesystem\filesystem; class CacheClearRoutesCommand extends Command { @@ -43,16 +43,20 @@ class CacheClearRoutesCommand extends Command if (filesystem()->directory($routesPath)->delete()) { $output->write( renderToString( - div('Routes were successfully cleared from the cache.', - 'color-success px-2 py-1') + div( + 'Routes were successfully cleared from the cache.', + 'color-success px-2 py-1' + ) ) ); $result = Command::SUCCESS; } else { $output->write( renderToString( - div('Routes cache wasn\'t cleared.', - 'color-danger px-2 py-1') + div( + 'Routes cache wasn\'t cleared.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -60,8 +64,10 @@ class CacheClearRoutesCommand extends Command } else { $output->write( renderToString( - div('Routes cache directory ' . $routesPath . ' doesn\'t exist.', - 'color-danger px-2 py-1') + div( + 'Routes cache directory ' . $routesPath . ' doesn\'t exist.', + 'color-danger px-2 py-1' + ) ) ); $result = Command::FAILURE; @@ -69,4 +75,4 @@ class CacheClearRoutesCommand extends Command return $result; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php b/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php index a2a3b8fe..ac9e2f8b 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheDeleteCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,12 +17,13 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function Flextype\cache; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\cache; class CacheDeleteCommand extends Command { @@ -40,19 +41,25 @@ class CacheDeleteCommand extends Command if (cache()->delete($key)) { $output->write( renderToString( - div('Cache item with key ' . $key . ' deleted.', - 'color-success px-2 py-1') + div( + 'Cache item with key ' . $key . ' deleted.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Cache item with key ' . $key . ' wasn\'t deleted.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Cache item with key ' . $key . ' wasn\'t deleted.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php index f8694fd7..19aed057 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheDeleteMultipleCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,13 +17,16 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function Flextype\cache; +use function Flextype\collectionFromString; +use function implode; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\collectionFromString; -use function Flextype\cache; +use function trim; class CacheDeleteMultipleCommand extends Command { @@ -37,7 +40,7 @@ class CacheDeleteMultipleCommand extends Command protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getArgument('keys')) { - $keys = collectionFromString($input->getArgument('keys'), ',')->map(fn($key) => trim($key))->toArray(); + $keys = collectionFromString($input->getArgument('keys'), ',')->map(static fn ($key) => trim($key))->toArray(); } else { $keys = []; } @@ -45,19 +48,25 @@ class CacheDeleteMultipleCommand extends Command if (cache()->deleteMultiple($keys)) { $output->write( renderToString( - div('Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] deleted.', - 'color-success px-2 py-1') + div( + 'Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] deleted.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] wasn\'t deleted.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Cache items with keys [b]' . implode('[/b], [b]', $keys) . '[/b] wasn\'t deleted.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php b/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php index 891b7c7d..5a1c0875 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheGetCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,12 +17,13 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function Flextype\cache; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\cache; class CacheGetCommand extends Command { @@ -47,4 +48,4 @@ class CacheGetCommand extends Command return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php index bce99150..dffb271b 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheGetMultipleCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,14 +17,14 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Input\InputOption; -use function Thermage\div; -use function Thermage\renderToString; + use function Flextype\cache; use function Flextype\collectionFromString; +use function Thermage\div; +use function Thermage\renderToString; class CacheGetMultipleCommand extends Command { @@ -50,7 +50,7 @@ class CacheGetMultipleCommand extends Command ) ); } - + return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php index ddf6ee37..3c5364a6 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheHasCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,9 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + +use function Flextype\cache; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\cache; class CacheHasCommand extends Command { @@ -40,19 +41,25 @@ class CacheHasCommand extends Command if (cache()->has($key)) { $output->write( renderToString( - div('Cache item with key [b]' . $key . '[/b] exists.', - 'color-success px-2 py-1') + div( + 'Cache item with key [b]' . $key . '[/b] exists.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Cache item with key [b]' . $key . '[/b] doesn\'t exists.', - 'color-success px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Cache item with key [b]' . $key . '[/b] doesn\'t exists.', + 'color-success px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php b/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php index a3da44be..1403f86e 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheSetCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,12 +17,13 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function Flextype\cache; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\cache; class CacheSetCommand extends Command { @@ -44,19 +45,25 @@ class CacheSetCommand extends Command if (cache()->set($key, $value, $ttl)) { $output->write( renderToString( - div('Cache item with key ' . $key . ' created.', - 'color-success px-2 py-1') + div( + 'Cache item with key ' . $key . ' created.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Cache item with key ' . $key . ' wasn\'t created.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Cache item with key ' . $key . ' wasn\'t created.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Cache/CacheSetMultipleCommand.php b/src/flextype/core/Console/Commands/Cache/CacheSetMultipleCommand.php index d5cf174e..07624316 100644 --- a/src/flextype/core/Console/Commands/Cache/CacheSetMultipleCommand.php +++ b/src/flextype/core/Console/Commands/Cache/CacheSetMultipleCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,14 +17,18 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Cache; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function array_keys; +use function Flextype\cache; +use function Flextype\serializers; +use function Glowy\Strings\strings; +use function implode; +use function parse_str; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Strings\strings; -use function Flextype\serializers; -use function Flextype\cache; class CacheSetMultipleCommand extends Command { @@ -49,19 +53,25 @@ class CacheSetMultipleCommand extends Command if (cache()->setMultiple($values, $ttl)) { $output->write( renderToString( - div('Cache items with keys [b]' . implode('[/b], [b]', array_keys($values)) . '[/b] created.', - 'color-success px-2 py-1') + div( + 'Cache items with keys [b]' . implode('[/b], [b]', array_keys($values)) . '[/b] created.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Cache items with keys [b]' . implode('[/b], [b]', array_keys($values)) . '[/b] wasn\'t created.', - 'color-success px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Cache items with keys [b]' . implode('[/b], [b]', array_keys($values)) . '[/b] wasn\'t created.', + 'color-success px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php index db25a930..9897b962 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesCopyCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,10 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class EntriesCopyCommand extends Command { @@ -43,29 +43,38 @@ class EntriesCopyCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } if (entries()->copy($id, $newID)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] coppied to [b]' . $newID . '[/b]', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] coppied to [b]' . $newID . '[/b]', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] wasn\'t coppied to [b]' . $newID . '[/b]', - 'color-success px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] wasn\'t coppied to [b]' . $newID . '[/b]', + 'color-success px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesCreateCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesCreateCommand.php index f1c2ad00..59002201 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesCreateCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesCreateCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,14 +17,16 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Entries; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; -use function Thermage\div; -use function Thermage\renderToString; -use function Glowy\Strings\strings; + use function Flextype\entries; use function Flextype\serializers; +use function Glowy\Strings\strings; +use function parse_str; +use function Thermage\div; +use function Thermage\renderToString; class EntriesCreateCommand extends Command { @@ -54,19 +56,25 @@ class EntriesCreateCommand extends Command if (entries()->create($id, $dataToSave)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] created.', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] created.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] wasn\'t created.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] wasn\'t created.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php index 0ca3f185..0dac9088 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesDeleteCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,9 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class EntriesDeleteCommand extends Command { @@ -40,29 +41,38 @@ class EntriesDeleteCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } if (entries()->delete($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] deleted.', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] deleted.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] wasn\'t deleted.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] wasn\'t deleted.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesFetchCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesFetchCommand.php index 6cca801c..06f88972 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesFetchCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesFetchCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,19 +17,23 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Entries; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Console\Helper\Table; -use function Thermage\div; -use function Thermage\span; -use function Thermage\renderToString; -use function Glowy\Strings\strings; + +use function array_push; +use function count; +use function Flextype\collection; use function Flextype\entries; use function Flextype\serializers; -use function Flextype\collection; +use function Glowy\Strings\strings; +use function parse_str; +use function Thermage\div; +use function Thermage\renderToString; +use function Thermage\span; + +use const PHP_EOL; class EntriesFetchCommand extends Command { @@ -75,7 +79,7 @@ class EntriesFetchCommand extends Command } $input->getOption('collection') and $options['collection'] = true; - + if ($input->getOption('find-depth-from') || $input->getOption('find-depth-to')) { $options['find']['depth'] = []; $input->getOption('find-depth-from') and array_push($options['find']['depth'], $input->getOption('find-depth-from')); @@ -94,72 +98,76 @@ class EntriesFetchCommand extends Command $input->getOption('find-size-to') and array_push($options['find']['size'], $input->getOption('find-size-to')); } - $input->getOption('find-exclude') and $options['find']['exclude'] = $input->getOption('find-exclude'); - $input->getOption('find-contains') and $options['find']['contains'] = $input->getOption('find-contains'); - $input->getOption('find-not-contains') and $options['find']['not_contains'] = $input->getOption('find-not-contains'); - $input->getOption('find-path') and $options['find']['path'] = $input->getOption('find-path'); - $input->getOption('find-sort-by-key') and $options['find']['sort_by']['key'] = $input->getOption('find-sort-by-key'); + $input->getOption('find-exclude') and $options['find']['exclude'] = $input->getOption('find-exclude'); + $input->getOption('find-contains') and $options['find']['contains'] = $input->getOption('find-contains'); + $input->getOption('find-not-contains') and $options['find']['not_contains'] = $input->getOption('find-not-contains'); + $input->getOption('find-path') and $options['find']['path'] = $input->getOption('find-path'); + $input->getOption('find-sort-by-key') and $options['find']['sort_by']['key'] = $input->getOption('find-sort-by-key'); $input->getOption('find-sort-by-direction') and $options['find']['sort_by']['direction'] = $input->getOption('find-sort-by-direction'); $input->getOption('filter-group-by') and $options['filter']['group_by'] = $input->getOption('filter-group-by'); - $input->getOption('filter-return') and $options['filter']['return'] = $input->getOption('filter-return'); - + $input->getOption('filter-return') and $options['filter']['return'] = $input->getOption('filter-return'); + if ($input->getOption('filter-where')) { $filterWhere = $input->getOption('filter-where'); - - foreach ($filterWhere as $key => $value) { + foreach ($filterWhere as $key => $value) { if (strings($value)->isJson()) { $whereValues = serializers()->json()->decode($value); } else { parse_str($value, $whereValues); } - + $where[] = $whereValues; } - + $options['filter']['where'] = $where; } - - $innerData = []; + + $innerData = []; $innerDataString = ''; - + $data = entries()->fetch($id, $options); - if (count($data) > 0) { - if (isset($options['collection']) && $options['collection'] == true) { - foreach ($data->toArray() as $item) { - foreach(collection($item)->dot() as $key => $value) { - $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); - } - $innerData[] = $innerDataString; - $innerDataString = ''; - } - } else { - foreach(collection($data)->dot() as $key => $value) { - $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); - } - $innerData[] = $innerDataString; - $innerDataString = ''; - } - - foreach ($innerData as $item) { - $output->write( - renderToString( - div($item, 'px-2 border-square border-color-success') - ) - ); - } - - return Command::SUCCESS; - } else { + if (count($data) <= 0) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } + + if (isset($options['collection']) && $options['collection'] === true) { + foreach ($data->toArray() as $item) { + foreach (collection($item)->dot() as $key => $value) { + $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); + } + + $innerData[] = $innerDataString; + $innerDataString = ''; + } + } else { + foreach (collection($data)->dot() as $key => $value) { + $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); + } + + $innerData[] = $innerDataString; + $innerDataString = ''; + } + + foreach ($innerData as $item) { + $output->write( + renderToString( + div($item, 'px-2 border-square border-color-success') + ) + ); + } + + return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesHasCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesHasCommand.php index cd4bae5f..a9340723 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesHasCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesHasCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,10 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class EntriesHasCommand extends Command { @@ -41,19 +41,25 @@ class EntriesHasCommand extends Command if (entries()->has($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] exists.', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] exists.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesMoveCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesMoveCommand.php index 46148eb5..46697ff5 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesMoveCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesMoveCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,9 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class EntriesMoveCommand extends Command { @@ -42,29 +43,38 @@ class EntriesMoveCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } if (entries()->move($id, $newID)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] moved to [b]' . $newID . '[/b]', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] moved to [b]' . $newID . '[/b]', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] wasn\'t moved to [b]' . $newID . '[/b]', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] wasn\'t moved to [b]' . $newID . '[/b]', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php b/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php index ab116f77..76a793f4 100644 --- a/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php +++ b/src/flextype/core/Console/Commands/Entries/EntriesUpdateCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,11 +20,13 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use function Thermage\div; -use function Thermage\renderToString; -use function Glowy\Strings\strings; + use function Flextype\entries; use function Flextype\serializers; +use function Glowy\Strings\strings; +use function parse_str; +use function Thermage\div; +use function Thermage\renderToString; class EntriesUpdateCommand extends Command { @@ -54,29 +56,38 @@ class EntriesUpdateCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } - + if (entries()->update($id, $dataToSave)) { $output->write( renderToString( - div('Entry [b]' . $id . '[/b] updated.', - 'color-success px-2 py-1') + div( + 'Entry [b]' . $id . '[/b] updated.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Entry [b]' . $id . '[/b] wasn\'t updated.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Entry [b]' . $id . '[/b] wasn\'t updated.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensCreateCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensCreateCommand.php index 6d5bd3df..f011c235 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensCreateCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensCreateCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,17 +17,19 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Tokens; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function array_merge; +use function Flextype\entries; +use function Flextype\generateToken; +use function Flextype\generateTokenHash; +use function Flextype\serializers; +use function Glowy\Strings\strings; +use function parse_str; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Strings\strings; -use function Flextype\generateToken; -use function Flextype\serializers; -use function Flextype\entries; -use function Flextype\generateTokenHash; - class TokensCreateCommand extends Command { @@ -61,19 +63,25 @@ class TokensCreateCommand extends Command if (entries()->create('tokens/' . $token, array_merge($dataToSave, ['hashed_access_token' => $hashed_access_token]))) { $output->write( renderToString( - div('Token [b]' . $token . '[/b] with secret access token [b]' . $access_token . '[/b] created.', - 'color-success px-2 py-1') + div( + 'Token [b]' . $token . '[/b] with secret access token [b]' . $access_token . '[/b] created.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Token wasn\'t created.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Token wasn\'t created.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensDeleteCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensDeleteCommand.php index f28d49ab..e9890b44 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensDeleteCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensDeleteCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,9 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class TokensDeleteCommand extends Command { @@ -40,29 +41,38 @@ class TokensDeleteCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } if (entries()->delete($id)) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] deleted.', - 'color-success px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] deleted.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Token entry [b]' . $id . '[/b] wasn\'t deleted.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Token entry [b]' . $id . '[/b] wasn\'t deleted.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensFetchCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensFetchCommand.php index 6eed8000..f0fc01c4 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensFetchCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensFetchCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,19 +17,23 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Tokens; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; -use Symfony\Component\Console\Helper\Table; -use function Thermage\div; -use function Thermage\span; -use function Thermage\renderToString; -use function Glowy\Strings\strings; -use function Flextype\serializers; -use function Flextype\entries; + +use function array_push; +use function count; use function Flextype\collection; +use function Flextype\entries; +use function Flextype\serializers; +use function Glowy\Strings\strings; +use function parse_str; +use function Thermage\div; +use function Thermage\renderToString; +use function Thermage\span; + +use const PHP_EOL; class TokensFetchCommand extends Command { @@ -75,7 +79,7 @@ class TokensFetchCommand extends Command } $input->getOption('collection') and $options['collection'] = true; - + if ($input->getOption('find-depth-from') || $input->getOption('find-depth-to')) { $options['find']['depth'] = []; $input->getOption('find-depth-from') and array_push($options['find']['depth'], $input->getOption('find-depth-from')); @@ -94,72 +98,76 @@ class TokensFetchCommand extends Command $input->getOption('find-size-to') and array_push($options['find']['size'], $input->getOption('find-size-to')); } - $input->getOption('find-exclude') and $options['find']['exclude'] = $input->getOption('find-exclude'); - $input->getOption('find-contains') and $options['find']['contains'] = $input->getOption('find-contains'); - $input->getOption('find-not-contains') and $options['find']['not_contains'] = $input->getOption('find-not-contains'); - $input->getOption('find-path') and $options['find']['path'] = $input->getOption('find-path'); - $input->getOption('find-sort-by-key') and $options['find']['sort_by']['key'] = $input->getOption('find-sort-by-key'); + $input->getOption('find-exclude') and $options['find']['exclude'] = $input->getOption('find-exclude'); + $input->getOption('find-contains') and $options['find']['contains'] = $input->getOption('find-contains'); + $input->getOption('find-not-contains') and $options['find']['not_contains'] = $input->getOption('find-not-contains'); + $input->getOption('find-path') and $options['find']['path'] = $input->getOption('find-path'); + $input->getOption('find-sort-by-key') and $options['find']['sort_by']['key'] = $input->getOption('find-sort-by-key'); $input->getOption('find-sort-by-direction') and $options['find']['sort_by']['direction'] = $input->getOption('find-sort-by-direction'); $input->getOption('filter-group-by') and $options['filter']['group_by'] = $input->getOption('filter-group-by'); - $input->getOption('filter-return') and $options['filter']['return'] = $input->getOption('filter-return'); - + $input->getOption('filter-return') and $options['filter']['return'] = $input->getOption('filter-return'); + if ($input->getOption('filter-where')) { $filterWhere = $input->getOption('filter-where'); - - foreach ($filterWhere as $key => $value) { + foreach ($filterWhere as $key => $value) { if (strings($value)->isJson()) { $whereValues = serializers()->json()->decode($value); } else { parse_str($value, $whereValues); } - + $where[] = $whereValues; } - + $options['filter']['where'] = $where; } - - $innerData = []; + + $innerData = []; $innerDataString = ''; - + $data = entries()->fetch('tokens/' . $id, $options); - if (count($data) > 0) { - if (isset($options['collection']) && $options['collection'] == true) { - foreach ($data->toArray() as $item) { - foreach(collection($item)->dot() as $key => $value) { - $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); - } - $innerData[] = $innerDataString; - $innerDataString = ''; - } - } else { - foreach(collection($data)->dot() as $key => $value) { - $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); - } - $innerData[] = $innerDataString; - $innerDataString = ''; - } - - foreach ($innerData as $item) { - $output->write( - renderToString( - div($item, 'px-2 border-square border-color-success') - ) - ); - } - - return Command::SUCCESS; - } else { + if (count($data) <= 0) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } + + if (isset($options['collection']) && $options['collection'] === true) { + foreach ($data->toArray() as $item) { + foreach (collection($item)->dot() as $key => $value) { + $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); + } + + $innerData[] = $innerDataString; + $innerDataString = ''; + } + } else { + foreach (collection($data)->dot() as $key => $value) { + $innerDataString .= renderToString(span('[b][color=success]' . $key . '[/color][/b]: ' . $value) . PHP_EOL); + } + + $innerData[] = $innerDataString; + $innerDataString = ''; + } + + foreach ($innerData as $item) { + $output->write( + renderToString( + div($item, 'px-2 border-square border-color-success') + ) + ); + } + + return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensGenerateCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensGenerateCommand.php index 0658e474..610d5ddc 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensGenerateCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensGenerateCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,12 +17,13 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Tokens; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; + +use function Flextype\generateToken; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\generateToken; class TokensGenerateCommand extends Command { @@ -37,11 +38,13 @@ class TokensGenerateCommand extends Command { $output->write( renderToString( - div('Token [b]' . generateToken($input->getArgument('length') ?? 16) . '[/b] generated.', - 'color-success px-2 py-1') + div( + 'Token [b]' . generateToken($input->getArgument('length') ?? 16) . '[/b] generated.', + 'color-success px-2 py-1' + ) ) ); return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensGenerateHashCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensGenerateHashCommand.php index 7eb2aa24..350692f4 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensGenerateHashCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensGenerateHashCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,13 +17,14 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Tokens; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; -use function Thermage\div; -use function Thermage\renderToString; + use function Flextype\generateToken; use function Flextype\generateTokenHash; +use function Thermage\div; +use function Thermage\renderToString; class TokensGenerateHashCommand extends Command { @@ -40,11 +41,13 @@ class TokensGenerateHashCommand extends Command $output->write( renderToString( - div('Hash [b]' . generateTokenHash($token) . '[/b] for token [b]' . $token . '[/b] generated.', - 'color-success px-2 py-1') + div( + 'Hash [b]' . generateTokenHash($token) . '[/b] for token [b]' . $token . '[/b] generated.', + 'color-success px-2 py-1' + ) ) ); return Command::SUCCESS; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensHasCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensHasCommand.php index fe232066..48a67d71 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensHasCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensHasCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,10 +20,10 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Style\SymfonyStyle; + +use function Flextype\entries; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\entries; class TokensHasCommand extends Command { @@ -41,19 +41,25 @@ class TokensHasCommand extends Command if (entries()->has($id)) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] exists.', - 'color-success px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] exists.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Token entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Token entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensUpdateCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensUpdateCommand.php index 2afc7a7c..10830b55 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensUpdateCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensUpdateCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -20,11 +20,13 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + +use function Flextype\entries; +use function Flextype\serializers; +use function Glowy\Strings\strings; +use function parse_str; use function Thermage\div; use function Thermage\renderToString; -use function Glowy\Strings\strings; -use function Flextype\serializers; -use function Flextype\entries; class TokensUpdateCommand extends Command { @@ -54,29 +56,38 @@ class TokensUpdateCommand extends Command if (! entries()->has($id)) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] doesn\'t exists.', - 'color-danger px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] doesn\'t exists.', + 'color-danger px-2 py-1' + ) ) ); + return Command::FAILURE; } - + if (entries()->update($id, $dataToSave)) { $output->write( renderToString( - div('Token entry [b]' . $id . '[/b] updated.', - 'color-success px-2 py-1') + div( + 'Token entry [b]' . $id . '[/b] updated.', + 'color-success px-2 py-1' + ) ) ); + return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Token entry [b]' . $id . '[/b] wasn\'t updated.', - 'color-danger px-2 py-1') - ) - ); - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Token entry [b]' . $id . '[/b] wasn\'t updated.', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php b/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php index a756f71b..a8d6ac65 100644 --- a/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php +++ b/src/flextype/core/Console/Commands/Tokens/TokensVerifyHashCommand.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,13 +17,14 @@ declare(strict_types=1); namespace Flextype\Console\Commands\Tokens; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Input\InputArgument; -use Symfony\Component\Console\Style\SymfonyStyle; + +use function dd; +use function Flextype\verifyTokenHash; use function Thermage\div; use function Thermage\renderToString; -use function Flextype\verifyTokenHash; class TokensVerifyHashCommand extends Command { @@ -41,21 +42,25 @@ class TokensVerifyHashCommand extends Command if (verifyTokenHash($input->getArgument('token'), $input->getArgument('token-hash'))) { $output->write( renderToString( - div('Token [b]' . $input->getArgument('token') . ' is verified', - 'color-success px-2 py-1') + div( + 'Token [b]' . $input->getArgument('token') . ' is verified', + 'color-success px-2 py-1' + ) ) ); return Command::SUCCESS; - } else { - $output->write( - renderToString( - div('Token [b]' . $input->getArgument('token') . ' isn\'t verified', - 'color-danger px-2 py-1') - ) - ); - - return Command::FAILURE; } + + $output->write( + renderToString( + div( + 'Token [b]' . $input->getArgument('token') . ' isn\'t verified', + 'color-danger px-2 py-1' + ) + ) + ); + + return Command::FAILURE; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Console/FlextypeConsole.php b/src/flextype/core/Console/FlextypeConsole.php index d52df386..d2efa53b 100644 --- a/src/flextype/core/Console/FlextypeConsole.php +++ b/src/flextype/core/Console/FlextypeConsole.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,43 +16,42 @@ declare(strict_types=1); namespace Flextype\Console; -use Symfony\Component\Console\Application as ConsoleApplication; use Flextype\Console\Commands\AboutCommand; -use Flextype\Console\Commands\Entries\EntriesCreateCommand; -use Flextype\Console\Commands\Entries\EntriesFetchCommand; -use Flextype\Console\Commands\Entries\EntriesUpdateCommand; -use Flextype\Console\Commands\Entries\EntriesDeleteCommand; -use Flextype\Console\Commands\Entries\EntriesCopyCommand; -use Flextype\Console\Commands\Entries\EntriesMoveCommand; -use Flextype\Console\Commands\Entries\EntriesHasCommand; -use Flextype\Console\Commands\Cache\CacheDeleteCommand; -use Flextype\Console\Commands\Cache\CacheSetCommand; -use Flextype\Console\Commands\Cache\CacheGetCommand; -use Flextype\Console\Commands\Cache\CacheGetMultipleCommand; -use Flextype\Console\Commands\Cache\CacheSetMultipleCommand; -use Flextype\Console\Commands\Cache\CacheDeleteMultipleCommand; use Flextype\Console\Commands\Cache\CacheClearCommand; -use Flextype\Console\Commands\Cache\CacheClearRoutesCommand; use Flextype\Console\Commands\Cache\CacheClearConfigCommand; use Flextype\Console\Commands\Cache\CacheClearDataCommand; +use Flextype\Console\Commands\Cache\CacheClearRoutesCommand; +use Flextype\Console\Commands\Cache\CacheDeleteCommand; +use Flextype\Console\Commands\Cache\CacheDeleteMultipleCommand; +use Flextype\Console\Commands\Cache\CacheGetCommand; +use Flextype\Console\Commands\Cache\CacheGetMultipleCommand; use Flextype\Console\Commands\Cache\CacheHasCommand; +use Flextype\Console\Commands\Cache\CacheSetCommand; +use Flextype\Console\Commands\Cache\CacheSetMultipleCommand; +use Flextype\Console\Commands\Entries\EntriesCopyCommand; +use Flextype\Console\Commands\Entries\EntriesCreateCommand; +use Flextype\Console\Commands\Entries\EntriesDeleteCommand; +use Flextype\Console\Commands\Entries\EntriesFetchCommand; +use Flextype\Console\Commands\Entries\EntriesHasCommand; +use Flextype\Console\Commands\Entries\EntriesMoveCommand; +use Flextype\Console\Commands\Entries\EntriesUpdateCommand; +use Flextype\Console\Commands\Tokens\TokensCreateCommand; +use Flextype\Console\Commands\Tokens\TokensDeleteCommand; +use Flextype\Console\Commands\Tokens\TokensFetchCommand; use Flextype\Console\Commands\Tokens\TokensGenerateCommand; use Flextype\Console\Commands\Tokens\TokensGenerateHashCommand; -use Flextype\Console\Commands\Tokens\TokensVerifyHashCommand; -use Flextype\Console\Commands\Tokens\TokensCreateCommand; -use Flextype\Console\Commands\Tokens\TokensFetchCommand; -use Flextype\Console\Commands\Tokens\TokensUpdateCommand; -use Flextype\Console\Commands\Tokens\TokensDeleteCommand; -use Flextype\Console\Commands\Tokens\TokensCopyCommand; -use Flextype\Console\Commands\Tokens\TokensMoveCommand; use Flextype\Console\Commands\Tokens\TokensHasCommand; +use Flextype\Console\Commands\Tokens\TokensUpdateCommand; +use Flextype\Console\Commands\Tokens\TokensVerifyHashCommand; +use Symfony\Component\Console\Application as ConsoleApplication; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; + use function Flextype\console; class FlextypeConsole extends ConsoleApplication { - public function run(InputInterface $input = null, OutputInterface $output = null): int + public function run(?InputInterface $input = null, ?OutputInterface $output = null): int { // Add Console Commands console()->add(new AboutCommand()); @@ -85,4 +84,4 @@ class FlextypeConsole extends ConsoleApplication return parent::run(); } -} \ No newline at end of file +} diff --git a/src/flextype/core/Endpoints/Api.php b/src/flextype/core/Endpoints/Api.php index 8b0fa94b..9b14a58e 100644 --- a/src/flextype/core/Endpoints/Api.php +++ b/src/flextype/core/Endpoints/Api.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -21,13 +21,12 @@ use Psr\Http\Message\ResponseInterface; use function array_keys; use function array_merge; use function count; -use function in_array; -use function is_string; -use function password_verify; +use function Flextype\entries; +use function Flextype\registry; use function Flextype\serializers; use function Flextype\verifyTokenHash; -use function Flextype\registry; -use function Flextype\entries; +use function in_array; +use function is_string; class Api { diff --git a/src/flextype/core/Endpoints/Cache.php b/src/flextype/core/Endpoints/Cache.php index fc7353df..5ad53257 100644 --- a/src/flextype/core/Endpoints/Cache.php +++ b/src/flextype/core/Endpoints/Cache.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. diff --git a/src/flextype/core/Endpoints/Entries.php b/src/flextype/core/Endpoints/Entries.php index e6687c41..e79caefc 100644 --- a/src/flextype/core/Endpoints/Entries.php +++ b/src/flextype/core/Endpoints/Entries.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,8 +19,8 @@ namespace Flextype\Endpoints; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use function Flextype\entries; use function count; +use function Flextype\entries; class Entries extends Api { diff --git a/src/flextype/core/Endpoints/Registry.php b/src/flextype/core/Endpoints/Registry.php index 1bd0fb66..706c514a 100644 --- a/src/flextype/core/Endpoints/Registry.php +++ b/src/flextype/core/Endpoints/Registry.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. diff --git a/src/flextype/core/Endpoints/Tokens.php b/src/flextype/core/Endpoints/Tokens.php index c7148532..2d47564e 100644 --- a/src/flextype/core/Endpoints/Tokens.php +++ b/src/flextype/core/Endpoints/Tokens.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,12 +19,12 @@ namespace Flextype\Endpoints; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use function array_merge; use function count; -use function Glowy\Filesystem\filesystem; +use function Flextype\entries; use function Flextype\generateToken; use function Flextype\generateTokenHash; use function Flextype\verifyTokenHash; -use function Flextype\entries; class Tokens extends Api { @@ -68,9 +68,9 @@ class Tokens extends Api { // Get Request Parsed Body $requestParsedBody = $request->getParsedBody(); - + // Validate Api Request - if ( + if ( count($result = $this->validateApiRequest([ 'request' => $request, 'api' => 'tokens', @@ -99,9 +99,9 @@ class Tokens extends Api { // Get Request Parsed Body $requestParsedBody = $request->getParsedBody(); - + // Validate Api Request - if ( + if ( count($result = $this->validateApiRequest([ 'request' => $request, 'api' => 'tokens', @@ -225,7 +225,7 @@ class Tokens extends Api // Fetch entry $entryData = entries()->fetch('tokens/' . $requestParsedBody['id'])->toArray(); - + // Return response if (count($entryData) > 0) { return $this->getApiResponse($response, $entryData, 200); @@ -234,7 +234,6 @@ class Tokens extends Api return $this->getApiResponse($response, [], 404); } - /** * Delete token entry. * diff --git a/src/flextype/core/Entries/Directives/ExpressionsDirective.php b/src/flextype/core/Entries/Directives/ExpressionsDirective.php index 0fc73f2a..0711ae9a 100644 --- a/src/flextype/core/Entries/Directives/ExpressionsDirective.php +++ b/src/flextype/core/Entries/Directives/ExpressionsDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,15 +14,13 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; use function Flextype\emitter; -use function Flextype\registry; use function Flextype\entries; use function Flextype\expression; +use function Flextype\registry; // Directive: [[ ]] emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.expressions.enabled')) { return; } @@ -36,13 +34,13 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $closingTag = registry()->get('flextype.settings.entries.directives.expressions.closing_tag'); $field = entries()->registry()->get('methods.fetch.field'); - + if (is_string($field['value'])) { - $field['value'] = preg_replace_callback('/' . $selfQuote($openingTag) . ' (.*?) ' . $selfQuote($closingTag) . '/s', function($matches) { + $field['value'] = preg_replace_callback('/' . $selfQuote($openingTag) . ' (.*?) ' . $selfQuote($closingTag) . '/s', function ($matches) { return expression()->evaluate($matches[1]); }, $field['value']); } entries()->registry()->set('methods.fetch.field.key', $field['key']); entries()->registry()->set('methods.fetch.field.value', $field['value']); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Directives/MarkdownDirective.php b/src/flextype/core/Entries/Directives/MarkdownDirective.php index cb480816..4e33e0cb 100644 --- a/src/flextype/core/Entries/Directives/MarkdownDirective.php +++ b/src/flextype/core/Entries/Directives/MarkdownDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,23 +14,21 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; -use function Glowy\Strings\strings; use function Flextype\emitter; -use function Flextype\registry; use function Flextype\entries; use function Flextype\parsers; +use function Flextype\registry; +use function Glowy\Strings\strings; // Directive: @markdown emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.markdown.enabled')) { return; } // Save markdown cache state to restore it later $markdownCacheState = registry()->get('flextype.settings.parsers.markdown.cache'); - + // Set markdown cache to false registry()->set('flextype.settings.parsers.markdown.cache', false); @@ -43,10 +41,10 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $field['value'] = parsers()->markdown()->parse($field['value']); } } - + entries()->registry()->set('methods.fetch.field.key', $field['key']); entries()->registry()->set('methods.fetch.field.value', $field['value']); // Restore markdown cache state registry()->set('flextype.settings.parsers.markdown.cache', $markdownCacheState); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Directives/PhpDirective.php b/src/flextype/core/Entries/Directives/PhpDirective.php index 51711901..6db63152 100644 --- a/src/flextype/core/Entries/Directives/PhpDirective.php +++ b/src/flextype/core/Entries/Directives/PhpDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,15 +14,13 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; -use function Glowy\Strings\strings; use function Flextype\emitter; use function Flextype\entries; use function Flextype\registry; +use function Glowy\Strings\strings; // Directive: @php emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.php.enabled')) { return; } @@ -40,7 +38,7 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $field['value'] = ob_get_clean(); } } - + entries()->registry()->set('methods.fetch.field.key', $field['key']); entries()->registry()->set('methods.fetch.field.value', $field['value']); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Directives/ShortcodesDirective.php b/src/flextype/core/Entries/Directives/ShortcodesDirective.php index 5c1e10fa..f5d0b41a 100644 --- a/src/flextype/core/Entries/Directives/ShortcodesDirective.php +++ b/src/flextype/core/Entries/Directives/ShortcodesDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,28 +14,26 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; -use function Glowy\Strings\strings; use function Flextype\emitter; -use function Flextype\registry; use function Flextype\entries; use function Flextype\parsers; +use function Flextype\registry; +use function Glowy\Strings\strings; // Directive: @shortcodes emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.shortcodes.enabled')) { return; } // Save shortcodes cache state to restore it later $shortcodesCacheState = registry()->get('flextype.settings.parsers.shortcodes.cache'); - + // Set shortcodes cache to false registry()->set('flextype.settings.parsers.shortcodes.cache', false); $field = entries()->registry()->get('methods.fetch.field'); - + if (is_string($field['value'])) { if (strings($field['value'])->contains('@shortcodes')) { $field['value'] = strings(parsers()->shortcodes()->parse($field['value']))->replace('@shortcodes', '')->trim()->toString(); @@ -49,4 +47,4 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { // Restore shortcodes cache state registry()->set('flextype.settings.parsers.shortcodes.cache', $shortcodesCacheState); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Directives/TextileDirective.php b/src/flextype/core/Entries/Directives/TextileDirective.php index b911d136..d7fa1c1b 100644 --- a/src/flextype/core/Entries/Directives/TextileDirective.php +++ b/src/flextype/core/Entries/Directives/TextileDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,23 +14,21 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; -use function Glowy\Strings\strings; use function Flextype\emitter; -use function Flextype\registry; -use function Flextype\parsers; use function Flextype\entries; +use function Flextype\parsers; +use function Flextype\registry; +use function Glowy\Strings\strings; // Directive: @textile emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.textile.enabled')) { return; } // Save textile cache state to restore it later $textileCacheState = registry()->get('flextype.settings.parsers.textile.cache'); - + // Set textile cache to false registry()->set('flextype.settings.parsers.textile.cache', false); @@ -43,10 +41,10 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { $field['value'] = parsers()->textile()->parse($field['value']); } } - + entries()->registry()->set('methods.fetch.field.key', $field['key']); entries()->registry()->set('methods.fetch.field.value', $field['value']); // Restore textile cache state registry()->set('flextype.settings.parsers.textile.cache', $textileCacheState); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Directives/TypesDirective.php b/src/flextype/core/Entries/Directives/TypesDirective.php index f9565c22..3705e1df 100644 --- a/src/flextype/core/Entries/Directives/TypesDirective.php +++ b/src/flextype/core/Entries/Directives/TypesDirective.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -14,22 +14,20 @@ declare(strict_types=1); * Redistributions of files must retain the above copyright notice. */ -use Glowy\Arrays\Arrays as Collection; -use function Glowy\Strings\strings; +use function Flextype\collection; +use function Flextype\collectionFromQueryString; use function Flextype\emitter; use function Flextype\entries; use function Flextype\registry; use function Flextype\serializers; -use function Flextype\collectionFromQueryString; -use function Flextype\collection; +use function Glowy\Strings\strings; // Directive: @type[] emitter()->addListener('onEntriesFetchSingleField', static function (): void { - if (! registry()->get('flextype.settings.entries.directives.types.enabled')) { return; } - + $field = entries()->registry()->get('methods.fetch.field'); if (is_string($field['value'])) { @@ -73,4 +71,4 @@ emitter()->addListener('onEntriesFetchSingleField', static function (): void { entries()->registry()->set('methods.fetch.field.key', $field['key']); entries()->registry()->set('methods.fetch.field.value', $field['value']); -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Entries/Expressions/ActionsExpression.php b/src/flextype/core/Entries/Expressions/ActionsExpression.php index ceb20a68..60d55125 100644 --- a/src/flextype/core/Entries/Expressions/ActionsExpression.php +++ b/src/flextype/core/Entries/Expressions/ActionsExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\actions; class ActionsExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('actions', fn() => '\Flextype\actions()', fn($arguments) => actions()) - ]; + return [new ExpressionFunction('actions', static fn () => '\Flextype\actions()', static fn ($arguments) => actions())]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/CollectionExpression.php b/src/flextype/core/Entries/Expressions/CollectionExpression.php index 070dab8e..bd24b624 100644 --- a/src/flextype/core/Entries/Expressions/CollectionExpression.php +++ b/src/flextype/core/Entries/Expressions/CollectionExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,11 +18,12 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\collection; use function Flextype\collectionFromJson; +use function Flextype\collectionFromQueryString; use function Flextype\collectionFromString; use function Flextype\collectionWithRange; -use function Flextype\collectionFromQueryString; use function Flextype\filterCollection; class CollectionExpression implements ExpressionFunctionProviderInterface @@ -30,12 +31,12 @@ class CollectionExpression implements ExpressionFunctionProviderInterface public function getFunctions() { return [ - new ExpressionFunction('collection', fn($items = null) => '\Flextype\collection($items)', fn($arguments, $items = null) => collection($items)), - new ExpressionFunction('collectionFromJson', fn(string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => '\Flextype\ccollectionFromJson($input, $assoc, $depth, $flags)', fn($arguments, string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => collectionFromJson($input, $assoc, $depth, $flags)), - new ExpressionFunction('collectionFromString', fn(string $string, string $separator) => '\Flextype\collectionFromString($string, $separator)', fn($arguments, string $string, string $separator) => collectionFromString($string, $separator)), - new ExpressionFunction('collectionWithRange', fn($low, $high, int $step = 1) => '\Flextype\collectionWithRange($low, $high, $step)', fn($arguments, $low, $high, int $step = 1) => collectionWithRange($low, $high, $step)), - new ExpressionFunction('collectionFromQueryString', fn(string $string) => '\Flextype\collectionFromQueryString($string)', fn($arguments, string $string) => collectionFromQueryString($string)), - new ExpressionFunction('filterCollection', fn($items = [], array $options = []) => '\Flextype\filterCollection($items, $options)', fn($arguments, $items = [], array $options = []) => filterCollection($items, $options)), + new ExpressionFunction('collection', static fn ($items = null) => '\Flextype\collection($items)', static fn ($arguments, $items = null) => collection($items)), + new ExpressionFunction('collectionFromJson', static fn (string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => '\Flextype\ccollectionFromJson($input, $assoc, $depth, $flags)', static fn ($arguments, string $input, bool $assoc = true, int $depth = 512, int $flags = 0) => collectionFromJson($input, $assoc, $depth, $flags)), + new ExpressionFunction('collectionFromString', static fn (string $string, string $separator) => '\Flextype\collectionFromString($string, $separator)', static fn ($arguments, string $string, string $separator) => collectionFromString($string, $separator)), + new ExpressionFunction('collectionWithRange', static fn ($low, $high, int $step = 1) => '\Flextype\collectionWithRange($low, $high, $step)', static fn ($arguments, $low, $high, int $step = 1) => collectionWithRange($low, $high, $step)), + new ExpressionFunction('collectionFromQueryString', static fn (string $string) => '\Flextype\collectionFromQueryString($string)', static fn ($arguments, string $string) => collectionFromQueryString($string)), + new ExpressionFunction('filterCollection', static fn ($items = [], array $options = []) => '\Flextype\filterCollection($items, $options)', static fn ($arguments, $items = [], array $options = []) => filterCollection($items, $options)), ]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/ConstExpression.php b/src/flextype/core/Entries/Expressions/ConstExpression.php index 6b0e32d2..7e02cf33 100644 --- a/src/flextype/core/Entries/Expressions/ConstExpression.php +++ b/src/flextype/core/Entries/Expressions/ConstExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,12 +19,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; +use function constant; +use function defined; + class ConstExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('const', fn(string $const) => "defined($const) ? constant($const) : ''", fn($arguments, string $const) => defined($const) ? constant($const) : '') - ]; + return [new ExpressionFunction('const', static fn (string $const) => "defined($const) ? constant($const) : ''", static fn ($arguments, string $const) => defined($const) ? constant($const) : '')]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/CsrfExpression.php b/src/flextype/core/Entries/Expressions/CsrfExpression.php index 0c0c9e8e..49ae5946 100644 --- a/src/flextype/core/Entries/Expressions/CsrfExpression.php +++ b/src/flextype/core/Entries/Expressions/CsrfExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\csrf; class CsrfExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('csrf', fn() => '', fn() => '') - ]; + return [new ExpressionFunction('csrf', static fn () => '', static fn () => '')]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/EntriesExpression.php b/src/flextype/core/Entries/Expressions/EntriesExpression.php index c736ac25..2b858aca 100644 --- a/src/flextype/core/Entries/Expressions/EntriesExpression.php +++ b/src/flextype/core/Entries/Expressions/EntriesExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,19 +16,18 @@ declare(strict_types=1); namespace Flextype\Entries\Expressions; -use Symfony\Component\ExpressionLanguage\ExpressionFunction; -use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; use Glowy\Arrays\Arrays as Collection; use Glowy\Macroable\Macroable; +use Symfony\Component\ExpressionLanguage\ExpressionFunction; +use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\entries; class EntriesExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('entries', fn() => '(new EntriesTwigExpressionsMethods())', fn($arguments) => (new EntriesTwigExpressionsMethods())) - ]; + return [new ExpressionFunction('entries', static fn () => '(new EntriesTwigExpressionsMethods())', static fn ($arguments) => (new EntriesTwigExpressionsMethods()))]; } } @@ -42,9 +41,9 @@ class EntriesTwigExpressionsMethods * @param string $id Unique identifier of the entry. * @param array $options Options array. * - * @access public - * * @return self Returns instance of The Arrays class. + * + * @access public */ public function fetch(string $id, array $options = []): Collection { @@ -76,4 +75,4 @@ class EntriesTwigExpressionsMethods { return entries()->entries->has($id); } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/FieldExpression.php b/src/flextype/core/Entries/Expressions/FieldExpression.php index d40c45d3..740d0677 100644 --- a/src/flextype/core/Entries/Expressions/FieldExpression.php +++ b/src/flextype/core/Entries/Expressions/FieldExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\entries; class FieldExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('field', fn(string $field) => "\Flextype\entries()->registry()->get('methods.fetch.result.' . $field . ')'", fn($arguments, string $field) => entries()->registry()->get('methods.fetch.result.' . $field)) - ]; + return [new ExpressionFunction('field', static fn (string $field) => "\Flextype\entries()->registry()->get('methods.fetch.result.' . $field . ')'", static fn ($arguments, string $field) => entries()->registry()->get('methods.fetch.result.' . $field))]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/FilesystemExpression.php b/src/flextype/core/Entries/Expressions/FilesystemExpression.php index 7f3f636b..f1e90316 100644 --- a/src/flextype/core/Entries/Expressions/FilesystemExpression.php +++ b/src/flextype/core/Entries/Expressions/FilesystemExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,20 +16,18 @@ declare(strict_types=1); namespace Flextype\Entries\Expressions; +use Glowy\Macroable\Macroable; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; use Symfony\Component\Finder\Finder; -use Glowy\Arrays\Arrays as Collection; + use function Glowy\Filesystem\filesystem; -use Glowy\Macroable\Macroable; class FilesystemExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('filesystem', fn() => '(new FilesystemExpressionMethods())', fn($arguments) => (new FilesystemExpressionMethods())) - ]; + return [new ExpressionFunction('filesystem', static fn () => '(new FilesystemExpressionMethods())', static fn ($arguments) => (new FilesystemExpressionMethods()))]; } } @@ -119,10 +117,8 @@ class FilesystemFileExpressionMethods * Path property * * Current file absolute path - * - * @var string|null */ - public $path; + public ?string $path = null; /** * Constructor @@ -139,7 +135,7 @@ class FilesystemFileExpressionMethods * * @return string|false The file contents or false on failure. */ - public function get() + public function get(): string|false { return filesystem()->file($this->path)->get(); } @@ -293,10 +289,8 @@ class FilesystemDirectoryExpressionMethods * Path property * * Current directory path. - * - * @var string|null */ - public $path; + public ?string $path = null; /** * Constructor diff --git a/src/flextype/core/Entries/Expressions/I18nExpression.php b/src/flextype/core/Entries/Expressions/I18nExpression.php index 3a7394fb..6ccd4e14 100644 --- a/src/flextype/core/Entries/Expressions/I18nExpression.php +++ b/src/flextype/core/Entries/Expressions/I18nExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,6 +18,7 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\__; class I18nExpression implements ExpressionFunctionProviderInterface @@ -25,8 +26,8 @@ class I18nExpression implements ExpressionFunctionProviderInterface public function getFunctions() { return [ - new ExpressionFunction('tr', fn(string $translate, array $values = [], string $locale = null) => '\Flextype\__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)), - new ExpressionFunction('__', fn(string $translate, array $values = [], string $locale = null) => '\Flextype\__($translate, $values, $locale)', fn($arguments, string $translate, array $values = [], string $locale = null) => __($translate, $values, $locale)), + new ExpressionFunction('tr', static fn (string $translate, array $values = [], ?string $locale = null) => '\Flextype\__($translate, $values, $locale)', static fn ($arguments, string $translate, array $values = [], ?string $locale = null) => __($translate, $values, $locale)), + new ExpressionFunction('__', static fn (string $translate, array $values = [], ?string $locale = null) => '\Flextype\__($translate, $values, $locale)', static fn ($arguments, string $translate, array $values = [], ?string $locale = null) => __($translate, $values, $locale)), ]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/ParsersExpression.php b/src/flextype/core/Entries/Expressions/ParsersExpression.php index 97b27d55..a4ee9f6e 100644 --- a/src/flextype/core/Entries/Expressions/ParsersExpression.php +++ b/src/flextype/core/Entries/Expressions/ParsersExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\parsers; class ParsersExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('parsers', fn() => '\Flextype\parsers()', fn($arguments) => parsers()) - ]; + return [new ExpressionFunction('parsers', static fn () => '\Flextype\parsers()', static fn ($arguments) => parsers())]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/RegistryExpression.php b/src/flextype/core/Entries/Expressions/RegistryExpression.php index 93f315ed..fecb82f9 100644 --- a/src/flextype/core/Entries/Expressions/RegistryExpression.php +++ b/src/flextype/core/Entries/Expressions/RegistryExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\registry; class RegistryExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('registry', fn() => '\Flextype\registry()', fn($arguments) => registry()) - ]; + return [new ExpressionFunction('registry', static fn () => '\Flextype\registry()', static fn ($arguments) => registry())]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/SerializersExpression.php b/src/flextype/core/Entries/Expressions/SerializersExpression.php index 23438fbd..592cd960 100644 --- a/src/flextype/core/Entries/Expressions/SerializersExpression.php +++ b/src/flextype/core/Entries/Expressions/SerializersExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\serializers; class SerializersExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('serializers', fn() => '\Flextype\serializers()', fn($arguments) => serializers()) - ]; + return [new ExpressionFunction('serializers', static fn () => '\Flextype\serializers()', static fn ($arguments) => serializers())]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/SlugifyExpression.php b/src/flextype/core/Entries/Expressions/SlugifyExpression.php index d338a0ae..3dde430a 100644 --- a/src/flextype/core/Entries/Expressions/SlugifyExpression.php +++ b/src/flextype/core/Entries/Expressions/SlugifyExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\slugify; class SlugifyExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('slugify', fn() => '\Flextype\slugify()', fn($arguments) => slugify()) - ]; + return [new ExpressionFunction('slugify', static fn () => '\Flextype\slugify()', static fn ($arguments) => slugify())]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/StringsExpression.php b/src/flextype/core/Entries/Expressions/StringsExpression.php index 7b32d08c..000617a5 100644 --- a/src/flextype/core/Entries/Expressions/StringsExpression.php +++ b/src/flextype/core/Entries/Expressions/StringsExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,16 +16,15 @@ declare(strict_types=1); namespace Flextype\Entries\Expressions; -use function Glowy\Strings\strings; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; +use function Glowy\Strings\strings; + class StringsExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('strings', fn($str) => '\Glowy\Strings\strings($str)', fn($arguments, $str) => strings($str)) - ]; + return [new ExpressionFunction('strings', static fn ($str) => '\Glowy\Strings\strings($str)', static fn ($arguments, $str) => strings($str))]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/UrlExpression.php b/src/flextype/core/Entries/Expressions/UrlExpression.php index 1578f40b..4d066910 100644 --- a/src/flextype/core/Entries/Expressions/UrlExpression.php +++ b/src/flextype/core/Entries/Expressions/UrlExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,34 +16,36 @@ declare(strict_types=1); namespace Flextype\Entries\Expressions; +use Psr\Http\Message\ServerRequestInterface; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; -use function Flextype\urlFor; + use function Flextype\fullUrlFor; -use function Flextype\isCurrentUrl; -use function Flextype\getCurrentUrl; +use function Flextype\getAbsoluteUrl; use function Flextype\getBasePath; use function Flextype\getBaseUrl; -use function Flextype\getAbsoluteUrl; +use function Flextype\getCurrentUrl; use function Flextype\getProjectUrl; use function Flextype\getUriString; +use function Flextype\isCurrentUrl; use function Flextype\redirect; +use function Flextype\urlFor; class UrlExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { return [ - new ExpressionFunction('urlFor', fn(string $routeName, array $data = [], array $queryParams = []) => '\Flextype\urlFor($routeName, $data, $queryParams)', fn(string $routeName, array $data = [], array $queryParams = []) => urlFor($routeName, $data, $queryParams)), - new ExpressionFunction('fullUrlFor', fn(\Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => '\Flextype\fullUrlFor($request, $routeName, $data, $queryParams)', fn(\Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => fullUrlFor($request, $routeName, $data = [], $queryParams = [])), - new ExpressionFunction('isCurrentUrl', fn(\Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = []) => '\Flextype\isCurrentUrl($request, $routeName, $data)', fn(\Psr\Http\Message\ServerRequestInterface $request, string $routeName, array $data = []) => isCurrentUrl($request, $routeName, $data = [])), - new ExpressionFunction('getCurrentUrl', fn(\Psr\Http\Message\ServerRequestInterface $request, bool $withQueryString = false) => '\Flextype\getCurrentUrl($request, $withQueryString)', fn(\Psr\Http\Message\ServerRequestInterface $request, bool $withQueryString = false) => getCurrentUrl($request, $withQueryString)), - new ExpressionFunction('getBasePath', fn() => '\Flextype\getBasePath()', fn() => getBasePath()), - new ExpressionFunction('getBaseUrl', fn() => '\Flextype\getBaseUrl()', fn() => getBaseUrl()), - new ExpressionFunction('getAbsoluteUrl', fn() => '\Flextype\getAbsoluteUrl()', fn() => getAbsoluteUrl()), - new ExpressionFunction('getProjectUrl', fn() => '\Flextype\getProjectUrl()', fn() => getProjectUrl()), - new ExpressionFunction('getUriString', fn() => '\Flextype\getUriString()', fn() => getUriString()), - new ExpressionFunction('redirect', fn(string $routeName, array $data = [], array $queryParams = [], int $status = 301) => '\Flextype\redirect($routeName, $data, $queryParams, $status)', fn(string $routeName, array $data = [], array $queryParams = [], int $status = 301) => redirect($routeName, $data, $queryParams, $status)) + new ExpressionFunction('urlFor', static fn (string $routeName, array $data = [], array $queryParams = []) => '\Flextype\urlFor($routeName, $data, $queryParams)', static fn (string $routeName, array $data = [], array $queryParams = []) => urlFor($routeName, $data, $queryParams)), + new ExpressionFunction('fullUrlFor', static fn (ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => '\Flextype\fullUrlFor($request, $routeName, $data, $queryParams)', static fn (ServerRequestInterface $request, string $routeName, array $data = [], array $queryParams = []) => fullUrlFor($request, $routeName, $data = [], $queryParams = [])), + new ExpressionFunction('isCurrentUrl', static fn (ServerRequestInterface $request, string $routeName, array $data = []) => '\Flextype\isCurrentUrl($request, $routeName, $data)', static fn (ServerRequestInterface $request, string $routeName, array $data = []) => isCurrentUrl($request, $routeName, $data = [])), + new ExpressionFunction('getCurrentUrl', static fn (ServerRequestInterface $request, bool $withQueryString = false) => '\Flextype\getCurrentUrl($request, $withQueryString)', static fn (ServerRequestInterface $request, bool $withQueryString = false) => getCurrentUrl($request, $withQueryString)), + new ExpressionFunction('getBasePath', static fn () => '\Flextype\getBasePath()', static fn () => getBasePath()), + new ExpressionFunction('getBaseUrl', static fn () => '\Flextype\getBaseUrl()', static fn () => getBaseUrl()), + new ExpressionFunction('getAbsoluteUrl', static fn () => '\Flextype\getAbsoluteUrl()', static fn () => getAbsoluteUrl()), + new ExpressionFunction('getProjectUrl', static fn () => '\Flextype\getProjectUrl()', static fn () => getProjectUrl()), + new ExpressionFunction('getUriString', static fn () => '\Flextype\getUriString()', static fn () => getUriString()), + new ExpressionFunction('redirect', static fn (string $routeName, array $data = [], array $queryParams = [], int $status = 301) => '\Flextype\redirect($routeName, $data, $queryParams, $status)', static fn (string $routeName, array $data = [], array $queryParams = [], int $status = 301) => redirect($routeName, $data, $queryParams, $status)), ]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Entries/Expressions/VarExpression.php b/src/flextype/core/Entries/Expressions/VarExpression.php index 9fba6945..565fd0e6 100644 --- a/src/flextype/core/Entries/Expressions/VarExpression.php +++ b/src/flextype/core/Entries/Expressions/VarExpression.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,13 @@ namespace Flextype\Entries\Expressions; use Symfony\Component\ExpressionLanguage\ExpressionFunction; use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface; + use function Flextype\entries; class VarExpression implements ExpressionFunctionProviderInterface { public function getFunctions() { - return [ - new ExpressionFunction('var', fn(string $var) => "\Flextype\entries()->registry()->get('methods.fetch.result.vars.' . $var . ')'", fn($arguments, string $var) => entries()->registry()->get('methods.fetch.result.vars.' . $var)) - ]; + return [new ExpressionFunction('var', static fn (string $var) => "\Flextype\entries()->registry()->get('methods.fetch.result.vars.' . $var . ')'", static fn ($arguments, string $var) => entries()->registry()->get('methods.fetch.result.vars.' . $var))]; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Flextype.php b/src/flextype/core/Flextype.php index 264542eb..0c3c2c27 100644 --- a/src/flextype/core/Flextype.php +++ b/src/flextype/core/Flextype.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -31,22 +31,16 @@ final class Flextype /** * The Flextype instance. - * - * @var Flextype|null */ private static Flextype|null $instance = null; /** * The Flextype Application. - * - * @var App */ private static App $app; /** * The Flextype Application Container. - * - * @var Container */ private static Container $container; diff --git a/src/flextype/core/I18n.php b/src/flextype/core/I18n.php index 03d3bdd4..481cb8f5 100644 --- a/src/flextype/core/I18n.php +++ b/src/flextype/core/I18n.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,6 +16,8 @@ declare(strict_types=1); namespace Flextype; +use function strtr; + class I18n { /** @@ -23,14 +25,12 @@ class I18n * * @var array */ - public static $dictionary = []; + public static array $dictionary = []; /** * Default locale - * - * @var string */ - public static $locale = 'en_US'; + public static string $locale = 'en_US'; /** * Add translation keys @@ -43,16 +43,15 @@ class I18n * * @param string $translates Translation keys and values to add * @param string $locale Locale - * @return void */ - public static function add(array $translates, string $locale = null) : void + public static function add(array $translates, ?string $locale = null): void { - $locale = ($locale === null) ? I18n::$locale : $locale; + $locale ??= self::$locale; - if (isset(I18n::$dictionary[$locale])) { - I18n::$dictionary[$locale] += $translates; + if (isset(self::$dictionary[$locale])) { + self::$dictionary[$locale] += $translates; } else { - I18n::$dictionary[$locale] = $translates; + self::$dictionary[$locale] = $translates; } } @@ -66,15 +65,14 @@ class I18n * @param string $translate Translate to find * @param array $values Values to replace in the translated text * @param string $locale Locale - * @return string */ - public static function find(string $translate, array $values = [], string $locale = null) : string + public static function find(string $translate, array $values = [], ?string $locale = null): string { - $locale = ($locale === null) ? I18n::$locale : $locale; + $locale ??= self::$locale; // Search current string to translate in the Dictionary - if (isset(I18n::$dictionary[$locale][$translate])) { - $translate = I18n::$dictionary[$locale][$translate]; + if (isset(self::$dictionary[$locale][$translate])) { + $translate = self::$dictionary[$locale][$translate]; $translate = empty($values) ? $translate : strtr($translate, $values); } else { $translate = $translate; @@ -83,4 +81,4 @@ class I18n // Return translation of a string return $translate; } -} \ No newline at end of file +} diff --git a/src/flextype/core/Middlewares/CsrfMiddleware.php b/src/flextype/core/Middlewares/CsrfMiddleware.php index aec4b744..49952b9f 100644 --- a/src/flextype/core/Middlewares/CsrfMiddleware.php +++ b/src/flextype/core/Middlewares/CsrfMiddleware.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,6 +19,7 @@ namespace Flextype\Middlewares; use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Server\RequestHandlerInterface as RequestHandler; use Slim\Psr7\Response; + use function Flextype\csrf; class CsrfMiddleware @@ -28,22 +29,21 @@ class CsrfMiddleware * * @param ServerRequest $request PSR-7 request * @param RequestHandler $handler PSR-15 request handler - * - * @return Response */ public function __invoke(Request $request, RequestHandler $handler): Response { $response = $handler->handle($request); - $data = $request->getParsedBody(); - + $data = $request->getParsedBody(); + if (isset($data[csrf()->getTokenName()])) { if (csrf()->isValid($data[csrf()->getTokenName()])) { return $response; - } else { - $response = new Response(); - $response->getBody()->write('This looks like a cross-site request forgery!'); - return $response; } + + $response = new Response(); + $response->getBody()->write('This looks like a cross-site request forgery!'); + + return $response; } return $response; diff --git a/src/flextype/core/Middlewares/WhoopsMiddleware.php b/src/flextype/core/Middlewares/WhoopsMiddleware.php index 4c7941c8..59a15906 100644 --- a/src/flextype/core/Middlewares/WhoopsMiddleware.php +++ b/src/flextype/core/Middlewares/WhoopsMiddleware.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,15 +16,14 @@ declare(strict_types=1); namespace Flextype\Middlewares; +use Flextype\Whoops; +use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; -use Psr\Http\Message\ServerRequestInterface; -use Psr\Http\Message\ResponseInterface; -use Flextype\Whoops; -class WhoopsMiddleware implements MiddlewareInterface +class WhoopsMiddleware implements MiddlewareInterface { - protected $settings = []; protected $handlers = []; @@ -34,7 +33,7 @@ class WhoopsMiddleware implements MiddlewareInterface * @param array $settings * @param array $handlers */ - public function __construct(array $settings = [], array $handlers = []) + public function __construct(array $settings = [], array $handlers = []) { $this->settings = $settings; $this->handlers = $handlers; @@ -42,12 +41,8 @@ class WhoopsMiddleware implements MiddlewareInterface /** * Handle the requests - * - * @param ServerRequestInterface $request - * @param RequestHandlerInterface $handler - * @return ResponseInterface */ - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $whoopsGuard = new Whoops($this->settings); $whoopsGuard->setRequest($request); @@ -56,5 +51,4 @@ class WhoopsMiddleware implements MiddlewareInterface return $handler->handle($request); } - -} \ No newline at end of file +} diff --git a/src/flextype/core/Parsers/Markdown.php b/src/flextype/core/Parsers/Markdown.php index f3d4a6af..08a69bd6 100644 --- a/src/flextype/core/Parsers/Markdown.php +++ b/src/flextype/core/Parsers/Markdown.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -107,7 +107,7 @@ final class Markdown * * @return mixed The MARKDOWN converted to a PHP value */ - public function parse(string $input) + public function parse(string $input): mixed { $cache = registry()->get('flextype.settings.parsers.markdown.cache.enabled'); @@ -130,7 +130,7 @@ final class Markdown /** * Get Cache ID for markdown. * - * @param string $input Input. + * @param string $input Input. * @param string $string String to append to the Cache ID. * * @return string Cache ID. diff --git a/src/flextype/core/Parsers/Parsers.php b/src/flextype/core/Parsers/Parsers.php index 351590a1..b9700bbe 100644 --- a/src/flextype/core/Parsers/Parsers.php +++ b/src/flextype/core/Parsers/Parsers.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. diff --git a/src/flextype/core/Parsers/Shortcodes.php b/src/flextype/core/Parsers/Shortcodes.php index 3d54fef7..19004c19 100644 --- a/src/flextype/core/Parsers/Shortcodes.php +++ b/src/flextype/core/Parsers/Shortcodes.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,17 +17,16 @@ declare(strict_types=1); namespace Flextype\Parsers; use Exception; - +use Thunder\Shortcode\Parser\RegularParser; use Thunder\Shortcode\ShortcodeFacade; use Thunder\Shortcode\Syntax\Syntax; -use Thunder\Shortcode\Parser\RegularParser; -use function Flextype\cache; use function count; use function file_exists; -use function is_array; +use function Flextype\cache; use function Flextype\registry; use function Glowy\Strings\strings; +use function is_array; final class Shortcodes { @@ -62,15 +61,17 @@ final class Shortcodes */ protected function __construct() { - $settings = registry()->get('flextype.settings.parsers.shortcodes'); + $settings = registry()->get('flextype.settings.parsers.shortcodes'); $this->shortcodeFacade = new ShortcodeFacade(); - $this->shortcodeFacade->setParser((new RegularParser((new Syntax($settings['opening_tag'], - $settings['closing_tag'], - $settings['closing_tag_marker'], - $settings['parameter_value_separator'], - $settings['parameter_value_delimiter']))))); + $this->shortcodeFacade->setParser((new RegularParser((new Syntax( + $settings['opening_tag'], + $settings['closing_tag'], + $settings['closing_tag_marker'], + $settings['parameter_value_separator'], + $settings['parameter_value_delimiter'] + ))))); } - + /** * Gets the instance via lazy initialization (created on first usage). */ @@ -93,10 +94,8 @@ final class Shortcodes /** * Init Shortcodes - * + * * @param array $shortcodes Shortcodes to init. - * - * @return void */ public function initShortcodes(array $shortcodes): void { @@ -193,9 +192,9 @@ final class Shortcodes /** * Get Cache ID for shortcode. * - * @param string $input Input. + * @param string $input Input. * @param string $string String to append to the Cache ID. - * + * * @return string Cache ID. * * @access public diff --git a/src/flextype/core/Parsers/Shortcodes/CalcShortcode.php b/src/flextype/core/Parsers/Shortcodes/CalcShortcode.php index 35f25a2b..070be7aa 100644 --- a/src/flextype/core/Parsers/Shortcodes/CalcShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/CalcShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,9 +17,10 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; + use function Flextype\expression; use function Flextype\parsers; +use function Flextype\registry; // Shortcode: calc // Usage: (calc:2+2) @@ -27,6 +28,6 @@ parsers()->shortcodes()->addHandler('calc', static function (ShortcodeInterface if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.calc.enabled')) { return ''; } - + return expression()->evaluate(parsers()->shortcodes()->parse($s->getBBCode())); }); diff --git a/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php b/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php index 410878fc..8b6c65a0 100644 --- a/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/ConstShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,11 +17,14 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; + +use function constant; +use function defined; use function Flextype\parsers; +use function Flextype\registry; // Shortcode: const -// Usage: (const:PROJECT_DIR) +// Usage: (const:PROJECT_DIR) parsers()->shortcodes()->addHandler('const', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.const.enabled')) { return ''; @@ -29,8 +32,9 @@ parsers()->shortcodes()->addHandler('const', static function (ShortcodeInterface if ($s->getBBCode() !== null) { $const = parsers()->shortcodes()->parse($s->getBBCode()); + return defined($const) ? constant($const) : ''; } return ''; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php b/src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php index af08fe1e..ba1a6862 100644 --- a/src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/EntriesShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,14 +17,15 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use Flextype\Entries\Entries; +use function array_keys; +use function Flextype\collection; +use function Flextype\collectionFromJson; use function Flextype\entries; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\collection; -use function Flextype\collectionFromJson; use function Glowy\Strings\strings; +use function parse_str; // Shortcode: entries // Usage: (entries fetch:'blog/post-1' field:'title') @@ -35,11 +36,12 @@ parsers()->shortcodes()->addHandler('entries', static function (ShortcodeInterfa $result = ''; $params = $s->getParameters(); - - if (collection(array_keys($params))->filter(fn ($v) => $v == 'fetch')->count() > 0 && - isset($params['id']) && - registry()->get('flextype.settings.parsers.shortcodes.shortcodes.entries.fetch.enabled') === true) { + if ( + collection(array_keys($params))->filter(static fn ($v) => $v === 'fetch')->count() > 0 && + isset($params['id']) && + registry()->get('flextype.settings.parsers.shortcodes.shortcodes.entries.fetch.enabled') === true + ) { $id = parsers()->shortcodes()->parse($params['id']); // Set options @@ -50,24 +52,25 @@ parsers()->shortcodes()->addHandler('entries', static function (ShortcodeInterfa } // Prepare options - $options = collection($options)->dot()->map(function($value) { - if(strings($value)->isInteger()) { + $options = collection($options)->dot()->map(static function ($value) { + if (strings($value)->isInteger()) { $value = strings($value)->toInteger(); - } elseif(strings($value)->isFloat()) { + } elseif (strings($value)->isFloat()) { $value = strings($value)->toFloat(); - } elseif(strings($value)->isBoolean()) { + } elseif (strings($value)->isBoolean()) { $value = strings($value)->toBoolean(); - } elseif(strings($value)->isNull()) { + } elseif (strings($value)->isNull()) { $value = strings($value)->toNull(); } else { $value = (string) $value; } + return $value; })->undot()->toArray(); - + // Backup current entry data $original = entries()->registry()['methods.fetch']; - + // Fetch entry $result = entries()->fetch($id, $options); @@ -78,10 +81,10 @@ parsers()->shortcodes()->addHandler('entries', static function (ShortcodeInterfa $result = $result->toJson(); // Get specific field value - if ($s->getParameter('field') != null) { - $result = collectionFromJson($result)->get(parsers()->shortcodes()->parse($s->getParameter('field')), ($s->getParameter('default') != null) ? parsers()->shortcodes()->parse($s->getParameter('default')) : ''); + if ($s->getParameter('field') !== null) { + $result = collectionFromJson($result)->get(parsers()->shortcodes()->parse($s->getParameter('field')), $s->getParameter('default') !== null ? parsers()->shortcodes()->parse($s->getParameter('default')) : ''); } } return $result; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php b/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php index 4651c868..76a563cf 100644 --- a/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/EvalShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,24 +17,25 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; + use function Flextype\expression; use function Flextype\parsers; +use function Flextype\registry; // Shortcode: eval -// Usage: (eval:2+2) +// Usage: (eval:2+2) // (eval)2+2(/eval) -// (eval)registry.get('flextype.manifest.version')(/eval) +// (eval)registry.get('flextype.manifest.version')(/eval) parsers()->shortcodes()->addHandler('eval', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.eval.enabled')) { return ''; } - if ($s->getContent() != null) { + if ($s->getContent() !== null) { return expression()->evaluate(parsers()->shortcodes()->parse($s->getContent())); } - if ($s->getBbCode() != null) { + if ($s->getBbCode() !== null) { return expression()->evaluate(parsers()->shortcodes()->parse($s->getBBCode())); } }); diff --git a/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php b/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php index a3370a97..c964b0b1 100644 --- a/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/FieldShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,9 +17,10 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; -use function Flextype\parsers; + use function Flextype\entries; +use function Flextype\parsers; +use function Flextype\registry; // Shortcode: field // Usage: (field:title) @@ -27,6 +28,6 @@ parsers()->shortcodes()->addHandler('field', static function (ShortcodeInterface if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.field.enabled')) { return ''; } - + return entries()->registry()->get('methods.fetch.result.' . parsers()->shortcodes()->parse($s->getBBCode())); }); diff --git a/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php b/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php index 1427b230..490e847c 100644 --- a/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/FilesystemShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,10 +17,12 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Glowy\Filesystem\filesystem; + +use function array_keys; +use function Flextype\collection; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\collection; +use function Glowy\Filesystem\filesystem; // Shortcode: filesystem // Usage: (filesystem get file:'1.txt) @@ -31,14 +33,15 @@ parsers()->shortcodes()->addHandler('filesystem', static function (ShortcodeInte $params = $s->getParameters(); - if (collection(array_keys($params))->filter(fn ($v) => $v == 'get')->count() > 0 && - isset($params['file']) && - registry()->get('flextype.settings.parsers.shortcodes.shortcodes.filesystem.get.enabled') === true) { - + if ( + collection(array_keys($params))->filter(static fn ($v) => $v === 'get')->count() > 0 && + isset($params['file']) && + registry()->get('flextype.settings.parsers.shortcodes.shortcodes.filesystem.get.enabled') === true + ) { $file = parsers()->shortcodes()->parse($params['file']); return filesystem()->file($file)->exists() ? filesystem()->file($file)->get() : ''; } return ''; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php b/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php index 9d82b25c..359f4075 100644 --- a/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/I18nShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,10 +18,10 @@ namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; +use function Flextype\__; +use function Flextype\collectionFromQueryString; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\collectionFromQueryString; -use function Flextype\__; // Shortcode: tr // Usage: (tr:foo values='foo=Foo' locale:'en_US') @@ -30,13 +30,13 @@ parsers()->shortcodes()->addHandler('tr', static function (ShortcodeInterface $s return ''; } - if ($s->getBbCode() != null) { + if ($s->getBbCode() !== null) { $translate = parsers()->shortcodes()->parse($s->getBbCode()); - $values = ($s->getParameter('values') != null) ? collectionFromQueryString(parsers()->shortcodes()->parse($s->getParameter('values')))->toArray() : []; - $locale = ($s->getParameter('locale') != null) ? parsers()->shortcodes()->parse($s->getParameter('locale')) : null; - + $values = $s->getParameter('values') !== null ? collectionFromQueryString(parsers()->shortcodes()->parse($s->getParameter('values')))->toArray() : []; + $locale = $s->getParameter('locale') !== null ? parsers()->shortcodes()->parse($s->getParameter('locale')) : null; + return __($translate, $values, $locale); - } + } return ''; }); diff --git a/src/flextype/core/Parsers/Shortcodes/IfShortcode.php b/src/flextype/core/Parsers/Shortcodes/IfShortcode.php index e689acdd..cb11643b 100644 --- a/src/flextype/core/Parsers/Shortcodes/IfShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/IfShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,11 +17,10 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use function Flextype\expression; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\expression; // Shortcode: if // Usage: (if:'(var:score) < (var:level1)') Show something... (/if) @@ -30,5 +29,5 @@ parsers()->shortcodes()->addHandler('if', static function (ShortcodeInterface $s return ''; } - return expression()->evaluate(parsers()->shortcodes()->parse((($s->getBbCode() != null) ? $s->getBbCode() : ''))) === true ? parsers()->shortcodes()->parse($s->getContent()) : ''; -}); \ No newline at end of file + return expression()->evaluate(parsers()->shortcodes()->parse(($s->getBbCode() ?? ''))) === true ? parsers()->shortcodes()->parse($s->getContent()) : ''; +}); diff --git a/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php b/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php index 81df42bd..33b55bc8 100644 --- a/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/MarkdownShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,6 +17,7 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; + use function Flextype\parsers; use function Flextype\registry; @@ -27,10 +28,10 @@ parsers()->shortcodes()->addHandler('markdown', static function (ShortcodeInterf if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.markdown.enabled')) { return ''; } - - if ($s->getContent() != null) { + + if ($s->getContent() !== null) { return parsers()->markdown()->parse(parsers()->shortcodes()->parse($s->getContent())); } return '@markdown'; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php b/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php index c876d48a..17b072b9 100644 --- a/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,8 +17,11 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; + use function Flextype\parsers; +use function Flextype\registry; +use function ob_get_clean; +use function ob_start; // Shortcode: php // Usage: (php) php code here (/php) @@ -28,11 +31,12 @@ parsers()->shortcodes()->addHandler('php', static function (ShortcodeInterface $ return ''; } - if ($s->getContent() != null) { + if ($s->getContent() !== null) { ob_start(); eval($s->getContent()); + return ob_get_clean(); } return '@php'; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/RawShortcode.php b/src/flextype/core/Parsers/Shortcodes/RawShortcode.php index 480cd9b6..1d151ecc 100644 --- a/src/flextype/core/Parsers/Shortcodes/RawShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/RawShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. diff --git a/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php index 25241170..a99353cb 100644 --- a/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/RegistryShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,10 +18,12 @@ namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; +use function array_keys; +use function Flextype\collection; use function Flextype\parsers; use function Flextype\registry; use function Flextype\serializers; -use function Flextype\collection; +use function is_array; // Shortcode: registry // Usage: (registry get id:'flextype.manifest.version') @@ -29,16 +31,17 @@ parsers()->shortcodes()->addHandler('registry', static function (ShortcodeInterf if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.registry.enabled')) { return ''; } - + $result = ''; $params = $s->getParameters(); - if (collection(array_keys($params))->filter(fn ($v) => $v == 'get')->count() > 0 && - isset($params['id']) && - registry()->get('flextype.settings.parsers.shortcodes.shortcodes.registry.get.enabled') === true) { - + if ( + collection(array_keys($params))->filter(static fn ($v) => $v === 'get')->count() > 0 && + isset($params['id']) && + registry()->get('flextype.settings.parsers.shortcodes.shortcodes.registry.get.enabled') === true + ) { $id = parsers()->shortcodes()->parse($params['id']); - $default = (isset($params['default'])) ? parsers()->shortcodes()->parse($params['default']) : null; + $default = isset($params['default']) ? parsers()->shortcodes()->parse($params['default']) : null; $result = registry()->get($id, $default); return is_array($result) ? serializers()->json()->encode($result) : $result; diff --git a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php index d2f72984..2efdac89 100644 --- a/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/StringsShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,10 +17,18 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; + +use function array_keys; +use function array_map; +use function count; +use function explode; use function Flextype\parsers; -use function Flextype\serializers; use function Flextype\registry; +use function Flextype\serializers; use function Glowy\Strings\strings; +use function is_iterable; +use function is_string; +use function parse_str; // Shortcode: strings // Usage: (strings) strings to modify (/strings) @@ -28,18 +36,17 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.strings.enabled')) { return ''; } - - $content = ($s->getContent() != null) ? parsers()->shortcodes()->parse($s->getContent()) : ''; - $varsDelimeter = ($s->getParameter('varsDelimeter') != null) ? parsers()->shortcodes()->parse($s->getParameter('varsDelimeter')) : ','; - foreach($s->getParameters() as $key => $value) { + $content = $s->getContent() !== null ? parsers()->shortcodes()->parse($s->getContent()) : ''; + $varsDelimeter = $s->getParameter('varsDelimeter') !== null ? parsers()->shortcodes()->parse($s->getParameter('varsDelimeter')) : ','; + foreach ($s->getParameters() as $key => $value) { $vars = $value !== null ? strings($value)->contains($varsDelimeter) ? explode($varsDelimeter, $value) : [$value] : []; // Parse shortcodes for each var. - $vars = array_map(fn($v) => parsers()->shortcodes()->parse(is_string($v) ? $v : ''), $vars); + $vars = array_map(static fn ($v) => parsers()->shortcodes()->parse(is_string($v) ? $v : ''), $vars); - if ($key == 'append') { + if ($key === 'append') { if (is_iterable($vars)) { $content = strings($content)->{'append'}(...$vars)->toString(); } else { @@ -47,7 +54,7 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa } } - if ($key == 'prepend') { + if ($key === 'prepend') { if (is_iterable($vars)) { $content = strings($content)->{'prepend'}(...$vars)->toString(); } else { @@ -55,297 +62,300 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa } } - if ($key == 'after') { + if ($key === 'after') { $content = strings($content)->{'after'}($vars[0])->toString(); } - if ($key == 'afterLast') { + if ($key === 'afterLast') { $content = strings($content)->{'afterLast'}($vars[0])->toString(); } - if ($key == 'before') { + if ($key === 'before') { $content = strings($content)->{'before'}($vars[0])->toString(); } - - if ($key == 'beforeLast') { + + if ($key === 'beforeLast') { $content = strings($content)->{'beforeLast'}($vars[0])->toString(); } - if ($key == 'lower') { + if ($key === 'lower') { $content = strings($content)->{'lower'}()->toString(); } - if ($key == 'upper') { + if ($key === 'upper') { $content = strings($content)->{'upper'}()->toString(); } - if ($key == 'sort') { + if ($key === 'sort') { $content = strings($content)->{'wordsSort' . strings($vars[0])->ucfirst()}()->toString(); } - if ($key == 'wordsLimit') { + if ($key === 'wordsLimit') { $content = strings($content)->{'wordsLimit'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 100, isset($vars[1]) ? (string) $vars[1] : '...')->toString(); } - if ($key == 'at') { + if ($key === 'at') { $content = strings($content)->{'at'}(strings($vars[0])->toInteger())->toString(); } - - if ($key == 'base64Decode') { + + if ($key === 'base64Decode') { $content = strings($content)->{'base64Decode'}()->toString(); } - if ($key == 'base64Encode') { + if ($key === 'base64Encode') { $content = strings($content)->{'base64Encode'}()->toString(); } - if ($key == 'between') { + if ($key === 'between') { $content = strings($content)->{'between'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (string) $vars[1] : '')->toString(); } - if ($key == 'camel') { + if ($key === 'camel') { $content = strings($content)->{'camel'}()->toString(); } - if ($key == 'capitalize') { + if ($key === 'capitalize') { $content = strings($content)->{'capitalize'}()->toString(); } - if ($key == 'chars') { + if ($key === 'chars') { $content = serializers()->json()->encode(strings($content)->{'chars'}()); } - if ($key == 'charsFrequency') { + if ($key === 'charsFrequency') { $content = serializers()->json()->encode(strings($content)->{'charsFrequency'}()); } - if ($key == 'contains') { + if ($key === 'contains') { if (isset($vars[0])) { parse_str($vars[0], $values); } else { $values = []; } - $content = strings($content)->{'contains'}(array_keys($values), (isset($vars[1]) ? strings($vars[1])->toBoolean() : true)) ? "true" : "false"; + + $content = strings($content)->{'contains'}(array_keys($values), (isset($vars[1]) ? strings($vars[1])->toBoolean() : true)) ? 'true' : 'false'; } - if ($key == 'containsAll') { + if ($key === 'containsAll') { if (isset($vars[0])) { parse_str($vars[0], $values); } else { $values = []; } - $content = strings($content)->{'containsAll'}(array_keys($values), (isset($vars[1]) ? strings($vars[1])->toBoolean() : true)) ? "true" : "false"; + + $content = strings($content)->{'containsAll'}(array_keys($values), (isset($vars[1]) ? strings($vars[1])->toBoolean() : true)) ? 'true' : 'false'; } - if ($key == 'containsAny') { + if ($key === 'containsAny') { if (isset($vars[0])) { parse_str($vars[0], $values); } else { $values = []; } - $content = strings($content)->{'containsAny'}(array_keys($values), isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? "true" : "false"; + + $content = strings($content)->{'containsAny'}(array_keys($values), isset($vars[1]) ? strings($vars[1])->toBoolean() : true) ? 'true' : 'false'; } - if ($key == 'count') { + if ($key === 'count') { $content = (string) strings($content)->{'count'}(); } - if ($key == 'crc32') { + if ($key === 'crc32') { $content = (string) strings($content)->{'crc32'}(); } - if ($key == 'countSubString') { + if ($key === 'countSubString') { $content = (string) strings($content)->{'countSubString'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : true); } - if ($key == 'endsWith') { - $content = strings($content)->{'endsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? "true" : "false"; + if ($key === 'endsWith') { + $content = strings($content)->{'endsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? 'true' : 'false'; } - if ($key == 'finish') { + if ($key === 'finish') { $content = strings($content)->{'finish'}(isset($vars[0]) ? (string) $vars[0] : '')->toString(); } - if ($key == 'firstSegment') { + if ($key === 'firstSegment') { $content = strings($content)->{'firstSegment'}(isset($vars[0]) ? (string) $vars[0] : ' ')->toString(); } - if ($key == 'format') { + if ($key === 'format') { $formatVars = $vars; if (count($formatVars) > 0) { $content = strings($content)->{'format'}(...$formatVars)->toString(); } } - - if ($key == 'getEncoding') { + + if ($key === 'getEncoding') { $content = strings($content)->{'getEncoding'}(); } - if ($key == 'setEncoding') { + if ($key === 'setEncoding') { $content = strings($content)->{'setEncoding'}(isset($vars[0]) ? (string) $vars[0] : ''); } - if ($key == 'hash') { + if ($key === 'hash') { $content = strings($content)->{'hash'}(isset($vars[0]) ? (string) $vars[0] : 'md5', isset($vars[1]) ? strings($vars[1])->toBoolean() : false)->toString(); } - if ($key == 'increment') { + if ($key === 'increment') { $content = strings($content)->{'increment'}(isset($vars[1]) ? (string) $vars[1] : '_', isset($vars[0]) ? (int) $vars[0] : 1)->toString(); } - if ($key == 'indexOf') { + if ($key === 'indexOf') { $content = strings($content)->{'indexOf'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (int) $vars[1] : 0, isset($vars[2]) ? strings($vars[2])->toBoolean() : true); } - if ($key == 'indexOfLast') { + if ($key === 'indexOfLast') { $content = strings($content)->{'indexOfLast'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (int) $vars[1] : 0, isset($vars[2]) ? strings($vars[2])->toBoolean() : true); } - if ($key == 'insert') { + if ($key === 'insert') { $content = strings($content)->{'insert'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (int) $vars[1] : 0); } - if ($key == 'isAlpha') { - $content = strings($content)->{'isAlpha'}() ? "true" : "false"; + if ($key === 'isAlpha') { + $content = strings($content)->{'isAlpha'}() ? 'true' : 'false'; } - if ($key == 'isAlphanumeric') { - $content = strings($content)->{'isAlphanumeric'}() ? "true" : "false"; + if ($key === 'isAlphanumeric') { + $content = strings($content)->{'isAlphanumeric'}() ? 'true' : 'false'; } - if ($key == 'isAscii') { - $content = strings($content)->{'isAscii'}() ? "true" : "false"; + if ($key === 'isAscii') { + $content = strings($content)->{'isAscii'}() ? 'true' : 'false'; } - if ($key == 'isBase64') { - $content = strings($content)->{'isBase64'}() ? "true" : "false"; + if ($key === 'isBase64') { + $content = strings($content)->{'isBase64'}() ? 'true' : 'false'; } - if ($key == 'isBlank') { - $content = strings($content)->{'isBlank'}() ? "true" : "false"; + if ($key === 'isBlank') { + $content = strings($content)->{'isBlank'}() ? 'true' : 'false'; } - if ($key == 'isBoolean') { - $content = strings($content)->{'isBoolean'}() ? "true" : "false"; + if ($key === 'isBoolean') { + $content = strings($content)->{'isBoolean'}() ? 'true' : 'false'; } - if ($key == 'isDigit') { - $content = strings($content)->{'isDigit'}() ? "true" : "false"; + if ($key === 'isDigit') { + $content = strings($content)->{'isDigit'}() ? 'true' : 'false'; } - if ($key == 'isEmail') { - $content = strings($content)->{'isEmail'}() ? "true" : "false"; + if ($key === 'isEmail') { + $content = strings($content)->{'isEmail'}() ? 'true' : 'false'; } - if ($key == 'isEmpty') { - $content = strings($content)->{'isEmpty'}() ? "true" : "false"; - } - - if ($key == 'isEqual') { - $content = strings($content)->{'isEqual'}(isset($vars[0]) ? (string) $vars[0] : '') ? "true" : "false"; + if ($key === 'isEmpty') { + $content = strings($content)->{'isEmpty'}() ? 'true' : 'false'; } - if ($key == 'isFalse') { - $content = strings($content)->{'isFalse'}() ? "true" : "false"; + if ($key === 'isEqual') { + $content = strings($content)->{'isEqual'}(isset($vars[0]) ? (string) $vars[0] : '') ? 'true' : 'false'; } - if ($key == 'isTrue') { - $content = strings($content)->{'isTrue'}() ? "true" : "false"; + if ($key === 'isFalse') { + $content = strings($content)->{'isFalse'}() ? 'true' : 'false'; } - if ($key == 'isHexadecimal') { - $content = strings($content)->{'isHexadecimal'}() ? "true" : "false"; + if ($key === 'isTrue') { + $content = strings($content)->{'isTrue'}() ? 'true' : 'false'; } - if ($key == 'isHTML') { - $content = strings($content)->{'isHTML'}() ? "true" : "false"; + if ($key === 'isHexadecimal') { + $content = strings($content)->{'isHexadecimal'}() ? 'true' : 'false'; } - if ($key == 'isIP') { - $content = strings($content)->{'isIP'}() ? "true" : "false"; + if ($key === 'isHTML') { + $content = strings($content)->{'isHTML'}() ? 'true' : 'false'; } - if ($key == 'isJson') { - $content = strings($content)->{'isJson'}() ? "true" : "false"; + if ($key === 'isIP') { + $content = strings($content)->{'isIP'}() ? 'true' : 'false'; } - if ($key == 'isUpper') { - $content = strings($content)->{'isUpper'}() ? "true" : "false"; + if ($key === 'isJson') { + $content = strings($content)->{'isJson'}() ? 'true' : 'false'; } - if ($key == 'isLower') { - $content = strings($content)->{'isLower'}() ? "true" : "false"; + if ($key === 'isUpper') { + $content = strings($content)->{'isUpper'}() ? 'true' : 'false'; } - if ($key == 'isMAC') { - $content = strings($content)->{'isMAC'}() ? "true" : "false"; + if ($key === 'isLower') { + $content = strings($content)->{'isLower'}() ? 'true' : 'false'; } - if ($key == 'isNumeric') { - $content = strings($content)->{'isNumeric'}() ? "true" : "false"; + if ($key === 'isMAC') { + $content = strings($content)->{'isMAC'}() ? 'true' : 'false'; } - if ($key == 'isPrintable') { - $content = strings($content)->{'isPrintable'}() ? "true" : "false"; + if ($key === 'isNumeric') { + $content = strings($content)->{'isNumeric'}() ? 'true' : 'false'; } - if ($key == 'isPunctuation') { - $content = strings($content)->{'isPunctuation'}() ? "true" : "false"; + if ($key === 'isPrintable') { + $content = strings($content)->{'isPrintable'}() ? 'true' : 'false'; } - if ($key == 'isUrl') { - $content = strings($content)->{'isUrl'}() ? "true" : "false"; + if ($key === 'isPunctuation') { + $content = strings($content)->{'isPunctuation'}() ? 'true' : 'false'; } - if ($key == 'isSimilar') { - $content = strings($content)->{'isSimilar'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (float) $vars[1] : 80.0) ? "true" : "false"; + if ($key === 'isUrl') { + $content = strings($content)->{'isUrl'}() ? 'true' : 'false'; } - if ($key == 'isSerialized') { - $content = strings($content)->{'isSerialized'}() ? "true" : "false"; + if ($key === 'isSimilar') { + $content = strings($content)->{'isSimilar'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (float) $vars[1] : 80.0) ? 'true' : 'false'; } - if ($key == 'kebab') { + if ($key === 'isSerialized') { + $content = strings($content)->{'isSerialized'}() ? 'true' : 'false'; + } + + if ($key === 'kebab') { $content = strings($content)->{'kebab'}()->toString(); } - if ($key == 'lastSegment') { + if ($key === 'lastSegment') { $content = strings($content)->{'lastSegment'}(isset($vars[0]) ? (string) $vars[0] : ' ')->toString(); } - if ($key == 'length') { + if ($key === 'length') { $content = strings($content)->{'length'}(); } - if ($key == 'limit') { + if ($key === 'limit') { $content = strings($content)->{'limit'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 100, isset($vars[1]) ? (string) $vars[1] : '...')->toString(); } - if ($key == 'lines') { + if ($key === 'lines') { $content = serializers()->json()->encode(strings($content)->{'lines'}()); } - if ($key == 'md5') { + if ($key === 'md5') { $content = strings($content)->{'md5'}(isset($vars[0]) ? strings($vars[0])->toBoolean() : false)->toString(); } - if ($key == 'move') { + if ($key === 'move') { $content = strings($content)->{'move'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 0, isset($vars[1]) ? strings($vars[1])->toInteger() : 0, isset($vars[2]) ? strings($vars[2])->toInteger() : 0)->toString(); } - if ($key == 'normalizeNewLines') { + if ($key === 'normalizeNewLines') { $content = strings($content)->{'normalizeNewLines'}()->toString(); } - if ($key == 'normalizeSpaces') { + if ($key === 'normalizeSpaces') { $content = strings($content)->{'normalizeSpaces'}()->toString(); } - if ($key == 'offsetExists') { - $content = strings($content)->{'offsetExists'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 0) ? "true" : "false"; + if ($key === 'offsetExists') { + $content = strings($content)->{'offsetExists'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 0) ? 'true' : 'false'; } - if ($key == 'offsetGet') { + if ($key === 'offsetGet') { $content = strings($content)->{'offsetGet'}(isset($vars[0]) ? strings($vars[0])->toString() : 0); } @@ -361,138 +371,140 @@ parsers()->shortcodes()->addHandler('strings', static function (ShortcodeInterfa $content = strings($content)->{'padRight'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 0, isset($vars[1]) ? (string) $vars[1] : ' ')->toString(); } - if ($key == 'quotesToEntities') { + if ($key === 'quotesToEntities') { $content = strings($content)->{'quotesToEntities'}()->toString(); } - if ($key == 'random') { + if ($key === 'random') { $content = strings($content)->{'random'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 64, isset($vars[1]) ? (string) $vars[1] : '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')->toString(); } - if ($key == 'reduceSlashes') { + if ($key === 'reduceSlashes') { $content = strings($content)->{'reduceSlashes'}()->toString(); } - if ($key == 'repeat') { + if ($key === 'repeat') { $content = strings($content)->{'repeat'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 1)->toString(); } - if ($key == 'replace') { + if ($key === 'replace') { $content = strings($content)->{'replace'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (string) $vars[1] : '')->toString(); } - if ($key == 'replaceDashes') { + if ($key === 'replaceDashes') { $content = strings($content)->{'replaceDashes'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : false)->toString(); } - if ($key == 'replaceFirst') { + if ($key === 'replaceFirst') { $content = strings($content)->{'replaceFirst'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (string) $vars[1] : '')->toString(); } - if ($key == 'replaceLast') { + if ($key === 'replaceLast') { $content = strings($content)->{'replaceLast'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? (string) $vars[1] : '')->toString(); } - if ($key == 'replaceNonAlpha') { + if ($key === 'replaceNonAlpha') { $content = strings($content)->{'replaceNonAlpha'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : false)->toString(); } - if ($key == 'replaceNonAlphanumeric') { + if ($key === 'replaceNonAlphanumeric') { $content = strings($content)->{'replaceNonAlphanumeric'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : false)->toString(); } - if ($key == 'replacePunctuations') { + if ($key === 'replacePunctuations') { $content = strings($content)->{'replacePunctuations'}(isset($vars[0]) ? (string) $vars[0] : '', isset($vars[1]) ? strings($vars[1])->toBoolean() : false)->toString(); } - if ($key == 'reverse') { + if ($key === 'reverse') { $content = strings($content)->{'reverse'}()->toString(); } - if ($key == 'segment') { + if ($key === 'segment') { $content = strings($content)->{'segment'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 1, isset($vars[1]) ? (string) $vars[1] : ' ')->toString(); } - if ($key == 'segments') { + if ($key === 'segments') { $content = serializers()->json()->encode(strings($content)->{'segments'}(isset($vars[0]) ? (string) $vars[0] : ' ')); } - - if ($key == 'sha1') { + + if ($key === 'sha1') { $content = strings($content)->{'sha1'}(isset($vars[0]) ? strings($vars[0])->toBoolean() : false)->toString(); } - if ($key == 'sha256') { + if ($key === 'sha256') { $content = strings($content)->{'sha256'}(isset($vars[0]) ? strings($vars[0])->toBoolean() : false)->toString(); } - if ($key == 'shuffle') { + if ($key === 'shuffle') { $content = strings($content)->{'shuffle'}()->toString(); } - if ($key == 'similarity') { + if ($key === 'similarity') { $content = (string) strings($content)->{'similarity'}(isset($vars[0]) ? (string) $vars[0] : ''); } - if ($key == 'snake') { + if ($key === 'snake') { $content = strings($content)->{'snake'}(isset($vars[0]) ? (string) $vars[0] : '_')->toString(); } - if ($key == 'start') { + if ($key === 'start') { $content = strings($content)->{'start'}(isset($vars[0]) ? (string) $vars[0] : '')->toString(); } - if ($key == 'startsWith') { - $content = strings($content)->{'startsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? "true" : "false"; + if ($key === 'startsWith') { + $content = strings($content)->{'startsWith'}(isset($vars[0]) ? (string) $vars[0] : '') ? 'true' : 'false'; } - if ($key == 'stripQuotes') { + if ($key === 'stripQuotes') { $content = strings($content)->{'stripQuotes'}()->toString(); } - if ($key == 'stripSpaces') { + if ($key === 'stripSpaces') { $content = strings($content)->{'stripSpaces'}()->toString(); } - if ($key == 'studly') { + if ($key === 'studly') { $content = strings($content)->{'studly'}()->toString(); } - if ($key == 'substr') { + if ($key === 'substr') { $content = strings($content)->{'substr'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 0, isset($vars[1]) ? (string) $vars[1] : null)->toString(); } - if ($key == 'trim') { + if ($key === 'trim') { $content = strings($content)->{'trim'}()->toString(); } - if ($key == 'trimLeft') { + if ($key === 'trimLeft') { $content = strings($content)->{'trimLeft'}()->toString(); } - if ($key == 'trimRight') { + if ($key === 'trimRight') { $content = strings($content)->{'trimRight'}()->toString(); } - if ($key == 'trimSlashes') { + if ($key === 'trimSlashes') { $content = strings($content)->{'trimSlashes'}()->toString(); } - if ($key == 'ucfirst') { + if ($key === 'ucfirst') { $content = strings($content)->{'ucfirst'}()->toString(); } - if ($key == 'wordsCount') { + if ($key === 'wordsCount') { $content = (string) strings($content)->{'wordsCount'}(isset($vars[0]) ? (string) $vars[0] : '?!;:,.'); } - if ($key == 'words') { + if ($key === 'words') { $content = serializers()->json()->encode(strings($content)->{'words'}(isset($vars[0]) ? (string) $vars[0] : '?!;:,.')); } - if ($key == 'wordsFrequency') { - $content = serializers()->json()->encode(strings($content)->{'wordsFrequency'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 2, isset($vars[1]) ? (string) $vars[1] : '.', isset($vars[2]) ? (string) $vars[2] : ',')); + if ($key !== 'wordsFrequency') { + continue; } - } - + + $content = serializers()->json()->encode(strings($content)->{'wordsFrequency'}(isset($vars[0]) ? strings($vars[0])->toInteger() : 2, isset($vars[1]) ? (string) $vars[1] : '.', isset($vars[2]) ? (string) $vars[2] : ',')); + } + return (string) $content; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php b/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php index 6feb7a95..68dc1aec 100644 --- a/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/TextileShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,6 +17,7 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; + use function Flextype\parsers; use function Flextype\registry; @@ -27,10 +28,10 @@ parsers()->shortcodes()->addHandler('textile', static function (ShortcodeInterfa if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.textile.enabled')) { return ''; } - - if ($s->getContent() != null) { + + if ($s->getContent() !== null) { return parsers()->textile()->parse(parsers()->shortcodes()->parse($s->getContent())); } return '@textile'; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php b/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php index 70922418..119c6d23 100644 --- a/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/TypeShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,8 +17,9 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; + use function Flextype\parsers; +use function Flextype\registry; // Shortcode: type // Usage: (type:string) @@ -26,8 +27,8 @@ parsers()->shortcodes()->addHandler('type', static function (ShortcodeInterface if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.type.enabled')) { return ''; } - - if ($s->getBbCode() != null) { + + if ($s->getBbCode() !== null) { return '@type[' . $s->getBBCode() . ']'; } diff --git a/src/flextype/core/Parsers/Shortcodes/UnlessShortcode.php b/src/flextype/core/Parsers/Shortcodes/UnlessShortcode.php index be2b2809..20907256 100644 --- a/src/flextype/core/Parsers/Shortcodes/UnlessShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/UnlessShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,11 +17,10 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use function Flextype\expression; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\expression; // Shortcode: unless // Usage: (unless:'(var:score) < (var:level1)') Show something... (/when) @@ -30,5 +29,5 @@ parsers()->shortcodes()->addHandler('unless', static function (ShortcodeInterfac return ''; } - return expression()->evaluate(parsers()->shortcodes()->parse((($s->getBbCode() != null) ? $s->getBbCode() : ''))) === false ? parsers()->shortcodes()->parse($s->getContent()) : ''; -}); \ No newline at end of file + return expression()->evaluate(parsers()->shortcodes()->parse(($s->getBbCode() ?? ''))) === false ? parsers()->shortcodes()->parse($s->getContent()) : ''; +}); diff --git a/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php index aec61b57..6252b440 100644 --- a/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/UrlShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,18 +17,17 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\app; -use function Flextype\parsers; -use function Flextype\serializers; -use function Flextype\registry; -use function Flextype\getBaseUrl; -use function Flextype\getBasePath; + use function Flextype\getAbsoluteUrl; +use function Flextype\getBasePath; +use function Flextype\getBaseUrl; use function Flextype\getProjectUrl; use function Flextype\getUriString; +use function Flextype\parsers; +use function Flextype\registry; +use function Flextype\serializers; use function Flextype\urlFor; - // Shortcode: getBaseUrl // Usage: (getBaseUrl) parsers()->shortcodes()->addHandler('getBaseUrl', static function () { @@ -55,7 +54,7 @@ parsers()->shortcodes()->addHandler('getAbsoluteUrl', static function () { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { return ''; } - + return getAbsoluteUrl(); }); @@ -65,7 +64,7 @@ parsers()->shortcodes()->addHandler('getProjectUrl', static function () { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { return ''; } - + return getProjectUrl(); }); @@ -75,7 +74,7 @@ parsers()->shortcodes()->addHandler('getUriString', static function () { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.url.enabled')) { return ''; } - + return getUriString(); }); @@ -86,7 +85,9 @@ parsers()->shortcodes()->addHandler('urlFor', static function (ShortcodeInterfac return ''; } - return urlFor($s->getParameter('routeName'), - $s->getParameter('data') != null ? serializers()->json()->decode(parsers()->shortcodes()->parse($s->getParameter('data'))) : [], - $s->getParameter('queryParams') != null ? serializers()->json()->decode(parsers()->shortcodes()->parse($s->getParameter('queryParams'))) : [],); -}); \ No newline at end of file + return urlFor( + $s->getParameter('routeName'), + $s->getParameter('data') !== null ? serializers()->json()->decode(parsers()->shortcodes()->parse($s->getParameter('data'))) : [], + $s->getParameter('queryParams') !== null ? serializers()->json()->decode(parsers()->shortcodes()->parse($s->getParameter('queryParams'))) : [], + ); +}); diff --git a/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php b/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php index 142b804d..a4f19427 100644 --- a/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/UuidShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,8 +16,9 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; -use Thunder\Shortcode\Shortcode\ShortcodeInterface; use Ramsey\Uuid\Uuid; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; + use function Flextype\parsers; use function Flextype\registry; use function Glowy\Strings\strings; @@ -30,8 +31,8 @@ parsers()->shortcodes()->addHandler('uuid', static function (ShortcodeInterface } $result = ''; - $uuid = ($s->getBbCode() != null) ? strings(parsers()->shortcodes()->parse($s->getBbCode()))->toInteger() : 4; - + $uuid = $s->getBbCode() !== null ? strings(parsers()->shortcodes()->parse($s->getBbCode()))->toInteger() : 4; + switch ($uuid) { case 4: default: @@ -40,4 +41,4 @@ parsers()->shortcodes()->addHandler('uuid', static function (ShortcodeInterface } return $result; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/VarShortcode.php b/src/flextype/core/Parsers/Shortcodes/VarShortcode.php index 90edb5a3..435e45b1 100644 --- a/src/flextype/core/Parsers/Shortcodes/VarShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/VarShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,39 +17,42 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use function Flextype\registry; -use function Flextype\parsers; + use function Flextype\entries; +use function Flextype\parsers; +use function Flextype\registry; // Shortcode: var -// Usage: (var:foo) +// Usage: (var:foo) // (var get:foo) -// (var set:foo value:Foo) +// (var set:foo value:Foo) // (var set:foo) Foo (/var) parsers()->shortcodes()->addHandler('var', static function (ShortcodeInterface $s) { if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.var.enabled')) { return ''; } - $params = ($s->getParameters() != null) ? $s->getParameters() : ''; - + $params = $s->getParameters() ?? ''; + if (isset($params['set'])) { if (isset($params['value'])) { $value = $params['value']; } else { - $value = ($s->getContent() != null) ? $s->getContent() : ''; + $value = $s->getContent() ?? ''; } + entries()->registry()->set('methods.fetch.result.vars.' . parsers()->shortcodes()->parse($params['set']), parsers()->shortcodes()->parse($value)); + return ''; - } + } if (isset($params['get'])) { return entries()->registry()->get('methods.fetch.result.vars.' . parsers()->shortcodes()->parse($params['get'])); - } + } if ($s->getBBCode() !== null) { return entries()->registry()->get('methods.fetch.result.vars.' . parsers()->shortcodes()->parse($s->getBBCode())); } return ''; -}); \ No newline at end of file +}); diff --git a/src/flextype/core/Parsers/Shortcodes/WhenShortcode.php b/src/flextype/core/Parsers/Shortcodes/WhenShortcode.php index 5267674f..1abcb687 100644 --- a/src/flextype/core/Parsers/Shortcodes/WhenShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/WhenShortcode.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,11 +17,10 @@ declare(strict_types=1); namespace Flextype\Parsers\Shortcodes; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use function Flextype\expression; use function Flextype\parsers; use function Flextype\registry; -use function Flextype\expression; // Shortcode: when // Usage: (when:'(var:score) < (var:level1)') Show something... (/when) @@ -30,5 +29,5 @@ parsers()->shortcodes()->addHandler('when', static function (ShortcodeInterface return ''; } - return expression()->evaluate(parsers()->shortcodes()->parse((($s->getBbCode() != null) ? $s->getBbCode() : ''))) === true ? parsers()->shortcodes()->parse($s->getContent()) : ''; -}); \ No newline at end of file + return expression()->evaluate(parsers()->shortcodes()->parse(($s->getBbCode() ?? ''))) === true ? parsers()->shortcodes()->parse($s->getContent()) : ''; +}); diff --git a/src/flextype/core/Parsers/Textile.php b/src/flextype/core/Parsers/Textile.php index 0fd8312f..f5bf363a 100644 --- a/src/flextype/core/Parsers/Textile.php +++ b/src/flextype/core/Parsers/Textile.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -19,9 +19,11 @@ namespace Flextype\Parsers; use Exception; use Netcarver\Textile\Parser; +use function count; use function Flextype\cache; use function Flextype\registry; use function Glowy\Strings\strings; +use function is_array; final class Textile { @@ -59,15 +61,20 @@ final class Textile $parser = new Parser(); foreach (registry()->get('flextype.settings.parsers.textile') as $key => $value) { - if ($key == 'cache') continue; - if ($key == 'symbol') { + if ($key === 'cache') { + continue; + } + + if ($key === 'symbol') { if (count($value) > 0 && is_array($value)) { foreach ($value as $name => $val) { $parser->setSymbol($name, $val); } } + continue; } + $parser->{'set' . strings($key)->camel()->ucfirst()}($value); } @@ -101,7 +108,7 @@ final class Textile * * @return mixed The TEXTILE converted to a PHP value */ - public function parse(string $input) + public function parse(string $input): mixed { $cache = registry()->get('flextype.settings.parsers.textile.cache.enabled'); diff --git a/src/flextype/core/Plugins.php b/src/flextype/core/Plugins.php index c53e3f2f..ab7e34c6 100755 --- a/src/flextype/core/Plugins.php +++ b/src/flextype/core/Plugins.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,14 +16,12 @@ declare(strict_types=1); namespace Flextype; -use Glowy\Macroable\Macroable; use Composer\Semver\Semver; -use Flextype\I18n; +use Glowy\Macroable\Macroable; use RuntimeException; use function array_diff_key; use function array_replace_recursive; -use function Glowy\Arrays\arrays; use function count; use function filemtime; use function Glowy\Filesystem\filesystem; @@ -80,7 +78,7 @@ class Plugins // Get plugins list $pluginsList = $this->getPluginsList(); - + // Get plugins Cache ID $pluginsCacheID = $this->getPluginsCacheID($pluginsList); @@ -109,7 +107,6 @@ class Plugins // Go through... foreach ($pluginsList as $plugin) { - // Set plugin settings directory $projectPluginSettingsDir = FLEXTYPE_PATH_PROJECT . '/config/plugins/' . $plugin['dirname']; @@ -129,8 +126,8 @@ class Plugins } // Get default plugin settings content - $defaultPluginSettingsFileContent = filesystem()->file($defaultPluginSettingsFile)->get(); - $defaultPluginSettings = empty($defaultPluginSettingsFileContent) ? [] : serializers()->yaml()->decode($defaultPluginSettingsFileContent); + $defaultPluginSettingsFileContent = filesystem()->file($defaultPluginSettingsFile)->get(); + $defaultPluginSettings = empty($defaultPluginSettingsFileContent) ? [] : serializers()->yaml()->decode($defaultPluginSettingsFileContent); // Create project plugin settings file ! filesystem()->file($projectPluginSettingsFile)->exists() and filesystem()->file($projectPluginSettingsFile)->put($defaultPluginSettingsFileContent); @@ -150,8 +147,8 @@ class Plugins } // Get default plugin manifest content - $defaultPluginManifestFileContent = filesystem()->file($defaultPluginManifestFile)->get(); - $defaultPluginManifest = empty($defaultPluginManifestFileContent) ? [] : serializers()->yaml()->decode($defaultPluginManifestFileContent); + $defaultPluginManifestFileContent = filesystem()->file($defaultPluginManifestFile)->get(); + $defaultPluginManifest = empty($defaultPluginManifestFileContent) ? [] : serializers()->yaml()->decode($defaultPluginManifestFileContent); // Merge plugin settings and manifest data $plugins[$plugin['dirname']]['manifest'] = $defaultPluginManifest; @@ -218,7 +215,7 @@ class Plugins } else { $translates = serializers()->yaml()->decode($content); } - + I18n::add($translates, $locale); } else { I18n::add([], registry()->get('flextype.settings.locale')); @@ -268,7 +265,6 @@ class Plugins */ public function getValidPluginsDependencies(array $plugins): array { - // Set verified plugins array $verifiedPlugins = []; @@ -372,12 +368,16 @@ class Plugins if (filesystem()->directory(FLEXTYPE_PATH_PROJECT . '/plugins/')->exists()) { foreach (filesystem()->find()->in(FLEXTYPE_PATH_PROJECT . '/plugins/')->directories()->depth(0) as $plugin) { $pluginName = $plugin->getBasename(); - if (filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/plugin.php')->exists() && - filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/plugin.yaml')->exists() && - filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/settings.yaml')->exists()) { - $pluginsList[$pluginName]['dirname'] = $plugin->getBasename(); - $pluginsList[$pluginName]['pathname'] = $plugin->getPathname(); + if ( + ! filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/plugin.php')->exists() || + ! filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/plugin.yaml')->exists() || + ! filesystem()->file(FLEXTYPE_PATH_PROJECT . '/plugins/' . $pluginName . '/settings.yaml')->exists() + ) { + continue; } + + $pluginsList[$pluginName]['dirname'] = $plugin->getBasename(); + $pluginsList[$pluginName]['pathname'] = $plugin->getPathname(); } } @@ -394,7 +394,7 @@ class Plugins $enabledPlugins = []; foreach ($plugins as $name => $plugin) { - if (! collection($plugin)->has('settings.enabled') || collection($plugin)->get('settings.enabled') == false) { + if (! collection($plugin)->has('settings.enabled') || collection($plugin)->get('settings.enabled') === false) { continue; } @@ -402,7 +402,7 @@ class Plugins } return $enabledPlugins; - } + } /** * Include enabled plugins diff --git a/src/flextype/core/Serializers/Frontmatter.php b/src/flextype/core/Serializers/Frontmatter.php index 2e8eebc7..182ae250 100644 --- a/src/flextype/core/Serializers/Frontmatter.php +++ b/src/flextype/core/Serializers/Frontmatter.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,19 +16,18 @@ declare(strict_types=1); namespace Flextype\Serializers; -use function array_slice; -use function Glowy\Arrays\arrays; +use function array_filter; +use function array_values; use function Flextype\cache; -use function count; -use function implode; +use function Flextype\collection; +use function Flextype\registry; +use function Flextype\serializers; +use function Glowy\Strings\strings; use function in_array; +use function is_array; use function ltrim; use function preg_replace; use function preg_split; -use function Flextype\registry; -use function Flextype\serializers; -use function Flextype\collection; -use function Glowy\Strings\strings; use const PHP_EOL; @@ -41,7 +40,7 @@ class Frontmatter * * @return string A FRONTMATTER string representing the original PHP value. */ - public function encode($input): string + public function encode(mixed $input): string { $headerSerializer = registry()->get('flextype.settings.serializers.frontmatter.encode.header.serializer'); $allowed = registry()->get('flextype.settings.serializers.frontmatter.encode.header.allowed'); @@ -73,7 +72,7 @@ class Frontmatter * * @return mixed The FRONTMATTER converted to a PHP value. */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.frontmatter.decode.cache.enabled'); $headerSerializer = registry()->get('flextype.settings.serializers.frontmatter.decode.header.serializer'); @@ -102,18 +101,18 @@ class Frontmatter unset($parts[0]); $parts = array_values(array_filter($parts)); } - + // Check for custom frontmatter header serializers if (strings(strings($parts[0])->lines()[1])->trim()->contains('---')) { $headerSerializer = strings(strings($parts[0])->lines()[1])->trim()->after('---')->toString(); - + $parts[0] = strings($parts[0])->replaceFirst('---' . $headerSerializer, '')->toString(); if (! in_array($headerSerializer, $allowed)) { $headerSerializer = 'yaml'; - } + } } - + $frontmatter = serializers()->{$headerSerializer}()->decode(strings($parts[0])->trim()->toString(), false); $content = ['content' => strings($parts[1] ?? '')->trim()->toString()]; diff --git a/src/flextype/core/Serializers/Json.php b/src/flextype/core/Serializers/Json.php index d42d0b4c..3905f1d7 100644 --- a/src/flextype/core/Serializers/Json.php +++ b/src/flextype/core/Serializers/Json.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,14 @@ namespace Flextype\Serializers; use RuntimeException; -use function Flextype\cache; use function defined; +use function Flextype\cache; +use function Flextype\registry; +use function Glowy\Strings\strings; use function json_decode; use function json_encode; use function json_last_error; use function json_last_error_msg; -use function Flextype\registry; -use function Glowy\Strings\strings; use const JSON_PRESERVE_ZERO_FRACTION; use const JSON_PRETTY_PRINT; @@ -45,7 +45,7 @@ class Json * * @return mixed A JSON string representing the original PHP value */ - public function encode($input) + public function encode(mixed $input): mixed { $options = registry()->get('flextype.settings.serializers.json.encode.options'); $depth = registry()->get('flextype.settings.serializers.json.encode.depth'); @@ -73,7 +73,7 @@ class Json * * @throws RuntimeException If the JSON is not valid */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.json.decode.cache.enabled'); $assoc = registry()->get('flextype.settings.serializers.json.decode.assoc'); diff --git a/src/flextype/core/Serializers/Json5.php b/src/flextype/core/Serializers/Json5.php index 2ecb72cb..2a087d81 100644 --- a/src/flextype/core/Serializers/Json5.php +++ b/src/flextype/core/Serializers/Json5.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,14 +18,14 @@ namespace Flextype\Serializers; use RuntimeException; -use function Flextype\cache; use function defined; -use function json_decode; +use function Flextype\cache; +use function Flextype\registry; +use function Glowy\Strings\strings; +use function json5_decode; use function json_encode; use function json_last_error; use function json_last_error_msg; -use function Flextype\registry; -use function Glowy\Strings\strings; use const JSON_PRESERVE_ZERO_FRACTION; use const JSON_PRETTY_PRINT; @@ -45,7 +45,7 @@ class Json5 * * @return mixed A JSON5 string representing the original PHP value. */ - public function encode($input) + public function encode(mixed $input): mixed { $options = registry()->get('flextype.settings.serializers.json5.encode.options'); $depth = registry()->get('flextype.settings.serializers.json5.encode.depth'); @@ -73,7 +73,7 @@ class Json5 * * @throws RuntimeException If the JSON5 is not valid. */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.json5.decode.cache.enabeled'); $assoc = registry()->get('flextype.settings.serializers.json5.decode.assoc'); @@ -81,7 +81,7 @@ class Json5 $flags = registry()->get('flextype.settings.serializers.json5.decode.flags'); $decode = static function (string $input, bool $assoc, int $depth, int $flags) { - return json5_decode($input, $assoc, $depth, $flags);; + return json5_decode($input, $assoc, $depth, $flags); }; if ($cache === true && registry()->get('flextype.settings.cache.enabled') === true) { diff --git a/src/flextype/core/Serializers/Neon.php b/src/flextype/core/Serializers/Neon.php index 31508e73..ea52fcaa 100644 --- a/src/flextype/core/Serializers/Neon.php +++ b/src/flextype/core/Serializers/Neon.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -33,7 +33,7 @@ class Neon * * @return string A NEON string representing the original PHP value. */ - public function encode($input): string + public function encode(mixed $input): string { $blockMode = registry()->get('flextype.settings.serializers.neon.encode.blockMode'); $indentation = registry()->get('flextype.settings.serializers.neon.encode.indentation'); @@ -54,7 +54,7 @@ class Neon * * @return mixed The NEON converted to a PHP value. */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.neon.decode.cache.enabled'); diff --git a/src/flextype/core/Serializers/PhpArray.php b/src/flextype/core/Serializers/PhpArray.php index 7cab1e20..f076887c 100644 --- a/src/flextype/core/Serializers/PhpArray.php +++ b/src/flextype/core/Serializers/PhpArray.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,15 +16,13 @@ declare(strict_types=1); namespace Flextype\Serializers; -use Symfony\Component\VarExporter\VarExporter; - use RuntimeException; -use Exception; +use Symfony\Component\VarExporter\VarExporter; +use Throwable; use function Flextype\cache; use function Flextype\registry; use function Glowy\Strings\strings; -use function var_export; class PhpArray { @@ -35,7 +33,7 @@ class PhpArray * * @return string A PhpArray string representing the original PHP value. */ - public function encode($input): string + public function encode(mixed $input): string { $wrap = registry()->get('flextype.settings.serializers.phparray.encode.wrap'); @@ -45,7 +43,7 @@ class PhpArray } else { $data = VarExporter::export($input); } - } catch (Exception $e) { + } catch (Throwable $e) { throw new RuntimeException('Encoding PhpArray failed'); } @@ -59,14 +57,14 @@ class PhpArray * * @return mixed The PhpArray converted to a PHP value. */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.phparray.decode.cache.enabled'); $decode = static function (string $input) { try { $value = include $input; - } catch (Exception $e) { + } catch (Throwable $e) { throw new RuntimeException('Decoding PhpArray failed'); } diff --git a/src/flextype/core/Serializers/Serializers.php b/src/flextype/core/Serializers/Serializers.php index 4b0fdfa0..8ce6d8ff 100644 --- a/src/flextype/core/Serializers/Serializers.php +++ b/src/flextype/core/Serializers/Serializers.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. diff --git a/src/flextype/core/Serializers/Yaml.php b/src/flextype/core/Serializers/Yaml.php index 08442d66..017817bc 100644 --- a/src/flextype/core/Serializers/Yaml.php +++ b/src/flextype/core/Serializers/Yaml.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -21,13 +21,13 @@ use Symfony\Component\Yaml\Exception\DumpException as SymfonyYamlDumpException; use Symfony\Component\Yaml\Exception\ParseException as SymfonyYamlParseException; use Symfony\Component\Yaml\Yaml as SymfonyYaml; -use function Flextype\cache; use function error_reporting; +use function Flextype\cache; +use function Flextype\registry; use function function_exists; +use function Glowy\Strings\strings; use function ini_get; use function ini_set; -use function Flextype\registry; -use function Glowy\Strings\strings; class Yaml { @@ -53,7 +53,7 @@ class Yaml * * @return string A YAML string representing the original PHP value. */ - public function encode($input): string + public function encode(mixed $input): string { $inline = registry()->get('flextype.settings.serializers.yaml.encode.inline'); $indent = registry()->get('flextype.settings.serializers.yaml.encode.indent'); @@ -80,7 +80,7 @@ class Yaml * * @throws RuntimeException If the YAML is not valid. */ - public function decode(string $input) + public function decode(string $input): mixed { $cache = registry()->get('flextype.settings.serializers.yaml.decode.cache.enabled'); $flags = registry()->get('flextype.settings.serializers.yaml.decode.flags'); diff --git a/src/flextype/core/Whoops.php b/src/flextype/core/Whoops.php index 00c97228..793d5b17 100644 --- a/src/flextype/core/Whoops.php +++ b/src/flextype/core/Whoops.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -17,16 +17,18 @@ declare(strict_types=1); namespace Flextype; use Psr\Http\Message\ServerRequestInterface; +use Whoops\Handler\JsonResponseHandler; +use Whoops\Handler\PlainTextHandler; +use Whoops\Handler\PrettyPageHandler; +use Whoops\Handler\XmlResponseHandler; use Whoops\Run as WhoopsRun; use Whoops\Util\Misc; -use Whoops\Handler\PrettyPageHandler; -use Whoops\Handler\PlainTextHandler; -use Whoops\Handler\JsonResponseHandler; -use Whoops\Handler\XmlResponseHandler; + +use function array_merge; +use function method_exists; class Whoops { - protected $settings = []; protected $request = null; protected $handlers = []; @@ -36,23 +38,20 @@ class Whoops * * @param array $settings */ - public function __construct(array $settings = []) + public function __construct(array $settings = []) { $this->settings = array_merge([ 'enable' => true, 'editor' => 'vscode', 'title' => 'Error!', - 'hadler' => 'plain' + 'hadler' => 'plain', ], $settings); } /** * Set the server request object - * - * @param ServerRequestInterface $request - * @return void */ - public function setRequest(ServerRequestInterface $request): void + public function setRequest(ServerRequestInterface $request): void { $this->request = $request; } @@ -61,26 +60,23 @@ class Whoops * Set the custom handlers for whoops * * @param array $handlers - * @return void */ - public function setHandlers(array $handlers): void + public function setHandlers(array $handlers): void { $this->handlers = $handlers; } /** * Install the whoops guard object - * - * @return WhoopsRun|null */ - public function install(): ?WhoopsRun + public function install(): ?WhoopsRun { if ($this->settings['enable'] === false) { return null; } // Set Whoops to default exception handler - $whoops = new \Whoops\Run; + $whoops = new WhoopsRun(); switch ($this->settings['handler']) { case 'json': @@ -128,19 +124,19 @@ class Whoops 'Port' => $this->request->getUri()->getPort(), 'Host' => $this->request->getUri()->getHost(), ]); - + $whoops->pushHandler($prettyPageHandler); break; } // Enable JsonResponseHandler when request is AJAX - if (Misc::isAjaxRequest() === true){ + if (Misc::isAjaxRequest() === true) { $whoops->pushHandler(new JsonResponseHandler()); } // Add each custom handler to whoops handler stack if (empty($this->handlers) === false) { - foreach($this->handlers as $handler) { + foreach ($this->handlers as $handler) { $whoops->pushHandler($handler); } } @@ -149,4 +145,4 @@ class Whoops return $whoops; } -} \ No newline at end of file +} diff --git a/src/flextype/defines.php b/src/flextype/defines.php index da413332..72b8d881 100644 --- a/src/flextype/defines.php +++ b/src/flextype/defines.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,6 +16,9 @@ declare(strict_types=1); namespace Flextype; +use function define; +use function defined; + if (! defined('FLEXTYPE_MINIMUM_PHP')) { /** * Define the Flextype Application minimum supported PHP version. @@ -42,4 +45,4 @@ if (! defined('FLEXTYPE_PATH_TMP')) { * Define the project tmp path (without trailing slash). */ define('FLEXTYPE_PATH_TMP', FLEXTYPE_ROOT_DIR . '/var/tmp'); -} \ No newline at end of file +} diff --git a/src/flextype/flextype.php b/src/flextype/flextype.php index fb7efe15..3b371266 100644 --- a/src/flextype/flextype.php +++ b/src/flextype/flextype.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -16,21 +16,17 @@ declare(strict_types=1); namespace Flextype; +use Cocur\Slugify\Slugify; +use DateTimeZone; +use Flextype\Console\FlextypeConsole; +use Flextype\Entries\Entries; +use Flextype\Middlewares\WhoopsMiddleware; +use Flextype\Parsers\Parsers; +use Flextype\Serializers\Serializers; use Glowy\Csrf\Csrf; use Glowy\Session\Session; use Glowy\View\View; -use Cocur\Slugify\Slugify; -use DateTimeZone; -use Flextype\Entries\Entries; -use Flextype\Handlers\HttpErrorHandler; -use Flextype\Handlers\ShutdownHandler; -use Flextype\Parsers\Parsers; -use Flextype\Serializers\Serializers; -use Flextype\Tokens\Tokens; -use Intervention\Image\ImageManager; use League\Event\Emitter; -use League\Flysystem\Filesystem as Flysystem; -use League\Flysystem\Local\LocalFilesystemAdapter as Local; use Monolog\Handler\StreamHandler; use Monolog\Logger; use Phpfastcache\Drivers\Apcu\Config; @@ -39,50 +35,37 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; -use Slim\Factory\ServerRequestCreatorFactory; use Slim\Middleware\ContentLengthMiddleware; use Slim\Middleware\OutputBufferingMiddleware; use Slim\Middleware\RoutingMiddleware; use Slim\Psr7\Factory\StreamFactory; -use Slim\Psr7\Response; -use Slim\Psr7\Stream; -use Symfony\Component\Yaml\Yaml as SymfonyYaml; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; -use Flextype\Middlewares\WhoopsMiddleware; -use Flextype\Console\FlextypeConsole; +use Symfony\Component\Yaml\Yaml as SymfonyYaml; -use function Flextype\setBasePath; -use function Flextype\app; use function array_replace_recursive; -use function Flextype\container; use function count; use function date; use function date_default_timezone_set; -use function define; -use function Flextype\emitter; use function extension_loaded; use function file_exists; use function filemtime; -use function Glowy\Filesystem\filesystem; -use function Flextype\flextype; use function function_exists; +use function Glowy\Filesystem\filesystem; +use function Glowy\Registry\registry; +use function Glowy\Strings\strings; use function implode; use function in_array; use function mb_internal_encoding; use function mb_language; use function mb_regex_encoding; use function md5; -use function Flextype\parsers; -use function Flextype\plugins; -use function register_shutdown_function; -use function Glowy\Registry\registry; -use function Flextype\session; -use function Glowy\Strings\strings; +use function php_sapi_name; +use function sprintf; use function sys_get_temp_dir; use function trim; use function var_export; use function version_compare; -use const DIRECTORY_SEPARATOR; + use const PHP_VERSION; // Get defines. @@ -168,11 +151,12 @@ if (filesystem()->file($preflightFlextypePath . '/' . $cacheID . '.php')->exists filesystem()->file($preflightFlextypePath . $cacheID . '.php')->put("set('flextype', $flextypeData); // Set Flextype Aplication base path -setBasePath('/' . registry()->get('flextype.settings.base_path')); +setBasePath(registry()->get('flextype.settings.base_path')); // Add Routing Middleware app()->add(new RoutingMiddleware(app()->getRouteResolver(), app()->getRouteCollector()->getRouteParser())); @@ -421,4 +405,4 @@ if (php_sapi_name() === 'cli') { registry()->get('flextype.settings.cli.enabled') and console()->run(); } else { registry()->get('flextype.settings.app.enabled') and app()->run(); -} \ No newline at end of file +} diff --git a/src/flextype/helpers/collection.php b/src/flextype/helpers/collection.php index 8824e017..8a9e0f9b 100644 --- a/src/flextype/helpers/collection.php +++ b/src/flextype/helpers/collection.php @@ -1,4 +1,4 @@ -directories() : $find->files(); } -} \ No newline at end of file +} diff --git a/src/flextype/helpers/helpers.php b/src/flextype/helpers/helpers.php index efbd3991..b50954d7 100644 --- a/src/flextype/helpers/helpers.php +++ b/src/flextype/helpers/helpers.php @@ -11,4 +11,4 @@ require_once __DIR__ . '/finder.php'; require_once __DIR__ . '/image.php'; require_once __DIR__ . '/upload.php'; require_once __DIR__ . '/tokens.php'; -require_once __DIR__ . '/url.php'; \ No newline at end of file +require_once __DIR__ . '/url.php'; diff --git a/src/flextype/helpers/i18n.php b/src/flextype/helpers/i18n.php index cfe06077..a519b9b5 100644 --- a/src/flextype/helpers/i18n.php +++ b/src/flextype/helpers/i18n.php @@ -1,12 +1,12 @@ - $username], 'en_US'); * - * @param string $translate Translate to find - * @param array $values Values to replace in the translated text - * @param string $locale Locale - * @return string + * @param string $translate Translate to find + * @param array $values Values to replace in the translated text + * @param string|null $locale Locale */ - function __(string $translate, array $values = [], string $locale = null) : string + function __(string $translate, array $values = [], string|null $locale = null): string { return I18n::find($translate, $values, $locale); } -} \ No newline at end of file +} diff --git a/src/flextype/helpers/image.php b/src/flextype/helpers/image.php index 8c7932ba..2d8aab1a 100644 --- a/src/flextype/helpers/image.php +++ b/src/flextype/helpers/image.php @@ -1,4 +1,4 @@ -container()->get('plugins'); } -} \ No newline at end of file +} diff --git a/src/flextype/helpers/tokens.php b/src/flextype/helpers/tokens.php index 2fe160e6..26611c49 100644 --- a/src/flextype/helpers/tokens.php +++ b/src/flextype/helpers/tokens.php @@ -1,15 +1,23 @@ -get('flextype.settings.upload'); - $uploadFolder = strings(FLEXTYPE_PATH_PROJECT . '/' . $settings['directory'] . '/' . $folder . '/')->reduceSlashes()->toString(); + $uploadFolder = strings(FLEXTYPE_PATH_PROJECT . '/' . $settings['directory'] . '/' . $folder . '/')->reduceSlashes()->toString(); filesystem()->directory($uploadFolder)->ensureExists(0755, true); @@ -50,12 +53,11 @@ if (! function_exists('upload')) { try { $result->confirm(); - - // If upload file is image, do image file processing + + // If upload file is image, do image file processing if ($result->name) { - $mediaFile = $uploadFolder . '/' . $result->name; - + if (getimagesize($mediaFile)) { imageFile($mediaFile, $settings['process']['image']); } @@ -68,4 +70,4 @@ if (! function_exists('upload')) { return $result; } -} \ No newline at end of file +} diff --git a/src/flextype/helpers/url.php b/src/flextype/helpers/url.php index bafb617c..9877d6d9 100644 --- a/src/flextype/helpers/url.php +++ b/src/flextype/helpers/url.php @@ -1,14 +1,16 @@ - $data Route placeholders. * - * @return bool + * @param ServerRequestInterface $request Servert request interface. + * @param string $routeName Route name. + * @param array $data Route placeholders. */ function isCurrentUrl(ServerRequestInterface $request, string $routeName, array $data = []): bool { $currentUrl = getBasePath() . $request->getUri()->getPath(); - $result = app()->getRouteCollector()->getRouteParser()->urlFor($routeName, $data); + $result = app()->getRouteCollector()->getRouteParser()->urlFor($routeName, $data); return $result === $currentUrl; } @@ -68,16 +68,14 @@ if (! function_exists('getCurrentUrl')) { * * @param ServerRequestInterface $request Servert request interface. * @param bool $withQueryString Get query string for current path. - * - * @return string */ function getCurrentUrl(ServerRequestInterface $request, bool $withQueryString = false): string { $currentUrl = getBasePath() . $request->getUri()->getPath(); - $query = $request->getUri()->getQuery(); + $query = $request->getUri()->getQuery(); - if ($withQueryString && !empty($query)) { - $currentUrl .= '?'.$query; + if ($withQueryString && ! empty($query)) { + $currentUrl .= '?' . $query; } return $currentUrl; @@ -101,10 +99,8 @@ if (! function_exists('setBasePath')) { * Set the base path. * * @param string $basePath Base path. - * - * @return void */ - function setBasePath(string $basePath) + function setBasePath(string $basePath): void { app()->setBasePath($basePath); } @@ -121,7 +117,7 @@ if (! function_exists('getBaseUrl')) { $baseUrl = registry()->get('flextype.settings.base_url') ?? ''; $basePath = registry()->get('flextype.settings.base_path') ?? ''; - if ($baseUrl != '') { + if ($baseUrl !== '') { return strings($baseUrl . '/' . $basePath)->reduceSlashes()->trimRight('/')->toString(); } @@ -142,9 +138,9 @@ if (! function_exists('getBaseUrl')) { $isHttps = static function (): bool { if (array_key_exists('HTTPS', $_SERVER)) { - return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; + return ! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; } - + return false; }; @@ -153,7 +149,7 @@ if (! function_exists('getBaseUrl')) { $isHttps = $isHttps(); $url .= $getAuth(); - + $serverData = collection($_SERVER); $host = (string) $serverData->get('HTTP_HOST'); @@ -162,7 +158,7 @@ if (! function_exists('getBaseUrl')) { if ($isHttps && $port !== 443) { $url .= $port ? ":{$port}" : ''; - } elseif (!$isHttps && $port !== 80) { + } elseif (! $isHttps && $port !== 80) { $url .= $port ? ":{$port}" : ''; } @@ -174,9 +170,7 @@ if (! function_exists('getBaseUrl')) { } } - $url .= '/' . $basePath; - - return $url; + return $url . '/' . $basePath; } } @@ -209,14 +203,12 @@ if (! function_exists('getProjectUrl')) { $url .= FLEXTYPE_PROJECT_NAME; return $url; - } + } } if (! function_exists('getUriString')) { /** * Get uri string. - * - * @return string */ function getUriString(): string { @@ -232,8 +224,6 @@ if (! function_exists('redirect')) { * @param array $data Route placeholders. * @param array $queryParams Query parameters. * @param int $status Status code. - * - * @return Response */ function redirect(string $routeName, array $data = [], array $queryParams = [], int $status = 301): Response { @@ -243,4 +233,4 @@ if (! function_exists('redirect')) { return $response; } -} \ No newline at end of file +} diff --git a/src/flextype/macros/collection.php b/src/flextype/macros/collection.php index a9887dc1..85e6320a 100644 --- a/src/flextype/macros/collection.php +++ b/src/flextype/macros/collection.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Flextype; use Glowy\Arrays\Arrays as Collection; + use function Glowy\Arrays\arrays as collection; if (! Collection::hasMacro('onlyFromCollection')) { diff --git a/src/flextype/macros/macros.php b/src/flextype/macros/macros.php index 22cb312a..5128a23c 100644 --- a/src/flextype/macros/macros.php +++ b/src/flextype/macros/macros.php @@ -4,4 +4,4 @@ declare(strict_types=1); namespace Flextype; -require_once __DIR__ . '/collection.php'; \ No newline at end of file +require_once __DIR__ . '/collection.php'; diff --git a/src/flextype/routes/endpoints/cache.php b/src/flextype/routes/endpoints/cache.php index d940e482..c5246fb4 100644 --- a/src/flextype/routes/endpoints/cache.php +++ b/src/flextype/routes/endpoints/cache.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,8 +18,6 @@ namespace Flextype; use Flextype\Endpoints\Cache; -use function Flextype\app; - /** * Clear cache. * diff --git a/src/flextype/routes/endpoints/entries.php b/src/flextype/routes/endpoints/entries.php index f1c9a069..c60d4136 100644 --- a/src/flextype/routes/endpoints/entries.php +++ b/src/flextype/routes/endpoints/entries.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,8 +18,6 @@ namespace Flextype; use Flextype\Endpoints\Entries; -use function Flextype\app; - /** * Fetch entry * diff --git a/src/flextype/routes/endpoints/registry.php b/src/flextype/routes/endpoints/registry.php index dc37d193..e59f61d3 100644 --- a/src/flextype/routes/endpoints/registry.php +++ b/src/flextype/routes/endpoints/registry.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,8 +18,6 @@ namespace Flextype; use Flextype\Endpoints\Registry; -use function Flextype\app; - /** * Get registry item * diff --git a/src/flextype/routes/endpoints/tokens.php b/src/flextype/routes/endpoints/tokens.php index 960f0fac..8ea032be 100644 --- a/src/flextype/routes/endpoints/tokens.php +++ b/src/flextype/routes/endpoints/tokens.php @@ -3,9 +3,9 @@ declare(strict_types=1); /** - * Flextype - Hybrid Content Management System with the freedom of a headless CMS + * 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. @@ -18,8 +18,6 @@ namespace Flextype; use Flextype\Endpoints\Tokens; -use function Flextype\app; - /** * Generate token * @@ -28,7 +26,7 @@ use function Flextype\app; * Body: * token - [REQUIRED] - Valid public token. * access_token - [REQUIRED] - Valid private access token. - * + * * Returns: * Generated token object. */ @@ -43,7 +41,7 @@ app()->post('/api/v1/tokens/generate', [Tokens::class, 'generate'])->setName('to * token - [REQUIRED] - Valid public token. * access_token - [REQUIRED] - Valid private access token. * string - [REQUIRED] - String to hash. - * + * * Returns: * Generated token hash object. */ @@ -59,7 +57,7 @@ app()->post('/api/v1/tokens/generate-hash', [Tokens::class, 'generateHash'])->se * access_token - [REQUIRED] - Valid private access token. * string - [REQUIRED] - String to verify. * hash - [REQUIRED] - Hash to verify. - * + * * Returns: * Token verification object. */ diff --git a/src/flextype/routes/routes.php b/src/flextype/routes/routes.php index 16840c01..d53a1901 100644 --- a/src/flextype/routes/routes.php +++ b/src/flextype/routes/routes.php @@ -15,4 +15,4 @@ require_once __DIR__ . '/endpoints/registry.php'; // Add project routes if (filesystem()->file(FLEXTYPE_PATH_PROJECT . '/routes/routes.php')->exists()) { require_once FLEXTYPE_PATH_PROJECT . '/routes/routes.php'; -} \ No newline at end of file +} diff --git a/src/flextype/settings.yaml b/src/flextype/settings.yaml index 0a95be50..d03c3a7f 100644 --- a/src/flextype/settings.yaml +++ b/src/flextype/settings.yaml @@ -328,20 +328,17 @@ cache: phparray: path: '/data' security_key: 'auto' - htaccess: true secure_file_manipulation: false default_ttl: 900 files: path: '/data' security_key: 'auto' - htaccess: true secure_file_manipulation: false cache_file_extension: txt default_ttl: 900 leveldb: path: '/data' security_key: 'auto' - htaccess: true default_ttl: 900 memcache: host: '127.0.0.1' @@ -391,7 +388,6 @@ cache: sqlite: path: '/data' security_key: auto - htaccess: true default_ttl: 900 ssdb: host: 127.0.0.1