From 6878334745b1ad974c95ff37e73b4e2dfcf812ae Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:42:33 +0300 Subject: [PATCH 01/52] feat(core): remove YamlTwigExtension --- twig/YamlTwigExtension.php | 65 -------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 twig/YamlTwigExtension.php diff --git a/twig/YamlTwigExtension.php b/twig/YamlTwigExtension.php deleted file mode 100644 index 389d9c1..0000000 --- a/twig/YamlTwigExtension.php +++ /dev/null @@ -1,65 +0,0 @@ -yaml()->encode($input); - } - - /** - * Decode YAML - */ - public function decode(string $input, bool $cache = true) - { - return flextype('serializers')->yaml()->decode($input, $cache); - } -} From 61a1c7ffbbc1f8a9fdfc6e8cf173e62b195e7591 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:42:45 +0300 Subject: [PATCH 02/52] feat(core): remove ShortcodeTwigExtension --- twig/ShortcodeTwigExtension.php | 47 --------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 twig/ShortcodeTwigExtension.php diff --git a/twig/ShortcodeTwigExtension.php b/twig/ShortcodeTwigExtension.php deleted file mode 100644 index 279cde0..0000000 --- a/twig/ShortcodeTwigExtension.php +++ /dev/null @@ -1,47 +0,0 @@ -shortcode()->process($value); - } - - return ''; - } -} From 5829a304a58508e4708a0f4b693b684a940ec10d Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:42:55 +0300 Subject: [PATCH 03/52] feat(core): remove RegistryTwigExtension --- twig/RegistryTwigExtension.php | 96 ---------------------------------- 1 file changed, 96 deletions(-) delete mode 100644 twig/RegistryTwigExtension.php diff --git a/twig/RegistryTwigExtension.php b/twig/RegistryTwigExtension.php deleted file mode 100644 index f17ccb3..0000000 --- a/twig/RegistryTwigExtension.php +++ /dev/null @@ -1,96 +0,0 @@ - new RegistryTwig(), - ]; - } -} - -class RegistryTwig -{ - /** - * Flextype Application - */ - - - /** - * Constructor - */ - public function __construct() - { - - } - - /** - * Get registry array - * - * @return array - */ - public function dump() : array - { - return flextype('registry')->dump(); - } - - /** - * Checks if an object with this name is in the registry. - * - * @param string $name The name of the registry item to check for existence. - * @return bool - */ - public function has(string $name) : bool - { - return flextype('registry')->has($name); - } - - /** - * Registers a given value under a given name. - * - * @param string $name The name of the value to store. - * @param mixed $value The value that needs to be stored. - * @return void - */ - public function set(string $name, $value = null) : void - { - flextype('registry')->set($name, $value); - } - - /** - * Get item from the registry. - * - * @param string $name The name of the item to fetch. - * @param mixed $default Default value - * @return mixed - */ - public function get(string $name, $default = null) - { - return flextype('registry')->get($name, $default); - } -} From f2a6ab1803ef1a6e6061158888be1cf49939017c Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:43:05 +0300 Subject: [PATCH 04/52] feat(core): remove MediaTwigExtension --- twig/MediaTwigExtension.php | 110 ------------------------------------ 1 file changed, 110 deletions(-) delete mode 100644 twig/MediaTwigExtension.php diff --git a/twig/MediaTwigExtension.php b/twig/MediaTwigExtension.php deleted file mode 100644 index 4c5a601..0000000 --- a/twig/MediaTwigExtension.php +++ /dev/null @@ -1,110 +0,0 @@ - new MediaTwig(), - ]; - } -} - -class MediaTwig -{ - /** - * Create a Media Files instance. - */ - public function files(): MediaFiles - { - return new MediaTwigFiles(); - } - - /** - * Create a Media Files instance. - */ - public function folders(): MediaFolders - { - return new MediaTwigFolders(); - } -} - -class MediaTwigFiles -{ - public function meta(): MediaTwigFilesMeta - { - return new MediaTwigFilesMeta(); - } - - public function fetch(string $path, array $options = []): Arrays - { - return flextype('media')->files()->fetch($path, $options); - } - - public function has(string $path): bool - { - return flextype('media')->files()->has($path); - } - - public function getFileLocation(string $path): bool - { - return flextype('media')->files()->getFileLocation($path); - } -} - - -class MediaTwigFilesMeta -{ - public function getFileMetaLocation(string $path): bool - { - return flextype('media')->files()->meta()->getFileMetaLocation($path); - } -} - -class MediaTwigFolders -{ - public function meta(): MediaTwigFoldersMeta - { - return new MediaTwigFoldersMeta(); - } - - public function fetch(string $path, array $options = []): Arrays - { - return flextype('media')->folders()->fetch($path, $options); - } - - public function has(string $path): bool - { - return flextype('media')->folders()->has($path); - } - - public function getDirectoryLocation(string $path): bool - { - return flextype('media')->folders()->getDirectoryLocation($path); - } -} - - -class MediaTwigFoldersMeta -{ - public function getDirectoryMetaLocation(string $path): bool - { - return flextype('media')->folders()->meta()->getDirectoryMetaLocation($path); - } -} From fab27b80b4386d5873272352ad4b73355134be37 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:43:16 +0300 Subject: [PATCH 05/52] feat(core): remove MarkdownTwigExtension --- twig/MarkdownTwigExtension.php | 47 ---------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 twig/MarkdownTwigExtension.php diff --git a/twig/MarkdownTwigExtension.php b/twig/MarkdownTwigExtension.php deleted file mode 100644 index 5b85d0a..0000000 --- a/twig/MarkdownTwigExtension.php +++ /dev/null @@ -1,47 +0,0 @@ -markdown()->parse($input, $cache); - } - - return ''; - } -} From fe4f432f7e3ddf868e14b5261b83f2e5977d4fce Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 12:43:25 +0300 Subject: [PATCH 06/52] feat(core): remove JsonTwigExtension --- twig/JsonTwigExtension.php | 65 -------------------------------------- 1 file changed, 65 deletions(-) delete mode 100644 twig/JsonTwigExtension.php diff --git a/twig/JsonTwigExtension.php b/twig/JsonTwigExtension.php deleted file mode 100644 index f56e4e9..0000000 --- a/twig/JsonTwigExtension.php +++ /dev/null @@ -1,65 +0,0 @@ -json()->encode($input); - } - - /** - * Decode JSON - */ - public function decode(string $input, bool $cache = true) - { - return flextype('serializers')->json()->decode($input, $cache); - } -} From 05f97ca26f1fbeb276e2c3277bfd91fbb463b41b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:16:02 +0300 Subject: [PATCH 07/52] feat(core): remove FlextypeTwigExtension --- twig/FlextypeTwigExtension.php | 245 +++++++++++++++++++++++++++++++++ 1 file changed, 245 insertions(+) create mode 100644 twig/FlextypeTwigExtension.php diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php new file mode 100644 index 0000000..5c60e3c --- /dev/null +++ b/twig/FlextypeTwigExtension.php @@ -0,0 +1,245 @@ + new FlextypeTwig(), + ]; + } +} + +class FlextypeTwig +{ + use Macroable; + + public function entries() + { + return new FlextypeEntriesTwig(); + } + + public function media() + { + return new FlextypeMediaTwig(); + } + + public function registry() + { + return flextype('registry'); + } + + public function parsers() + { + return flextype('parsers'); + } + + public function serializers() + { + return flextype('serializers'); + } + + public function cache() + { + return flextype('cache'); + } + + public function emitter() + { + return flextype('emitter'); + } +} + +class FlextypeEntriesTwig +{ + use Macroable; + + /** + * Fetch. + * + * @param string $id Unique identifier of the entry. + * @param array $options Options array. + * + * @access public + * + * @return self Returns instance of The Arrays class. + */ + public function fetch(string $id, array $options = []): Arrays + { + return flextype('entries')->fetch($id, $options); + } +} + +class FlextypeMediaTwig +{ + use Macroable; + + /** + * Create a Media Files instance. + */ + public function files(): MediaFiles + { + return new FlextypeMediaTwigFiles(); + } + + /** + * Create a Media Files instance. + */ + public function folders(): MediaFolders + { + return new FlextypeMediaTwigFolders(); + } +} + +class FlextypeMediaTwigFiles +{ + use Macroable; + + /** + * Create a Media Files Meta instance. + */ + public function meta(): MediaTwigFilesMeta + { + return new FlextypeMediaTwigFilesMeta(); + } + + /** + * Fetch. + * + * @param string $id The path to file. + * @param array $options Options array. + * + * @return self Returns instance of The Arrays class. + * + * @access public + */ + public function fetch(string $id, array $options = []): Arrays + { + return flextype('media')->files()->fetch($id, $options); + } + + /** + * Check whether a file exists. + * + * @param string $id Unique identifier of the file. + * + * @return bool True on success, false on failure. + * + * @access public + */ + public function has(string $id): bool + { + return flextype('media')->files()->has($id); + } + + /** + * Get file location + * + * @param string $id Unique identifier of the file. + * + * @return string entry file location + * + * @access public + */ + public function getFileLocation(string $id): bool + { + return flextype('media')->files()->getFileLocation($id); + } +} + +class FlextypeMediaTwigFilesMeta +{ + use Macroable; + + /** + * Get file meta location + * + * @param string $id Unique identifier of the file. + * + * @return string entry file location + * + * @access public + */ + public function getFileMetaLocation(string $id): bool + { + return flextype('media')->files()->meta()->getFileMetaLocation($id); + } +} + +class FlextypeMediaTwigFolders +{ + use Macroable; + + /** + * Create a Media Folders Meta instance. + */ + public function meta(): MediaTwigFoldersMeta + { + return new FlextypeMediaTwigFoldersMeta(); + } + + /** + * Fetch. + * + * @param string $id The path to folder. + * @param array $options Options array. + * + * @return self Returns instance of The Arrays class. + * + * @access public + */ + public function fetch(string $id, array $options = []): Arrays + { + return flextype('media')->folders()->fetch($id, $options); + } + + /** + * Get files directory location + * + * @param string $id Unique identifier of the folder. + * + * @return string entry directory location + * + * @access public + */ + public function getDirectoryLocation(string $id): string + { + return flextype('media')->folders()->getDirectoryLocation($id); + } +} + +class FlextypeMediaTwigFoldersMeta +{ + use Macroable; + + /** + * Get files directory meta location + * + * @param string $id Unique identifier of the folder. + * + * @return string entry directory location + * + * @access public + */ + public function getDirectoryMetaLocation(string $id): string + { + return flextype('media')->folders()->meta()->getDirectoryMetaLocation($id); + } +} From 86fa32c8a426308358f3cc8b2e061a24e0d1862b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:16:27 +0300 Subject: [PATCH 08/52] feat(core): remove EntriesTwigExtension --- twig/EntriesTwigExtension.php | 49 ----------------------------------- 1 file changed, 49 deletions(-) delete mode 100644 twig/EntriesTwigExtension.php diff --git a/twig/EntriesTwigExtension.php b/twig/EntriesTwigExtension.php deleted file mode 100644 index bd56eb1..0000000 --- a/twig/EntriesTwigExtension.php +++ /dev/null @@ -1,49 +0,0 @@ - new EntriesTwig(), - ]; - } -} - -class EntriesTwig -{ - /** - * Flextype Application - */ - - /** - * Constructor - */ - public function __construct() - { - - } - - /** - * Fetch. - */ - public function fetch(string $id, array $options = []) - { - return flextype('entries')->fetch($id, $options); - } -} From 10dd1a5ad5921dddfc7f507a4dbdee90e18a400f Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:16:41 +0300 Subject: [PATCH 09/52] feat(core): remove EmitterTwigExtension --- twig/EmitterTwigExtension.php | 66 ----------------------------------- 1 file changed, 66 deletions(-) delete mode 100644 twig/EmitterTwigExtension.php diff --git a/twig/EmitterTwigExtension.php b/twig/EmitterTwigExtension.php deleted file mode 100644 index 23305e0..0000000 --- a/twig/EmitterTwigExtension.php +++ /dev/null @@ -1,66 +0,0 @@ - new EmitterTwig(), - ]; - } -} - -class EmitterTwig -{ - /** - * Flextype Application - */ - - - /** - * Constructor - */ - public function __construct() - { - - } - - /** - * Emitting event - */ - public function emit($event) - { - return flextype('emitter')->emit($event); - } - - /** - * Emitting events in batches - */ - public function emitBatch(array $events) - { - return flextype('emitter')->emitBatch($events); - } -} From 5e3d903cb0c96df6344e13cb5d4615f6b5a772ef Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:16:51 +0300 Subject: [PATCH 10/52] feat(core): remove CacheTwigExtension --- twig/CacheTwigExtension.php | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 twig/CacheTwigExtension.php diff --git a/twig/CacheTwigExtension.php b/twig/CacheTwigExtension.php deleted file mode 100644 index 2058a62..0000000 --- a/twig/CacheTwigExtension.php +++ /dev/null @@ -1,34 +0,0 @@ - flextype('cache'), - ]; - } -} From 791eded7e8a398e76cdef30b0ef706da7ac5205a Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:17:23 +0300 Subject: [PATCH 11/52] refactor(core): remove complexity from ArraysTwigExtension --- twig/ArraysTwigExtension.php | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/twig/ArraysTwigExtension.php b/twig/ArraysTwigExtension.php index 8032b18..7e39cae 100644 --- a/twig/ArraysTwigExtension.php +++ b/twig/ArraysTwigExtension.php @@ -9,19 +9,10 @@ namespace Flextype\Plugin\Twig\Twig; -use Atomastic\Arrays\Arrays; use Twig\Extension\AbstractExtension; class ArraysTwigExtension extends AbstractExtension { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Callback for twig. * @@ -30,21 +21,7 @@ public function __construct() public function getFunctions() : array { return [ - new \Twig\TwigFunction('arrays', [$this, 'arrays']), + new \Twig\TwigFunction('arrays', 'arrays'), ]; } - - /** - * Create a new arrayable object from the given elements. - * - * Initializes a Arrays object and assigns $items the supplied values. - * - * @param mixed $items Items - * - * @return Atomastic\Arrays\Arrays - */ - function arrays($items = []): Arrays - { - return Arrays::create($items); - } } From bb5fac5ba198f06f9f457fdac0beb19cb9788212 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:17:34 +0300 Subject: [PATCH 12/52] refactor(core): remove complexity from CsrfTwigExtension --- twig/CsrfTwigExtension.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/twig/CsrfTwigExtension.php b/twig/CsrfTwigExtension.php index 60697bb..aab3951 100644 --- a/twig/CsrfTwigExtension.php +++ b/twig/CsrfTwigExtension.php @@ -14,14 +14,6 @@ class CsrfTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Register Global variables in an extension */ From db865a83c935f7da868a21d7a8753d73916998a4 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:17:55 +0300 Subject: [PATCH 13/52] refactor(core): update FilesystemTwigExtension --- twig/FilesystemTwigExtension.php | 333 ++++++++++++++++++++++++++++--- 1 file changed, 309 insertions(+), 24 deletions(-) diff --git a/twig/FilesystemTwigExtension.php b/twig/FilesystemTwigExtension.php index 128d6cf..8db5a5f 100644 --- a/twig/FilesystemTwigExtension.php +++ b/twig/FilesystemTwigExtension.php @@ -9,52 +9,337 @@ namespace Flextype\Plugin\Twig\Twig; -use Flextype\Component\Filesystem\Filesystem; use Twig\Extension\AbstractExtension; -use function basename; -use function strrchr; -use function substr; +use Twig\Extension\GlobalsInterface; +use Atomastic\Macroable\Macroable; +use Symfony\Component\Finder\Finder; -class FilesystemTwigExtension extends AbstractExtension +class FilesystemTwigExtension extends AbstractExtension implements GlobalsInterface { /** - * Callback for twig. - * - * @return array + * Register Global variables in an extension */ - public function getFunctions() : array + public function getGlobals() : array { return [ - new \Twig\TwigFunction('filesystem_list_contents', [$this, 'list_contents']), - new \Twig\TwigFunction('filesystem_has', [$this, 'has']), - new \Twig\TwigFunction('filesystem_read', [$this, 'read']), - new \Twig\TwigFunction('filesystem_ext', [$this, 'ext']), - new \Twig\TwigFunction('filesystem_basename', [$this, 'basename']), + 'filesystem' => new FilesystemTwig(), ]; } +} + +class FilesystemTwig +{ + use Macroable; + + /** + * Create a File instance. + */ + public function file($path): FilesystemFileTwig + { + return new FilesystemFileTwig($path); + } + + /** + * Create a Directory instance. + */ + public function directory($path): FilesystemDirectoryTwig + { + return new FilesystemDirectoryTwig($path); + } + + /** + * Create a Finder instance. + */ + public function find(): Finder + { + return filesystem()->find(); + } + + /** + * Determine if the given path is a stream path. + * + * @param string $path Path to check. + * + * @return bool Returns TRUE if the given path is stream path, FALSE otherwise. + */ + public function isStream(string $path): bool + { + return filesystem()->isStream($path); + } + + /** + * Determine if the given path is absolute path. + * + * @param string $path Path to check. + * + * @return bool Returns TRUE if the given path is absolute path, FALSE otherwise. + */ + public function isAbsolute(string $path): bool + { + return filesystem()->isAbsolute($path); + } + + /** + * Determine if the given path is a Windows path. + * + * @param string $path Path to check. + * + * @return bool true if windows path, false otherwise + */ + public function isWindowsPath(string $path): bool + { + return filesystem()->isWindowsPath($path); + } + + /** + * Find path names matching a given pattern. + * + * @param string $pattern The pattern. + * @param int $flags Valid flags. + * + * @return array Returns an array containing the matched files/directories, an empty array if no file matched. + */ + public function glob(string $pattern, int $flags = 0): array + { + return filesystem()->glob($pattern, $flags); + } +} + +class FilesystemFileTwig +{ + use Macroable; - public function list_contents(string $directory = '', bool $recursive = false) + /** + * Path property + * + * Current file absolute path + * + * @var string|null + */ + public $path; + + /** + * Constructor + * + * @param string $path Path to file. + */ + public function __construct(string $path) { - return Filesystem::listContents($directory, $recursive); + $this->path = $path; } - public function has($path) + /** + * Get the contents of a file. + * + * @return string|false The file contents or false on failure. + */ + public function get() { - return Filesystem::has($path); + return filesystem()->file($this->path)->get(); } - public function read($path) + /** + * Checks the existence of file and returns false if any of them is missing. + * + * @return bool Returns true or false if any of them is missing. + */ + public function exists(): bool { - return Filesystem::read($path); + return filesystem()->file($this->path)->exists(); } - public function ext($file) + /** + * Get the file's last modification time. + * + * @return int Returns the time the file was last modified. + */ + public function lastModified(): int { - return substr(strrchr($file, '.'), 1); + return filesystem()->file($this->path)->lastModified(); } - public function basename($value, $suffix = '') + /** + * Get the file's last access time. + * + * @return int Returns the time the file was last assecc. + */ + public function lastAccess(): int + { + return filesystem()->file($this->path)->lastAccess(); + } + + /** + * Get the mime-type of a given file. + * + * @return string The mime-type of a given file. + */ + public function mimeType(): string + { + return filesystem()->file($this->path)->mimeType(); + } + + /** + * Get the file type of a given file. + * + * @return string The file type of a given file. + */ + public function type(): string + { + return filesystem()->file($this->path)->type(); + } + + /** + * Get the file extension from a file path. + * + * @return string The extension of a given file. + */ + public function extension(): string + { + return filesystem()->file($this->path)->extension(); + } + + /** + * Get the trailing name component from a file path. + * + * @return string The trailing name of a given file. + */ + public function basename(): string + { + return filesystem()->file($this->path)->basename(); + } + + /** + * Get the file name from a file path. + * + * @return string The file name of a given file. + */ + public function name(): string + { + return filesystem()->file($this->path)->name(); + } + + /** + * Return current path. + * + * @return string|null Current path + */ + public function path(): ?string + { + return filesystem()->file($this->path)->path(); + } + + /** + * Gets file size in bytes. + * + * @return int Returns the size of the file in bytes. + */ + public function size(): int + { + return filesystem()->file($this->path)->size(); + } + + /** + * Get the MD5 hash of the file at the given path. + * + * @return string Returns a string on success, FALSE otherwise. + */ + public function hash(): string + { + return filesystem()->file($this->path)->hash(); + } + + /** + * Determine if the given path is readable. + * + * @return bool Returns TRUE if the given path exists and is readable, FALSE otherwise. + */ + public function isReadable(): bool + { + return filesystem()->file($this->path)->isReadable(); + } + + /** + * Determine if the given path is writable. + * + * @return bool Returns TRUE if the given path exists and is writable, FALSE otherwise. + */ + public function isWritable(): bool + { + return filesystem()->file($this->path)->isWritable(); + } + + /** + * Determine if the given path is a regular file. + * + * @return bool Returns TRUE if the filename exists and is a regular file, FALSE otherwise. + */ + public function isFile(): bool + { + return filesystem()->file($this->path)->isFile(); + } +} + + +class FilesystemDirectoryTwig +{ + use Macroable; + + /** + * Path property + * + * Current directory path. + * + * @var string|null + */ + public $path; + + /** + * Constructor + * + * @param string $path Path to directory. + */ + public function __construct(string $path) + { + $this->path = $path; + } + + /** + * Checks the existence of directory and returns false if any of them is missing. + * + * @return bool Returns true or false if any of them is missing. + */ + public function exists(): bool + { + return filesystem()->directory($this->path)->exists(); + } + + /** + * Gets size of a given directory in bytes. + * + * @return int Returns the size of the directory in bytes. + */ + public function size(): int + { + return filesystem()->directory($this->path)->size(); + } + + /** + * Determine if the given path is a directory. + * + * @return bool Returns TRUE if the given path exists and is a directory, FALSE otherwise. + */ + public function isDirectory(): bool + { + return filesystem()->directory($this->path)->isDirectory(); + } + + /** + * Return current path. + * + * @return string|null Current path + */ + public function path(): ?string { - return basename($value, $suffix); + return filesystem()->directory($this->path)->path(); } } From a6ea0333187d04346c45d873addd10bb368e4226 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:18:08 +0300 Subject: [PATCH 14/52] feat(core): add FiltersTwigExtension --- twig/FiltersTwigExtension.php | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 twig/FiltersTwigExtension.php diff --git a/twig/FiltersTwigExtension.php b/twig/FiltersTwigExtension.php new file mode 100644 index 0000000..2779875 --- /dev/null +++ b/twig/FiltersTwigExtension.php @@ -0,0 +1,37 @@ +shortcode()->process($value) : ''; + } + + public function markdown($value) : string + { + return !empty($value) ? flextype('parsers')->markdown()->process($value) : ''; + } +} From bfa492ae00c62fb4d5a9798aff4d6157f2fff344 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:18:31 +0300 Subject: [PATCH 15/52] refactor(core): remove complexity from FlashTwigExtension --- twig/FlashTwigExtension.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/twig/FlashTwigExtension.php b/twig/FlashTwigExtension.php index bfb7ea8..eaac0d0 100644 --- a/twig/FlashTwigExtension.php +++ b/twig/FlashTwigExtension.php @@ -13,14 +13,6 @@ class FlashTwigExtension extends AbstractExtension { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Returns a list of functions to add to the existing list. * From 6a2da5a261ab8e1bcbb52dbd267400e1a82f3b89 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:18:42 +0300 Subject: [PATCH 16/52] refactor(core): remove complexity from GlobalTwigExtension --- twig/GlobalVarsTwigExtension.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/twig/GlobalVarsTwigExtension.php b/twig/GlobalVarsTwigExtension.php index 9193a30..719f66a 100644 --- a/twig/GlobalVarsTwigExtension.php +++ b/twig/GlobalVarsTwigExtension.php @@ -15,14 +15,6 @@ class GlobalVarsTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Register Global variables in an extension */ @@ -30,7 +22,7 @@ public function getGlobals() : array { return [ 'PATH_PROJECT' => PATH['project'], - 'PHP_VERSION' => PHP_VERSION + 'PHP_VERSION' => PHP_VERSION, ]; } } From 4f5321ede87bf31c6f0533bdcf203c057e6040a9 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:18:54 +0300 Subject: [PATCH 17/52] refactor(core): remove complexity from StringsTwigExtension --- twig/StringsTwigExtension.php | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/twig/StringsTwigExtension.php b/twig/StringsTwigExtension.php index b3d191a..64b12c2 100644 --- a/twig/StringsTwigExtension.php +++ b/twig/StringsTwigExtension.php @@ -14,14 +14,6 @@ class StringsTwigExtension extends AbstractExtension { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Callback for twig. * @@ -30,23 +22,7 @@ public function __construct() public function getFunctions() : array { return [ - new \Twig\TwigFunction('strings', [$this, 'strings']), + new \Twig\TwigFunction('strings', 'strings'), ]; } - - /** - * Create a new stringable object from the given string. - * - * Initializes a Strings object and assigns both $string and $encoding properties - * the supplied values. $string is cast to a string prior to assignment. Throws - * an InvalidArgumentException if the first argument is an array or object - * without a __toString method. - * - * @param mixed $string Value to modify, after being cast to string. Default: '' - * @param mixed $encoding The character encoding. Default: UTF-8 - */ - function strings($string = '', $encoding = 'UTF-8'): Strings - { - return new Strings($string, $encoding); - } } From 5e43e505de41e45b06c3651f5741c33fc078df04 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:19:07 +0300 Subject: [PATCH 18/52] refactor(core): remove complexity from UrlTwigExtension --- twig/UrlTwigExtension.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/twig/UrlTwigExtension.php b/twig/UrlTwigExtension.php index d8295e1..cb16bd4 100644 --- a/twig/UrlTwigExtension.php +++ b/twig/UrlTwigExtension.php @@ -15,14 +15,6 @@ class UrlTwigExtension extends AbstractExtension { - /** - * Constructor - */ - public function __construct() - { - - } - /** * Callback for twig. * From e2ef1929c48ede7782a1fea36caf76610cfbbbef Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:19:31 +0300 Subject: [PATCH 19/52] refactor(core): update settings for extensions --- settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.yaml b/settings.yaml index 8f2dace..8f339f4 100644 --- a/settings.yaml +++ b/settings.yaml @@ -20,7 +20,7 @@ auto_reload: true cache: true debug: false charset: "UTF-8" -extensions: ['Cache', 'Entries', 'Emitter', 'I18n', 'Json', 'Yaml', 'Markdown', 'Filesystem', 'Csrf', 'GlobalVars', 'Url', 'Registry', 'Shortcode', 'Arrays', 'Flash', 'Media', 'Strings'] +extensions: ['I18n', 'Filesystem', 'Csrf', 'GlobalVars', 'Url', 'Strings', 'Arrays', 'Flash', 'Flextype', 'Filters'] # Twig plugin priority priority: 100 From 71ba1e4260c1dfbb7f60345fe2d9bf799fab5b5a Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:47:34 +0300 Subject: [PATCH 20/52] docs(readme): update docs for TWIG --- README.md | 480 +++++++----------------------------------------------- 1 file changed, 57 insertions(+), 423 deletions(-) diff --git a/README.md b/README.md index 09259ae..68e0056 100755 --- a/README.md +++ b/README.md @@ -6,6 +6,11 @@ Twig plugin to present Twig template engine for Flextype. +* [Dependencies](#dependencies) +* [Installation](#installation) +* [Introduction to Templating](#introduction-to-templating) +* [License](#license) + ## Dependencies The following dependencies need to be installed for Twig Plugin. @@ -20,468 +25,97 @@ The following dependencies need to be installed for Twig Plugin. 2. Create new folder `/project/plugins/twig` 3. Download Twig Plugin and unzip plugin content to the folder `/project/plugins/twig` -## Documentation - -### Twig Filters & Functions - -Twig already provides an extensive list of [filters, functions, and tags](https://twig.symfony.com/doc/2.x/), Flextype also provides a selection of useful additions to make the process of theming easier. - -#### Flextype Twig Filters - -Twig filters are applied to Twig variables by using the `|` character followed by the filter name. Parameters can be passed in just like Twig functions using parenthesis. - -##### shortcode - -Parse shortcode - -Usage: - -```twig -{{ '[b]Bold text[/b]'|shortcode }} -``` - -Result: - -**Bold text** - -##### markdown - -Parse markdown - -Usage: markdown - -```twig -{{ '**Bold text**'|markdown }} -``` - -Result: - -**Bold text** - -##### tr - -Translate text - -Usage: -```twig -{{ 'site_powered_by_flextype'|tr }} -``` - -Result: - -Build fast, flexible, easier to manage websites with -Flextype. - -Multiple filters can be chained. The output of one filter is applied to the next. - -Usage: -```twig -{{ '[b]Bold text[/b] *Italic text*'|shortcode|markdown }} -``` - -Result: - -**Bold text** *Italic text* - -#### Flextype Twig Functions - -Twig functions are called directly with any parameters being passed in via parenthesis. - -##### yaml_decode - -Decode valid yaml string into array - -Usage: -```twig -{{ yaml_decode('title: Hello World!').title }} -``` - -Result: -```twig -Hello World! -``` - -##### yaml_encode - -Encode array into valid yaml string - -Usage: -```twig -{{ yaml_encode({'title': 'Hello World!'})}} -``` - -Result: -```yaml -title: 'Hello World!' -``` - -##### json_decode - -Decode valid json string into array - -Usage: -```twig -{{ json_decode('{"title": "Hello World!"}').title }} -``` - -Result: -```twig -Hello World! -``` - -##### json_encode - -Encode array into valid json string - -Usage: -```twig -{{ json_encode({'title': 'Hello World!'})}} -``` - -Result: -```json -{"title": "Hello World!"} -``` - -##### tr or __ - -Translate string - -Usage: -```twig -{{ tr('site_powered_by_flextype') }} -{{ __('site_powered_by_flextype') }} -``` - -Result: - -Build fast, flexible, easier to manage websites with -Flextype. - -##### filesystem_list_contents - -List contents of a directory - -Usage: - -```twig -{% set media = filesystem_list_contents(PATH_UPLOADS ~ '/' ~ entry.id) %} -``` - -Result: - -array (media) - -##### filesystem_has - -Check whether a file exists - -Usage: -```twig -{% if (filesystem_has(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md')) %} - Show something... -{% endif %} -``` - -##### filesystem_read - -Read a file - -Usage: -```twig -{{ filesystem_read(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} -``` - -Result: - -``` - Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. -``` - -##### filesystem_ext - -Get file extension - -Usage: -```twig -{{ filesystem_ext(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} -``` - -Result: - -.md - -##### filesystem_basename +### Introduction to Templating -Get filename +Twig is a modern template engine for PHP. -Usage: +* **Fast**: Twig compiles templates down to plain optimized PHP code. The overhead compared to regular PHP code was reduced to the very minimum. +* **Secure**: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design. +* **Flexible**: Twig is powered by a flexible lexer and parser. This allows the developer to define its own custom tags and filters, and create its own DSL. -```twig -{{ filesystem_basename(PATH_PROJECT ~ '/media/' ~ entry.id ~ '/about.md') }} -``` +Twig templates are HTML files that are sprinkled with bits of Twig code. When Twig loads a template, the first thing it will do is separate the raw HTML code from the Twig code. The raw HTML code will be output to the browser without any tampering. -Result: +All Twig code follows a basic pattern that separates it from the surrounding HTML. At its outer edges you will find left and right curly braces {{ and }}, coupled with another character that signifies what type of Twig code it is. These sets of characters are called “delimiters”. -entry +There are three types of delimiters that Twig looks out for: -##### path_for +`{#` – Comments +`{%` – Tags +`{{` – Print statements -Returns the URL for a given route. +#### Comments -Usage: -```twig -{{ path_for('profile') }} -``` +Twig comments are wrapped in {# and #} delimiters. You can use them to leave little notes for yourself in the code. -##### base_url +They are similar to HTML comments in that they won’t show up as rendered text in the browser. The difference is that they will never make it into the HTML source in the first place. -Returns the Uri object's base URL. + +{# This won’t! #} -Usage: -```twig -{{ base_url() }} -``` +#### Tags -##### url +Twig tags are wrapped in {% and %} delimiters, and are used to define the logic of your template, such as conditionals, loops, variable definitions, template includes, and other things. -Returns the Uri object's App URL. +The syntax within the {% and %} delimiters varies from tag to tag, but they will always start with the same thing: the name of the tag. -Usage: -```twig -{{ url() }} -``` +#### Print Statements -##### is_current_path +To output additional HTML code dynamically, use a print statement. They are wrapped in {{ and }} delimiters, and you can put just about anything inside them, as long as it can be treated as a string. -Returns true is the provided route name and parameters are valid for the current path. -```twig -{% if is_current_path('profile') %} - Show profile page -{% endif %} ``` - -##### current_path - -Renders the current path, with or without the query string. -```twig -{{ current_path() }} +

Hi, {{ entry.title }}

``` -### Twig Variables - -When you are working with twig templates, for e.g. when you designing a theme, Twig Plugin gives you access to all sorts of objects and variables available in Flextype within your Twig templates. The Twig templating framework provides powerful ways to read and manipulate these objects and variables. - -#### Core Objects +Don’t place a print statement (or any other Twig code) within another print statement. [See Combining Strings to learn how to combine strings with other expressions](#combining-strings). -There are several **core objects** that are available to a Twig template, and each object has a set of **variables** and **functions**. +#### Auto-escaping -#### registry +Most of the time, print statements will automatically HTML-encode the content before actually outputting it (called auto-escaping), which helps defend against cross-site scripting (XSS) vulnerabilities. -Registry stored all flextype, themes and plugins settings.
-You can access Flextype registry via the registry object. +For example, let’s say you have a search results page, where the search query is defined by a q query string parameter, and in the event that there are no results, you want to output a message to the user that includes the query: -Usage: - -```twig -{{ registry.flextype.theme }} {# returns the currently configured theme #} ``` +{% set query = request.getQueryParam().q %} -##### entry - -Because Flextype is built using the structure defined in the `/project/entries/` folder, each entry is represented by a entry object. - -The entry object is probably the most important object you will work with as it contains all the information about the current page you are currently on. +{% set entries = flextype.entries.fetch('blog', {'collection': true}) + .where('title', 'contains', query) + .all() %} -Usage: - -```twig -{{ entry.title }} {# returns the current entry title #} -``` - -##### entries - -Fetch single entry - -Usage: - -```twig -{% set about_entry = entries.fetch('about') %} -``` - -Fetch collection of entries - -Usage: - -```twig -{% set posts = entries.fetch('blog', {'collection': true}) %} -``` - -##### emitter - -Emitting events - -Usage: -```twig -{% do emitter.emit('onThemeHeader') %} -``` - -Emitting events in batches - -Usage: - -```twig -{% do emitter.emitBatch({'onThemeHeader', 'onSomeOtherEvent'}) %} -``` - -##### arr - -Contains methods that can be useful when working with arrays. - -Sorts a multi-dimensional array by a certain column - -Usage: - -```twig -{% set new_array = arr.sort(old.array, 'title') %} -``` - -Sets an array value using "dot notation". - -Usage: - -```twig -{% set entry = arr.set(entry, 'title', 'New Title') %} -``` - -Return value from array using "dot notation". -If the key does not exist in the array, the default value will be returned instead. - -Usage: - -```twig -{{ arr.get(entry, 'title') }} -``` - -Delete an array value using "dot notation". - -Usage: - -```twig -{% set entry = arr.delete(entry, 'title') %} -``` - -Checks if the given dot-notated key exists in the array. - -Usage: - -```twig -{% if arr.keyExists(entry, 'title') %} - Do something... -{% endif %} -``` - -Returns a random value from an array. - -Usage: - -```twig -{{ arr.random(['php', 'js', 'css', 'html']) }} -``` - -Returns TRUE if the array is associative and FALSE if not. - -Usage: - -```twig -{% if arr.isAssoc(entry) %} - Do something... +{% if entries %} +

Search Results

+
    + {% for entry in entries %} +
  • {{ entry.id }}
  • + {% endfor %} +
+{% else %} +

Sorry, no results for {{ query }} were found.

{% endif %} ``` -Returns TRUE if the array is associative and FALSE if not. - -Usage: - -```twig -{% set array1 = {'name': 'john', 'mood': 'happy', 'food': 'bacon'} %} -{% set array2 = {'name': 'jack', 'food': 'tacos', 'drink': 'beer'} %} -{% set array3 = arr.overwrite(array1, array2) %} -``` - -Converts an array to a JSON string - -Usage: - -```twig -{{ arr.json(entry) }} -``` - -Returns the first element of an array - -Usage: - -```twig -{{ arr.first(entry) }} -``` - -Returns the last element of an array - -Usage: - -```twig -{{ arr.last(entry) }} -``` - -Converts an array to a JSON string - -Usage: - -```twig -{{ arr.toJson(entry) }} -``` - -Create an new Array from JSON string. +If it weren’t for auto-escaping, a search for would result in this HTML: -Usage: +

Sorry, no results for .

+Which would cause JavaScript to execute on the page, even though it wasn’t part of the original Twig template. But thanks to auto-escaping, you’d actually end up with this HTML: -```twig -{% set array = arr.createFromJson($string) %} -``` - -Create an new Array object via string. +

Sorry, no results for <script>alert('Danger!!!')</script>.

+There are two cases where print statements will output content directly, without auto-escaping it first: -Usage: +When the content is deemed safe by the last tag or function that was called within the print statement (such as the markdown filter). +When you explicitly mark the content as safe using a raw (opens new window) filter. -```twig -{% set array = arr.createFromString('cat, dog, bird', ',') %} -``` +#### Manual escaping -Counts all elements in an array. +There are times where you may need to work with both trusted and untrusted content together. For example, let’s say you want to output user-supplied content as Markdown, but you want to ensure they haven’t put anything nefarious in there first. -Usage: +To do that, you could explicitly encode all HTML within the user-supplied content using the escape (opens new window) filter, before passing it to the markdown filter: -```twig -{{ arr.size(array) }} ``` - -Return an array with elements in reverse order. - -Usage: - -```twig -{% set new_array = arr.reverse(old_array) %} +{# Escape any HTML in the Body field, then format as Markdown #} +{{ entry.content|escape|markdown }} ``` -#### Global Variables - -```twig -{{ PATH_PROJECT }} {# Returns the path to the project directory (without trailing slash). #} -{{ PATH_LOGS }} {# Returns the path to the logs directory (without trailing slash). #} -{{ PATH_CONFIG }} {# Returns the path to the default config directory (without trailing slash). #} -{{ PATH_CACHE }} {# Returns the path to the cache directory (without trailing slash). #} -{{ PHP_VERSION }} {# Returns the php version #} -``` +#### Combining Strings ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) From fd8dca0c7339994464d2f6421184f15081f99edb Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 13:50:06 +0300 Subject: [PATCH 21/52] docs(readme): update docs for TWIG --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 68e0056..ae807f4 100755 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ All Twig code follows a basic pattern that separates it from the surrounding HTM There are three types of delimiters that Twig looks out for: -`{#` – Comments -`{%` – Tags -`{{` – Print statements +`{#` – Comments +`{%` – Tags +`{{` – Print statements #### Comments @@ -78,8 +78,8 @@ For example, let’s say you have a search results page, where the search query {% set query = request.getQueryParam().q %} {% set entries = flextype.entries.fetch('blog', {'collection': true}) - .where('title', 'contains', query) - .all() %} + .where('title', 'contains', query) + .all() %} {% if entries %}

Search Results

@@ -95,10 +95,16 @@ For example, let’s say you have a search results page, where the search query If it weren’t for auto-escaping, a search for would result in this HTML: +```

Sorry, no results for .

+``` + Which would cause JavaScript to execute on the page, even though it wasn’t part of the original Twig template. But thanks to auto-escaping, you’d actually end up with this HTML: +```

Sorry, no results for <script>alert('Danger!!!')</script>.

+``` + There are two cases where print statements will output content directly, without auto-escaping it first: When the content is deemed safe by the last tag or function that was called within the print statement (such as the markdown filter). @@ -111,7 +117,7 @@ There are times where you may need to work with both trusted and untrusted conte To do that, you could explicitly encode all HTML within the user-supplied content using the escape (opens new window) filter, before passing it to the markdown filter: ``` -{# Escape any HTML in the Body field, then format as Markdown #} +{# Escape any HTML in the Content field, then format as Markdown #} {{ entry.content|escape|markdown }} ``` From d5597300a8374e0914bcb9593ac0ac690ac31824 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 14:04:21 +0300 Subject: [PATCH 22/52] docs(readme): update docs for TWIG --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae807f4..0cadfbf 100755 --- a/README.md +++ b/README.md @@ -107,8 +107,8 @@ Which would cause JavaScript to execute on the page, even though it wasn’t par There are two cases where print statements will output content directly, without auto-escaping it first: -When the content is deemed safe by the last tag or function that was called within the print statement (such as the markdown filter). -When you explicitly mark the content as safe using a raw (opens new window) filter. +* When the content is deemed safe by the last tag or function that was called within the print statement (such as the markdown filter). +* When you explicitly mark the content as safe using a raw filter. #### Manual escaping @@ -121,6 +121,7 @@ To do that, you could explicitly encode all HTML within the user-supplied conten {{ entry.content|escape|markdown }} ``` + #### Combining Strings ## LICENSE From 25bd0050cc7b84a427d3d054b8ed7557b4bc3d50 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 14:08:01 +0300 Subject: [PATCH 23/52] docs(readme): update docs for TWIG --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0cadfbf..1f0cb56 100755 --- a/README.md +++ b/README.md @@ -39,26 +39,28 @@ All Twig code follows a basic pattern that separates it from the surrounding HTM There are three types of delimiters that Twig looks out for: -`{#` – Comments -`{%` – Tags -`{{` – Print statements +`{#` – [Comments](#comments) +`{%` – [Tags](#tags) +`{{` – [Print statements](#print-statements) -#### Comments +#### Comments Twig comments are wrapped in {# and #} delimiters. You can use them to leave little notes for yourself in the code. They are similar to HTML comments in that they won’t show up as rendered text in the browser. The difference is that they will never make it into the HTML source in the first place. +``` {# This won’t! #} +``` -#### Tags +#### Tags Twig tags are wrapped in {% and %} delimiters, and are used to define the logic of your template, such as conditionals, loops, variable definitions, template includes, and other things. The syntax within the {% and %} delimiters varies from tag to tag, but they will always start with the same thing: the name of the tag. -#### Print Statements +#### Print Statements To output additional HTML code dynamically, use a print statement. They are wrapped in {{ and }} delimiters, and you can put just about anything inside them, as long as it can be treated as a string. From 1bf4e7b666760de0a29a7cc52661d036dd115238 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 14:08:25 +0300 Subject: [PATCH 24/52] docs(readme): update docs for TWIG --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1f0cb56..b976e55 100755 --- a/README.md +++ b/README.md @@ -39,9 +39,9 @@ All Twig code follows a basic pattern that separates it from the surrounding HTM There are three types of delimiters that Twig looks out for: -`{#` – [Comments](#comments) -`{%` – [Tags](#tags) -`{{` – [Print statements](#print-statements) +`{#` – [Comments](#comments) +`{%` – [Tags](#tags) +`{{` – [Print statements](#print-statements) #### Comments From c0e09e912345111d16798a39c3488773fec6f461 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 14:35:56 +0300 Subject: [PATCH 25/52] docs(readme): update docs for TWIG --- README.md | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b976e55..3b3bbc1 100755 --- a/README.md +++ b/README.md @@ -8,7 +8,9 @@ Twig plugin to present Twig template engine for Flextype. * [Dependencies](#dependencies) * [Installation](#installation) -* [Introduction to Templating](#introduction-to-templating) +* [Global Variables](#global-variables) +* [Functions](#functions) +* [Filters](#filters) * [License](#license) ## Dependencies @@ -25,7 +27,7 @@ The following dependencies need to be installed for Twig Plugin. 2. Create new folder `/project/plugins/twig` 3. Download Twig Plugin and unzip plugin content to the folder `/project/plugins/twig` -### Introduction to Templating +### Introduction Twig is a modern template engine for PHP. @@ -70,7 +72,7 @@ To output additional HTML code dynamically, use a print statement. They are wrap Don’t place a print statement (or any other Twig code) within another print statement. [See Combining Strings to learn how to combine strings with other expressions](#combining-strings). -#### Auto-escaping +#### Auto-escaping Most of the time, print statements will automatically HTML-encode the content before actually outputting it (called auto-escaping), which helps defend against cross-site scripting (XSS) vulnerabilities. @@ -112,7 +114,7 @@ There are two cases where print statements will output content directly, without * When the content is deemed safe by the last tag or function that was called within the print statement (such as the markdown filter). * When you explicitly mark the content as safe using a raw filter. -#### Manual escaping +#### Manual escaping There are times where you may need to work with both trusted and untrusted content together. For example, let’s say you want to output user-supplied content as Markdown, but you want to ensure they haven’t put anything nefarious in there first. @@ -123,8 +125,37 @@ To do that, you could explicitly encode all HTML within the user-supplied conten {{ entry.content|escape|markdown }} ``` +#### Resources -#### Combining Strings +* [Official Twig Documentation](http://twig.sensiolabs.org/documentation) +* [Twig for Template Designers](http://twig.sensiolabs.org/doc/templates.html) +* [Twig for Developers](http://twig.sensiolabs.org/doc/api.html) +* [6 Minute Video Introduction to Twig](http://www.dev-metal.com/6min-video-introduction-twig-php-templating-engine/) +* [Introduction to Twig](http://www.slideshare.net/markstory/introduction-to-twig) + +### Global Variables + +The following Flextype Twig Global variables are available in Flextype Twig Templates: + +| Variable | Description | +|---|---| +| _self | The current template name. | +| _context | The currently-defined variables. | +| _charset | The current charset. | +| PATH_PROJECT | Project path (without trailing slash).. | +| PHP_VERSION | PHP Version. | +| flextype | Flextype object. | +| filesystem | Filesystem object. | + +### Functions + +The following Flextype Twig Functions are available in Flextype Twig Templates: + +| Variable | Description | +|---|---| +| arrays | Returns a new arrsys object from the given elements. | +| strings | Returns a new strings object from the given string. | +| url | Returns application URL. | ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) From e986e3c29bfa1d407a5b00531bb0845ae402d308 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 14:37:34 +0300 Subject: [PATCH 26/52] docs(readme): update docs for TWIG --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3b3bbc1..6e47da8 100755 --- a/README.md +++ b/README.md @@ -125,7 +125,7 @@ To do that, you could explicitly encode all HTML within the user-supplied conten {{ entry.content|escape|markdown }} ``` -#### Resources +#### Resources * [Official Twig Documentation](http://twig.sensiolabs.org/documentation) * [Twig for Template Designers](http://twig.sensiolabs.org/doc/templates.html) @@ -133,7 +133,7 @@ To do that, you could explicitly encode all HTML within the user-supplied conten * [6 Minute Video Introduction to Twig](http://www.dev-metal.com/6min-video-introduction-twig-php-templating-engine/) * [Introduction to Twig](http://www.slideshare.net/markstory/introduction-to-twig) -### Global Variables +### Global Variables The following Flextype Twig Global variables are available in Flextype Twig Templates: @@ -147,7 +147,7 @@ The following Flextype Twig Global variables are available in Flextype Twig Temp | flextype | Flextype object. | | filesystem | Filesystem object. | -### Functions +### Functions The following Flextype Twig Functions are available in Flextype Twig Templates: From d0ba566b1f50634a3c5756a494f70bd39d6d38e2 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:56:42 +0300 Subject: [PATCH 27/52] refactor(core): remove GlobalVarsTwigExtension --- twig/GlobalVarsTwigExtension.php | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 twig/GlobalVarsTwigExtension.php diff --git a/twig/GlobalVarsTwigExtension.php b/twig/GlobalVarsTwigExtension.php deleted file mode 100644 index 719f66a..0000000 --- a/twig/GlobalVarsTwigExtension.php +++ /dev/null @@ -1,28 +0,0 @@ - PATH['project'], - 'PHP_VERSION' => PHP_VERSION, - ]; - } -} From e52e6b8ac9fac37176b06c5864559e62668fbb33 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:56:56 +0300 Subject: [PATCH 28/52] refactor(core): add ConstantsTwigExtension --- twig/ConstantsTwigExtension.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 twig/ConstantsTwigExtension.php diff --git a/twig/ConstantsTwigExtension.php b/twig/ConstantsTwigExtension.php new file mode 100644 index 0000000..92d720c --- /dev/null +++ b/twig/ConstantsTwigExtension.php @@ -0,0 +1,28 @@ + PATH['project'], + 'PHP_VERSION' => PHP_VERSION, + ]; + } +} From 1eb2189a563a15b768f628c5413891be608d34f6 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:57:32 +0300 Subject: [PATCH 29/52] refactor(core): updates for FilesystemTwigExtension --- twig/FilesystemTwigExtension.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/twig/FilesystemTwigExtension.php b/twig/FilesystemTwigExtension.php index 8db5a5f..db5362a 100644 --- a/twig/FilesystemTwigExtension.php +++ b/twig/FilesystemTwigExtension.php @@ -14,15 +14,17 @@ use Atomastic\Macroable\Macroable; use Symfony\Component\Finder\Finder; -class FilesystemTwigExtension extends AbstractExtension implements GlobalsInterface +class FilesystemTwigExtension extends AbstractExtension { /** - * Register Global variables in an extension + * Callback for twig. + * + * @return array */ - public function getGlobals() : array + public function getFunctions() : array { return [ - 'filesystem' => new FilesystemTwig(), + new \Twig\TwigFunction('filesystem', function() { return new FilesystemTwig(); }), ]; } } From a3020018ffb2aba024eaf86d90ed855955159b57 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:57:45 +0300 Subject: [PATCH 30/52] refactor(core): updates for FlextypeTwigExtension --- twig/FlextypeTwigExtension.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php index 5c60e3c..8be9605 100644 --- a/twig/FlextypeTwigExtension.php +++ b/twig/FlextypeTwigExtension.php @@ -94,7 +94,7 @@ class FlextypeMediaTwig /** * Create a Media Files instance. */ - public function files(): MediaFiles + public function files(): FlextypeMediaTwigFiles { return new FlextypeMediaTwigFiles(); } @@ -102,7 +102,7 @@ public function files(): MediaFiles /** * Create a Media Files instance. */ - public function folders(): MediaFolders + public function folders(): FlextypeMediaTwigFolders { return new FlextypeMediaTwigFolders(); } @@ -115,7 +115,7 @@ class FlextypeMediaTwigFiles /** * Create a Media Files Meta instance. */ - public function meta(): MediaTwigFilesMeta + public function meta(): FlextypeMediaTwigFilesMeta { return new FlextypeMediaTwigFilesMeta(); } @@ -190,7 +190,7 @@ class FlextypeMediaTwigFolders /** * Create a Media Folders Meta instance. */ - public function meta(): MediaTwigFoldersMeta + public function meta(): FlextypeMediaTwigFoldersMeta { return new FlextypeMediaTwigFoldersMeta(); } From 225156899d822b582d2435b5d1eee06fa9dc8a8e Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:57:59 +0300 Subject: [PATCH 31/52] refactor(core): update settings for extensions --- settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.yaml b/settings.yaml index 8f339f4..ab911e4 100644 --- a/settings.yaml +++ b/settings.yaml @@ -20,7 +20,7 @@ auto_reload: true cache: true debug: false charset: "UTF-8" -extensions: ['I18n', 'Filesystem', 'Csrf', 'GlobalVars', 'Url', 'Strings', 'Arrays', 'Flash', 'Flextype', 'Filters'] +extensions: ['I18n', 'Filesystem', 'Csrf', 'Constants', 'Url', 'Strings', 'Arrays', 'Flash', 'Flextype', 'Filters'] # Twig plugin priority priority: 100 From 7da468549de027ae815f6dd39aac53afb2f81985 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 15:58:11 +0300 Subject: [PATCH 32/52] docs(readme): update docs for TWIG --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6e47da8..c3f0d95 100755 --- a/README.md +++ b/README.md @@ -142,10 +142,29 @@ The following Flextype Twig Global variables are available in Flextype Twig Temp | _self | The current template name. | | _context | The currently-defined variables. | | _charset | The current charset. | -| PATH_PROJECT | Project path (without trailing slash).. | +| PATH_PROJECT | Project path (without trailing slash). | | PHP_VERSION | PHP Version. | | flextype | Flextype object. | -| filesystem | Filesystem object. | + +#### PATH_PROJECT + +Project path (without trailing slash). + +``` +{{ PATH_PROJECT }} +``` + +#### PATH_PROJECT + +Project path (without trailing slash). + +``` +{{ PHP_VERSION }} +``` + +### flextype + +PHP Version. ### Functions @@ -156,6 +175,7 @@ The following Flextype Twig Functions are available in Flextype Twig Templates: | arrays | Returns a new arrsys object from the given elements. | | strings | Returns a new strings object from the given string. | | url | Returns application URL. | +| filesystem | Filesystem function. | ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) From f90d6d35516589dcdf6c9a84f7cf7de6dcf9488b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 16:05:39 +0300 Subject: [PATCH 33/52] docs(readme): update docs for TWIG --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c3f0d95..708a385 100755 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ The following Flextype Twig Global variables are available in Flextype Twig Temp | _charset | The current charset. | | PATH_PROJECT | Project path (without trailing slash). | | PHP_VERSION | PHP Version. | -| flextype | Flextype object. | +| flextype | Retursns Flextype object. | #### PATH_PROJECT @@ -162,9 +162,14 @@ Project path (without trailing slash). {{ PHP_VERSION }} ``` -### flextype +#### flextype + +Returns Flextype object, which provides access points to various helper functions and objects for templates. + +| Twig Code | Links | +|---|---| +| {{ flextype.entries.fetch() }} | [Documentation](https://docs.flextype.org/en/core/entries#methods-fetch) | -PHP Version. ### Functions From 630aa36b79c5c5b059ed4ced77d2cf5f653bc26b Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 16:06:02 +0300 Subject: [PATCH 34/52] docs(readme): update docs for TWIG --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 708a385..ef5b98c 100755 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ Returns Flextype object, which provides access points to various helper function | Twig Code | Links | |---|---| -| {{ flextype.entries.fetch() }} | [Documentation](https://docs.flextype.org/en/core/entries#methods-fetch) | +| `{{ flextype.entries.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/entries#methods-fetch) | ### Functions From f9909423a62fcac472d7da888597a621fffaa74d Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:01:47 +0300 Subject: [PATCH 35/52] docs(readme): update docs for TWIG --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef5b98c..a9ab1df 100755 --- a/README.md +++ b/README.md @@ -154,9 +154,9 @@ Project path (without trailing slash). {{ PATH_PROJECT }} ``` -#### PATH_PROJECT +#### PHP_VERSION -Project path (without trailing slash). +PHP Version. ``` {{ PHP_VERSION }} @@ -169,7 +169,16 @@ Returns Flextype object, which provides access points to various helper function | Twig Code | Links | |---|---| | `{{ flextype.entries.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/entries#methods-fetch) | - +| `{{ flextype.media.files.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-files-fetch) | +| `{{ flextype.media.files.meta.getFileMetaLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | +| `{{ flextype.media.folders.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-fetch) | +| `{{ flextype.media.folders.getDirectoryLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | +| `{{ flextype.media.folders.getDirMetaLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | +| `{{ flextype.registry }}` | [Documentation](https://docs.flextype.org/en/core/registry) | +| `{{ flextype.parsers }}` | [Documentation](https://docs.flextype.org/en/core/parsers) | +| `{{ flextype.serializers }}` | [Documentation](https://docs.flextype.org/en/core/serializers) | +| `{{ flextype.cache }}` | [Documentation](https://www.phpfastcache.com) | +| `{{ flextype.emitter }}` | [Documentation](https://event.thephpleague.com/2.0/) | ### Functions From 8494591c40345b214683439f01399e0a708302a9 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:05:54 +0300 Subject: [PATCH 36/52] docs(readme): update docs for TWIG --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a9ab1df..046c659 100755 --- a/README.md +++ b/README.md @@ -166,19 +166,19 @@ PHP Version. Returns Flextype object, which provides access points to various helper functions and objects for templates. -| Twig Code | Links | +| Objects | Available Methods | |---|---| -| `{{ flextype.entries.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/entries#methods-fetch) | -| `{{ flextype.media.files.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-files-fetch) | -| `{{ flextype.media.files.meta.getFileMetaLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | -| `{{ flextype.media.folders.fetch() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-fetch) | -| `{{ flextype.media.folders.getDirectoryLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | -| `{{ flextype.media.folders.getDirMetaLocation() }}` | [Documentation](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | -| `{{ flextype.registry }}` | [Documentation](https://docs.flextype.org/en/core/registry) | -| `{{ flextype.parsers }}` | [Documentation](https://docs.flextype.org/en/core/parsers) | -| `{{ flextype.serializers }}` | [Documentation](https://docs.flextype.org/en/core/serializers) | -| `{{ flextype.cache }}` | [Documentation](https://www.phpfastcache.com) | -| `{{ flextype.emitter }}` | [Documentation](https://event.thephpleague.com/2.0/) | +| `flextype.entries` | [fetch()](https://docs.flextype.org/en/core/entries#methods-fetch) +| `flextype.media.files` | [fetch()](https://docs.flextype.org/en/core/media#methods-files-fetch) | +| `flextype.media.files.meta` | [getFileMetaLocation()](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | +| `flextype.media.folders` | [fetch()](https://docs.flextype.org/en/core/media#methods-folders-fetch) | +| `flextype.media.folders` | [getDirectoryLocation()](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | +| `flextype.media.folders` | [getDirMetaLocation()](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | +| `{{ flextype.registry }}` | [all](https://docs.flextype.org/en/core/registry) | +| `{{ flextype.parsers }}` | [all](https://docs.flextype.org/en/core/parsers) | +| `{{ flextype.serializers }}` | [all](https://docs.flextype.org/en/core/serializers) | +| `{{ flextype.cache }}` | [all](https://www.phpfastcache.com) | +| `{{ flextype.emitter }}` | [all](https://event.thephpleague.com/2.0/) | ### Functions From caa8e394b03faf9169c1a74d8c9eb6c80a8e72ca Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:07:34 +0300 Subject: [PATCH 37/52] docs(readme): update docs for TWIG --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 046c659..0313a98 100755 --- a/README.md +++ b/README.md @@ -171,14 +171,13 @@ Returns Flextype object, which provides access points to various helper function | `flextype.entries` | [fetch()](https://docs.flextype.org/en/core/entries#methods-fetch) | `flextype.media.files` | [fetch()](https://docs.flextype.org/en/core/media#methods-files-fetch) | | `flextype.media.files.meta` | [getFileMetaLocation()](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | -| `flextype.media.folders` | [fetch()](https://docs.flextype.org/en/core/media#methods-folders-fetch) | -| `flextype.media.folders` | [getDirectoryLocation()](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | -| `flextype.media.folders` | [getDirMetaLocation()](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | -| `{{ flextype.registry }}` | [all](https://docs.flextype.org/en/core/registry) | -| `{{ flextype.parsers }}` | [all](https://docs.flextype.org/en/core/parsers) | -| `{{ flextype.serializers }}` | [all](https://docs.flextype.org/en/core/serializers) | -| `{{ flextype.cache }}` | [all](https://www.phpfastcache.com) | -| `{{ flextype.emitter }}` | [all](https://event.thephpleague.com/2.0/) | +| `flextype.media.folders` | [fetch()](https://docs.flextype.org/en/core/media#methods-folders-fetch) [getDirectoryLocation()](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | +| `flextype.media.folders.meta` | [getDirMetaLocation()](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | +| `{{ flextype.registry }}` | [all methods available](https://docs.flextype.org/en/core/registry) | +| `{{ flextype.parsers }}` | [all methods available](https://docs.flextype.org/en/core/parsers) | +| `{{ flextype.serializers }}` | [all methods available](https://docs.flextype.org/en/core/serializers) | +| `{{ flextype.cache }}` | [all methods available](https://www.phpfastcache.com) | +| `{{ flextype.emitter }}` | [all methods available](https://event.thephpleague.com/2.0/) | ### Functions From f8c8f1a40586b139d4fc8c578608c72b91393b15 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:08:02 +0300 Subject: [PATCH 38/52] docs(readme): update docs for TWIG --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0313a98..63bd7c9 100755 --- a/README.md +++ b/README.md @@ -173,11 +173,11 @@ Returns Flextype object, which provides access points to various helper function | `flextype.media.files.meta` | [getFileMetaLocation()](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | | `flextype.media.folders` | [fetch()](https://docs.flextype.org/en/core/media#methods-folders-fetch) [getDirectoryLocation()](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | | `flextype.media.folders.meta` | [getDirMetaLocation()](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | -| `{{ flextype.registry }}` | [all methods available](https://docs.flextype.org/en/core/registry) | -| `{{ flextype.parsers }}` | [all methods available](https://docs.flextype.org/en/core/parsers) | -| `{{ flextype.serializers }}` | [all methods available](https://docs.flextype.org/en/core/serializers) | -| `{{ flextype.cache }}` | [all methods available](https://www.phpfastcache.com) | -| `{{ flextype.emitter }}` | [all methods available](https://event.thephpleague.com/2.0/) | +| `flextype.registry` | [all methods available](https://docs.flextype.org/en/core/registry) | +| `flextype.parsers` | [all methods available](https://docs.flextype.org/en/core/parsers) | +| `flextype.serializers }}` | [all methods available](https://docs.flextype.org/en/core/serializers) | +| `flextype.cache` | [all methods available](https://www.phpfastcache.com) | +| `flextype.emitter` | [all methods available](https://event.thephpleague.com/2.0/) | ### Functions From d74f330d5901d780f5e3df68de48ecf104476f2f Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:10:16 +0300 Subject: [PATCH 39/52] docs(readme): update docs for TWIG --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63bd7c9..e70cca2 100755 --- a/README.md +++ b/README.md @@ -169,13 +169,13 @@ Returns Flextype object, which provides access points to various helper function | Objects | Available Methods | |---|---| | `flextype.entries` | [fetch()](https://docs.flextype.org/en/core/entries#methods-fetch) -| `flextype.media.files` | [fetch()](https://docs.flextype.org/en/core/media#methods-files-fetch) | +| `flextype.media.files` | [fetch()](https://docs.flextype.org/en/core/media#methods-files-fetch) [has()](https://docs.flextype.org/en/core/media#methods-files-has) | | `flextype.media.files.meta` | [getFileMetaLocation()](https://docs.flextype.org/en/core/media#methods-files-meta-getFileMetaLocation) | | `flextype.media.folders` | [fetch()](https://docs.flextype.org/en/core/media#methods-folders-fetch) [getDirectoryLocation()](https://docs.flextype.org/en/core/media#methods-folders-getDirLocation) | | `flextype.media.folders.meta` | [getDirMetaLocation()](https://docs.flextype.org/en/core/media#methods-folders-meta-getDirMetaLocation) | | `flextype.registry` | [all methods available](https://docs.flextype.org/en/core/registry) | | `flextype.parsers` | [all methods available](https://docs.flextype.org/en/core/parsers) | -| `flextype.serializers }}` | [all methods available](https://docs.flextype.org/en/core/serializers) | +| `flextype.serializers` | [all methods available](https://docs.flextype.org/en/core/serializers) | | `flextype.cache` | [all methods available](https://www.phpfastcache.com) | | `flextype.emitter` | [all methods available](https://event.thephpleague.com/2.0/) | From ce365aeb1e9d2d99b01eb8e954f648f87beba87c Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 17:15:34 +0300 Subject: [PATCH 40/52] docs(readme): update docs for TWIG --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e70cca2..efbf781 100755 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ The following Flextype Twig Global variables are available in Flextype Twig Temp | _charset | The current charset. | | PATH_PROJECT | Project path (without trailing slash). | | PHP_VERSION | PHP Version. | -| flextype | Retursns Flextype object. | +| flextype | Returns Flextype object. | #### PATH_PROJECT @@ -185,10 +185,10 @@ The following Flextype Twig Functions are available in Flextype Twig Templates: | Variable | Description | |---|---| -| arrays | Returns a new arrsys object from the given elements. | +| arrays | Returns a new arrays object from the given elements. | | strings | Returns a new strings object from the given string. | +| filesystem | Returns a new filesystem object from the given string. | | url | Returns application URL. | -| filesystem | Filesystem function. | ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) From d54f56c1d572d282b723fa08e1d92c27c123d9ff Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 20:56:04 +0300 Subject: [PATCH 41/52] refactor(core): updates for FlextypeTwigExtension --- twig/FlextypeTwigExtension.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php index 8be9605..ef0f29c 100644 --- a/twig/FlextypeTwigExtension.php +++ b/twig/FlextypeTwigExtension.php @@ -65,6 +65,11 @@ public function emitter() { return flextype('emitter'); } + + public function slugify() + { + return flextype('slugify'); + } } class FlextypeEntriesTwig From 4df134e47a1e88cdeb0354978518499e7713a123 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 21:30:13 +0300 Subject: [PATCH 42/52] refactor(core): updates for FiltersTwigExtension --- twig/FiltersTwigExtension.php | 1 + 1 file changed, 1 insertion(+) diff --git a/twig/FiltersTwigExtension.php b/twig/FiltersTwigExtension.php index 2779875..121fcec 100644 --- a/twig/FiltersTwigExtension.php +++ b/twig/FiltersTwigExtension.php @@ -22,6 +22,7 @@ public function getFilters() : array { return [ new \Twig\TwigFilter('shortcode', [$this, 'shortcode']), + new \Twig\TwigFilter('markdown', [$this, 'markdown']), ]; } From 1f3f91ec17b8be06b7ba2567539b00a2c0ff0bc3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 21:33:25 +0300 Subject: [PATCH 43/52] refactor(core): make FlashTwigExtension part of FlextypeTwigExtension --- settings.yaml | 2 +- twig/FlashTwigExtension.php | 42 ---------------------------------- twig/FlextypeTwigExtension.php | 5 ++++ 3 files changed, 6 insertions(+), 43 deletions(-) delete mode 100644 twig/FlashTwigExtension.php diff --git a/settings.yaml b/settings.yaml index ab911e4..7ef563c 100644 --- a/settings.yaml +++ b/settings.yaml @@ -20,7 +20,7 @@ auto_reload: true cache: true debug: false charset: "UTF-8" -extensions: ['I18n', 'Filesystem', 'Csrf', 'Constants', 'Url', 'Strings', 'Arrays', 'Flash', 'Flextype', 'Filters'] +extensions: ['I18n', 'Filesystem', 'Csrf', 'Constants', 'Url', 'Strings', 'Arrays', 'Flextype', 'Filters'] # Twig plugin priority priority: 100 diff --git a/twig/FlashTwigExtension.php b/twig/FlashTwigExtension.php deleted file mode 100644 index eaac0d0..0000000 --- a/twig/FlashTwigExtension.php +++ /dev/null @@ -1,42 +0,0 @@ -getMessage($key); - } - - return flextype('flash')->getMessages(); - } -} diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php index ef0f29c..13b8712 100644 --- a/twig/FlextypeTwigExtension.php +++ b/twig/FlextypeTwigExtension.php @@ -70,6 +70,11 @@ public function slugify() { return flextype('slugify'); } + + public function flash() + { + return flextype('flash'); + } } class FlextypeEntriesTwig From b999fae4844c06e5c61c2b3f6a626c0113954186 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 26 Dec 2020 21:47:14 +0300 Subject: [PATCH 44/52] refactor(core): make FlashTwigExtension part of FlextypeTwigExtension --- dependencies.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.php b/dependencies.php index 76d9bf8..6cfd1e3 100644 --- a/dependencies.php +++ b/dependencies.php @@ -61,7 +61,7 @@ if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twig_extension_class_name . '.php')) { - if ($twig_extension == 'Flash') { + if ($twig_extension == 'Flextype') { flextype()->container()['flash'] = static function () { return new Messages(); }; From 60c089ab975ff7764db92da2e8fd8e8e9fe28173 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 11:19:47 +0300 Subject: [PATCH 45/52] refactor(core): updates for FlextypeTwigExtension --- twig/FlextypeTwigExtension.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php index 13b8712..c59d5eb 100644 --- a/twig/FlextypeTwigExtension.php +++ b/twig/FlextypeTwigExtension.php @@ -33,7 +33,7 @@ class FlextypeTwig public function entries() { - return new FlextypeEntriesTwig(); + return new EntriesTwig(); } public function media() @@ -77,7 +77,7 @@ public function flash() } } -class FlextypeEntriesTwig +class EntriesTwig { use Macroable; @@ -104,30 +104,30 @@ class FlextypeMediaTwig /** * Create a Media Files instance. */ - public function files(): FlextypeMediaTwigFiles + public function files(): MediaTwigFiles { - return new FlextypeMediaTwigFiles(); + return new MediaTwigFiles(); } /** * Create a Media Files instance. */ - public function folders(): FlextypeMediaTwigFolders + public function folders(): MediaFoldersTwig { - return new FlextypeMediaTwigFolders(); + return new MediaFoldersTwig(); } } -class FlextypeMediaTwigFiles +class MediaTwigFiles { use Macroable; /** * Create a Media Files Meta instance. */ - public function meta(): FlextypeMediaTwigFilesMeta + public function meta(): MediaFilesMetaTwig { - return new FlextypeMediaTwigFilesMeta(); + return new MediaFilesMetaTwig(); } /** @@ -174,7 +174,7 @@ public function getFileLocation(string $id): bool } } -class FlextypeMediaTwigFilesMeta +class MediaFilesMetaTwig { use Macroable; @@ -193,16 +193,16 @@ public function getFileMetaLocation(string $id): bool } } -class FlextypeMediaTwigFolders +class MediaFoldersTwig { use Macroable; /** * Create a Media Folders Meta instance. */ - public function meta(): FlextypeMediaTwigFoldersMeta + public function meta(): MediaFoldersMetaTwig { - return new FlextypeMediaTwigFoldersMeta(); + return new MediaFoldersMetaTwig(); } /** @@ -235,7 +235,7 @@ public function getDirectoryLocation(string $id): string } } -class FlextypeMediaTwigFoldersMeta +class MediaFoldersMetaTwig { use Macroable; From 1a840b1024b64f3080e271e8fde4fe598acd15d1 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 11:20:05 +0300 Subject: [PATCH 46/52] refactor(core): set prio 0 --- settings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.yaml b/settings.yaml index 7ef563c..dd0128c 100644 --- a/settings.yaml +++ b/settings.yaml @@ -23,4 +23,4 @@ charset: "UTF-8" extensions: ['I18n', 'Filesystem', 'Csrf', 'Constants', 'Url', 'Strings', 'Arrays', 'Flextype', 'Filters'] # Twig plugin priority -priority: 100 +priority: 0 From ebb815a6307245ce3d6c11f3f4581da3dbc9e907 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 11:20:35 +0300 Subject: [PATCH 47/52] refactor(core): updates for PHP 7.4 --- dependencies.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/dependencies.php b/dependencies.php index 6cfd1e3..313e531 100644 --- a/dependencies.php +++ b/dependencies.php @@ -22,9 +22,7 @@ /** * Add CSRF (cross-site request forgery) protection service to Flextype container */ -flextype()->container()['csrf'] = static function (){ - return new Guard(); -}; +flextype()->container()['csrf'] = fn() => new Guard(); /** * Add Twig service to Flextype container @@ -53,21 +51,19 @@ $twig->addExtension(new DebugExtension()); // Load Flextype Twig extensions from directory /flextype/twig/ based on settings.twig.extensions array - $twig_extensions = flextype('registry')->get('plugins.twig.settings.extensions'); + $twigExtensions = flextype('registry')->get('plugins.twig.settings.extensions'); - foreach ($twig_extensions as $twig_extension) { - $twig_extension_class_name = $twig_extension . 'TwigExtension'; - $twig_extension_class_name_with_namespace = 'Flextype\\Plugin\\Twig\\Twig\\' . $twig_extension . 'TwigExtension'; + foreach ($twigExtensions as $twigExtension) { + $twigExtensionClassName = $twigExtension . 'TwigExtension'; + $twigExtensionClassNameWithNamespace = 'Flextype\\Plugin\\Twig\\Twig\\' . $twigExtension . 'TwigExtension'; - if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twig_extension_class_name . '.php')) { + if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twigExtensionClassName . '.php')) { - if ($twig_extension == 'Flextype') { - flextype()->container()['flash'] = static function () { - return new Messages(); - }; + if ($twigExtension == 'Flextype') { + flextype()->container()['flash'] = fn() => new Messages(); } - $twig->addExtension(new $twig_extension_class_name_with_namespace()); + $twig->addExtension(new $twigExtensionClassNameWithNamespace()); } } From d296c8d4d6a21100f0e34637accb98bb2d1189ee Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 11:20:44 +0300 Subject: [PATCH 48/52] refactor(core): updates for PHP 7.4 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 8e1fcc1..c439f5f 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "issues": "https://github.com/flextype-plugins/twig/issues" }, "require": { - "php": ">=7.3.0", + "php": ">=7.4.0", "slim/twig-view": "~2.5.0", "slim/csrf": "~0.8.3", "slim/flash": "~0.4.0", @@ -27,7 +27,7 @@ "apcu-autoloader": true, "optimize-autoloader": true, "platform": { - "php": "7.3.0" + "php": "7.4.0" } }, "autoload": { From 652540dd6ea61c29644c4d1b20c48c74eb1a9666 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 19:07:50 +0300 Subject: [PATCH 49/52] docs(readme): update docs for TWIG --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index efbf781..a91c528 100755 --- a/README.md +++ b/README.md @@ -190,6 +190,16 @@ The following Flextype Twig Functions are available in Flextype Twig Templates: | filesystem | Returns a new filesystem object from the given string. | | url | Returns application URL. | +### Filters + +The following Flextype Twig Filters are available in Flextype Twig Templates: + +| Variable | Description | +|---|---| +| __ | Translate string | +| shortcode | Shortcode parser | +| markdown | Markdown parser | + ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum) From 8d923ae07f3c0ddfb2e088ea28a88a1eef2e6b9a Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 19:08:25 +0300 Subject: [PATCH 50/52] refactor(core): updates for FlextypeTwigExtension --- dependencies.php | 23 ++++++++--------------- twig/FlextypeTwigExtension.php | 10 +++++----- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/dependencies.php b/dependencies.php index 313e531..cc3517c 100644 --- a/dependencies.php +++ b/dependencies.php @@ -27,25 +27,18 @@ /** * Add Twig service to Flextype container */ -flextype()->container()['twig'] = static function () { - - // Get twig settings - $twigSettings = [ - 'auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'), - 'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['tmp'] . '/twig' : false, - 'debug' => flextype('registry')->get('plugins.twig.settings.debug'), - 'charset' => flextype('registry')->get('plugins.twig.settings.charset') - ]; +flextype()->container()['twig'] = function () { // Create Twig View - $twig = new Twig(PATH['project'], $twigSettings); - - // Instantiate - $router = flextype('router'); - $uri = Uri::createFromEnvironment(new Environment($_SERVER)); + $twig = new Twig(PATH['project'], + ['auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'), + 'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['tmp'] . '/twig' : false, + 'debug' => flextype('registry')->get('plugins.twig.settings.debug'), + 'charset' => flextype('registry')->get('plugins.twig.settings.charset')]); // Add Twig Extension - $twig->addExtension(new TwigExtension($router, $uri)); + $twig->addExtension(new TwigExtension(flextype('router'), + Uri::createFromEnvironment(new Environment($_SERVER)))); // Add Twig Debug Extension $twig->addExtension(new DebugExtension()); diff --git a/twig/FlextypeTwigExtension.php b/twig/FlextypeTwigExtension.php index c59d5eb..8915fed 100644 --- a/twig/FlextypeTwigExtension.php +++ b/twig/FlextypeTwigExtension.php @@ -38,7 +38,7 @@ public function entries() public function media() { - return new FlextypeMediaTwig(); + return new MediaTwig(); } public function registry() @@ -97,16 +97,16 @@ public function fetch(string $id, array $options = []): Arrays } } -class FlextypeMediaTwig +class MediaTwig { use Macroable; /** * Create a Media Files instance. */ - public function files(): MediaTwigFiles + public function files(): MediaFilesTwig { - return new MediaTwigFiles(); + return new MediaFilesTwig(); } /** @@ -118,7 +118,7 @@ public function folders(): MediaFoldersTwig } } -class MediaTwigFiles +class MediaFilesTwig { use Macroable; From 75fb6945068990fb7bb2c672fab13ff8d4bad9fe Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 28 Dec 2020 19:56:29 +0300 Subject: [PATCH 51/52] refactor(core): updates for FilterTwigExtension --- twig/FiltersTwigExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twig/FiltersTwigExtension.php b/twig/FiltersTwigExtension.php index 121fcec..28ef1b0 100644 --- a/twig/FiltersTwigExtension.php +++ b/twig/FiltersTwigExtension.php @@ -3,7 +3,7 @@ declare(strict_types=1); /** - * Flextype (http://flextype.org) + * Flextype (https://flextype.org) * Founded by Sergey Romanenko and maintained by Flextype Community. */ From 8e76d5d704a767b5f032cc76c5970e81490cd2e3 Mon Sep 17 00:00:00 2001 From: Awilum Date: Wed, 30 Dec 2020 15:22:21 +0300 Subject: [PATCH 52/52] Twig 1.7.0 --- CHANGELOG.md | 21 +++++++++++++++++++++ README.md | 4 ++-- plugin.yaml | 4 ++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c0be5..905203c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,24 @@ + +# [1.7.0](https://github.com/flextype-plugins/twig/compare/v1.6.0...v1.7.0) (2020-12-30) + +### Features + +* **core** update code base for new Flextype 0.9.14 +* **core** Moving to PHP 7.4 +* **core** use new TWIG Plugin 1.7.0 +* **extension** new Constants Extension +* **extension** new Filesystem Extension +* **extension** new Flextype Extension +* **extension** new Filters Extension + +New docs on the way here https://github.com/flextype-plugins/twig/ + +BREAKING CHANGES + +* in the templates use `flextype.registry` instead of `registry` +* in the templates use `flextype.entries` instead of `entries` +* in the templates use `flextype.media` instead of `media_*` + # [1.6.0](https://github.com/flextype-plugins/twig/compare/v1.5.1...v1.6.0) (2020-12-20) diff --git a/README.md b/README.md index a91c528..78d2cbf 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Twig Plugin for Flextype

-Version License Total downloads Flextype Discord +Version License Total downloads Flextype Discord

Twig plugin to present Twig template engine for Flextype. @@ -19,7 +19,7 @@ The following dependencies need to be installed for Twig Plugin. | Item | Version | Download | |---|---|---| -| [flextype](https://github.com/flextype/flextype) | 0.9.13 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.14 | [download](https://github.com/flextype/flextype/releases) | ## Installation diff --git a/plugin.yaml b/plugin.yaml index 22a17b1..ec1788e 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Twig -version: 1.6.0 +version: 1.7.0 description: Twig plugin to present Twig template engine for Flextype. icon: fas fa-palette author: @@ -11,4 +11,4 @@ bugs: https://github.com/flextype-plugins/twig/issues license: MIT dependencies: - flextype: 0.9.13 + flextype: 0.9.14