From 660de69ac3d843d85ca7a66935083a68bf599f05 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 7 Dec 2020 13:13:41 +0300 Subject: [PATCH] Twig 1.4.0 --- .gitignore | 20 +++++++ CHANGELOG.md | 7 +++ LICENSE.txt | 2 +- README.md | 10 ++-- composer.json | 4 +- dependencies.php | 2 +- plugin.yaml | 4 +- twig/ArraysTwigExtension.php | 95 +++----------------------------- twig/CollectionTwigExtension.php | 40 -------------- twig/EntriesTwigExtension.php | 19 ++----- twig/GlobalVarsTwigExtension.php | 2 - 11 files changed, 52 insertions(+), 153 deletions(-) create mode 100755 .gitignore delete mode 100644 twig/CollectionTwigExtension.php diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..c00a8d8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Global +.composer +composer.lock +package-lock.json +vendor/ +node_modules/ +dist/ + +# Flextype Site Specific +var/ + +# OS Generated +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db +*.swp + +# phpstorm +.idea/* diff --git a/CHANGELOG.md b/CHANGELOG.md index 4065c80..c205c0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.4.0](https://github.com/flextype-plugins/twig/compare/v1.3.0...v1.4.0) (2020-12-07) + +### Features + +* **core** update code base for new Flextype 0.9.12 + # [1.3.0](https://github.com/flextype-plugins/twig/compare/v1.2.0...v1.3.0) (2020-08-25) diff --git a/LICENSE.txt b/LICENSE.txt index f628cc1..6b05ac2 100755 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2018-2020 Sergey Romanenko +Copyright (c) 2021 Sergey Romanenko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index fc7339e..174337c 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. @@ -12,7 +12,7 @@ The following dependencies need to be installed for Twig Plugin. | Item | Version | Download | |---|---|---| -| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.12 | [download](https://github.com/flextype/flextype/releases) | ## Installation @@ -306,7 +306,7 @@ Fetch single entry Usage: ```twig -{% set about_entry = entries.fetch('about') %} +{% set about_entry = entries.fetchSingle('about') %} ``` Fetch collection of entries @@ -314,7 +314,7 @@ Fetch collection of entries Usage: ```twig -{% set posts = entries.fetch('blog', {}) %} +{% set posts = entries.fetchSingle('blog', {}) %} or {% set posts = entries.fetchCollection('blog') %} ``` @@ -487,4 +487,4 @@ Usage: ## LICENSE [The MIT License (MIT)](https://github.com/flextype-plugins/twig/blob/master/LICENSE.txt) -Copyright (c) 2018-2020 [Sergey Romanenko](https://github.com/Awilum) +Copyright (c) 2021 [Sergey Romanenko](https://github.com/Awilum) diff --git a/composer.json b/composer.json index 5b8f7be..8e1fcc1 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,9 @@ "php": ">=7.3.0", "slim/twig-view": "~2.5.0", "slim/csrf": "~0.8.3", - "slim/flash": "~0.4.0" + "slim/flash": "~0.4.0", + "flextype-components/arrays" : "3.0.1", + "flextype-components/filesystem": "2.0.8" }, "config": { "apcu-autoloader": true, diff --git a/dependencies.php b/dependencies.php index a8075e5..76d9bf8 100644 --- a/dependencies.php +++ b/dependencies.php @@ -34,7 +34,7 @@ // Get twig settings $twigSettings = [ 'auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'), - 'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false, + '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') ]; diff --git a/plugin.yaml b/plugin.yaml index c12d1b4..183a11d 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Twig -version: 1.3.0 +version: 1.4.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.11 + flextype: 0.9.12 diff --git a/twig/ArraysTwigExtension.php b/twig/ArraysTwigExtension.php index 5c2db0f..7531207 100644 --- a/twig/ArraysTwigExtension.php +++ b/twig/ArraysTwigExtension.php @@ -10,10 +10,8 @@ namespace Flextype\Plugin\Twig\Twig; use Twig\Extension\AbstractExtension; -use Twig\Extension\GlobalsInterface; -use Flextype\Component\Arrays\Arrays; -class ArraysTwigExtension extends AbstractExtension implements GlobalsInterface +class ArraysTwigExtension extends AbstractExtension { /** * Constructor @@ -24,96 +22,19 @@ public function __construct() } /** - * Register Global variables in an extension - */ - public function getGlobals() : array - { - return [ - 'arrays' => new ArraysTwig(), - ]; - } -} - -class ArraysTwig -{ - /** - * Flextype Application - */ - - - /** - * Constructor - */ - public function __construct() - { - - } - - /** - * Sorts a multi-dimensional array by a certain column + * Callback for twig. * - * @param array $array The source array - * @param string $field The name of the column - * @param string $direction Order type DESC (descending) or ASC (ascending) - * @param const $method A PHP sort method flag or 'natural' for natural sorting, which is not supported in PHP by sort flags * @return array */ - public function sort(array $array, string $field, string $direction = 'ASC', $method = SORT_REGULAR) : array - { - return Arrays::sort($array, $field, $direction, $method); - } - - /** - * Sets an array value using "dot notation". - * - * @access public - * @param array $array Array you want to modify - * @param string $path Array path - * @param mixed $value Value to set - */ - public function set(array &$array, string $path, $value) + public function getFunctions() : array { - Arrays::set($array, $path, $value); - return $array; - } - - /** - * Returns value from array using "dot notation". - * If the key does not exist in the array, the default value will be returned instead. - * - * @param array $array Array to extract from - * @param string $path Array path - * @param mixed $default Default value - * @return mixed - */ - public function get(array $array, string $path, $default = null) - { - return Arrays::get($array, $path, $default); - } - - /** - * Deletes an array value using "dot notation". - * - * @access public - * @param array $array Array you want to modify - * @param string $path Array path - * @return bool - */ - public function delete(array &$array, string $path) : bool - { - Arrays::delete($array, $path); - return $array; + return [ + new \Twig\TwigFunction('arrays', [$this, 'arrays']), + ]; } - /** - * Checks if the given dot-notated key exists in the array. - * - * @param array $array The search array - * @param mixed $path Array path - * @return bool - */ - public function has(array $array, $path) : bool + public function arrays($items) { - return Arrays::has($array, $path); + return arrays($items); } } diff --git a/twig/CollectionTwigExtension.php b/twig/CollectionTwigExtension.php deleted file mode 100644 index 581d772..0000000 --- a/twig/CollectionTwigExtension.php +++ /dev/null @@ -1,40 +0,0 @@ - new EntriesTwig(), @@ -31,7 +31,6 @@ class EntriesTwig * Flextype Application */ - /** * Constructor */ @@ -40,27 +39,19 @@ public function __construct() } - /** - * Fetch entry(entries) - */ - public function fetch(string $path, bool $collection = false, array $filter = []) : array - { - return flextype('entries')->fetch($path, $collection, $filter); - } - /** * Fetch single entry */ - public function fetchSingle(string $path) : array + public function fetchSingle(string $id, array $options = []) { - return flextype('entries')->fetch($path); + return flextype('entries')->fetchSingle($id, $options); } /** * Fetch entries collection */ - public function fetchCollection(string $path, array $filter = []) : array + public function fetchCollection(string $id, array $options = []) { - return flextype('entries')->fetchCollection($path, $filter); + return flextype('entries')->fetchCollection($id, $options); } } diff --git a/twig/GlobalVarsTwigExtension.php b/twig/GlobalVarsTwigExtension.php index d55e02c..9193a30 100644 --- a/twig/GlobalVarsTwigExtension.php +++ b/twig/GlobalVarsTwigExtension.php @@ -30,8 +30,6 @@ public function getGlobals() : array { return [ 'PATH_PROJECT' => PATH['project'], - 'PATH_CACHE' => PATH['cache'], - 'PATH_LOGS' => PATH['logs'], 'PHP_VERSION' => PHP_VERSION ]; }