From ad4cf07f229160a5027f2c4691da8196675030c0 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 25 Aug 2020 18:07:01 +0300 Subject: [PATCH] Twig 1.3.0 --- CHANGELOG.md | 7 +++++++ README.md | 4 ++-- dependencies.php | 20 ++++++++++---------- plugin.yaml | 4 ++-- twig/ArraysTwigExtension.php | 17 ++++++----------- twig/CacheTwigExtension.php | 11 +++-------- twig/CollectionTwigExtension.php | 9 ++------- twig/CsrfTwigExtension.php | 21 ++++++++------------- twig/EmitterTwigExtension.php | 21 ++++++++------------- twig/EntriesTwigExtension.php | 27 +++++++-------------------- twig/FlashTwigExtension.php | 13 ++++--------- twig/GlobalVarsTwigExtension.php | 9 ++------- twig/JsonTwigExtension.php | 13 ++++--------- twig/MarkdownTwigExtension.php | 11 +++-------- twig/RegistryTwigExtension.php | 24 ++++++++++-------------- twig/ShortcodeTwigExtension.php | 11 +++-------- twig/UrlTwigExtension.php | 13 ++++--------- twig/YamlTwigExtension.php | 13 ++++--------- 18 files changed, 89 insertions(+), 159 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87972b2..4065c80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ + +# [1.3.0](https://github.com/flextype-plugins/twig/compare/v1.2.0...v1.3.0) (2020-08-25) + +### Features + +* **core** update code base for new Flextype 0.9.11 + # [1.2.0](https://github.com/flextype-plugins/twig/compare/v1.1.1...v1.2.0) (2020-08-19) diff --git a/README.md b/README.md index de1ebc0..fc7339e 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.10 | [download](https://github.com/flextype/flextype/releases) | +| [flextype](https://github.com/flextype/flextype) | 0.9.11 | [download](https://github.com/flextype/flextype/releases) | ## Installation diff --git a/dependencies.php b/dependencies.php index 2aa2a1e..a8075e5 100644 --- a/dependencies.php +++ b/dependencies.php @@ -22,28 +22,28 @@ /** * Add CSRF (cross-site request forgery) protection service to Flextype container */ -$flextype->container()['csrf'] = static function () use ($flextype){ +flextype()->container()['csrf'] = static function (){ return new Guard(); }; /** * Add Twig service to Flextype container */ -$flextype->container()['twig'] = static function () use ($flextype) { +flextype()->container()['twig'] = static function () { // Get twig settings $twigSettings = [ - 'auto_reload' => $flextype->container('registry')->get('plugins.twig.settings.auto_reload'), - 'cache' => $flextype->container('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false, - 'debug' => $flextype->container('registry')->get('plugins.twig.settings.debug'), - 'charset' => $flextype->container('registry')->get('plugins.twig.settings.charset') + 'auto_reload' => flextype('registry')->get('plugins.twig.settings.auto_reload'), + 'cache' => flextype('registry')->get('plugins.twig.settings.cache') ? PATH['cache'] . '/twig' : false, + 'debug' => flextype('registry')->get('plugins.twig.settings.debug'), + 'charset' => flextype('registry')->get('plugins.twig.settings.charset') ]; // Create Twig View $twig = new Twig(PATH['project'], $twigSettings); // Instantiate - $router = $flextype->container('router'); + $router = flextype('router'); $uri = Uri::createFromEnvironment(new Environment($_SERVER)); // Add Twig Extension @@ -53,7 +53,7 @@ $twig->addExtension(new DebugExtension()); // Load Flextype Twig extensions from directory /flextype/twig/ based on settings.twig.extensions array - $twig_extensions = $flextype->container('registry')->get('plugins.twig.settings.extensions'); + $twig_extensions = flextype('registry')->get('plugins.twig.settings.extensions'); foreach ($twig_extensions as $twig_extension) { $twig_extension_class_name = $twig_extension . 'TwigExtension'; @@ -62,12 +62,12 @@ if (file_exists(ROOT_DIR . '/project/plugins/twig/twig/' . $twig_extension_class_name . '.php')) { if ($twig_extension == 'Flash') { - $flextype->container()['flash'] = static function () { + flextype()->container()['flash'] = static function () { return new Messages(); }; } - $twig->addExtension(new $twig_extension_class_name_with_namespace($flextype)); + $twig->addExtension(new $twig_extension_class_name_with_namespace()); } } diff --git a/plugin.yaml b/plugin.yaml index bf20d67..c12d1b4 100755 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: Twig -version: 1.2.0 +version: 1.3.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.10 + flextype: 0.9.11 diff --git a/twig/ArraysTwigExtension.php b/twig/ArraysTwigExtension.php index 011d1dc..5c2db0f 100644 --- a/twig/ArraysTwigExtension.php +++ b/twig/ArraysTwigExtension.php @@ -15,17 +15,12 @@ class ArraysTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -34,7 +29,7 @@ public function __construct($flextype) public function getGlobals() : array { return [ - 'arrays' => new ArraysTwig($this->flextype), + 'arrays' => new ArraysTwig(), ]; } } @@ -44,14 +39,14 @@ class ArraysTwig /** * Flextype Application */ - protected $flextype; + /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** diff --git a/twig/CacheTwigExtension.php b/twig/CacheTwigExtension.php index 2903c0b..2058a62 100644 --- a/twig/CacheTwigExtension.php +++ b/twig/CacheTwigExtension.php @@ -14,17 +14,12 @@ class CacheTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -33,7 +28,7 @@ public function __construct($flextype) public function getGlobals() : array { return [ - 'cache' => $this->flextype->container('cache'), + 'cache' => flextype('cache'), ]; } } diff --git a/twig/CollectionTwigExtension.php b/twig/CollectionTwigExtension.php index fe0b8e3..581d772 100644 --- a/twig/CollectionTwigExtension.php +++ b/twig/CollectionTwigExtension.php @@ -13,17 +13,12 @@ class CollectionTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** diff --git a/twig/CsrfTwigExtension.php b/twig/CsrfTwigExtension.php index a3d317c..60697bb 100644 --- a/twig/CsrfTwigExtension.php +++ b/twig/CsrfTwigExtension.php @@ -14,17 +14,12 @@ class CsrfTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -33,10 +28,10 @@ public function __construct($flextype) public function getGlobals() : array { // CSRF token name and value - $csrfNameKey = $this->flextype->container('csrf')->getTokenNameKey(); - $csrfValueKey = $this->flextype->container('csrf')->getTokenValueKey(); - $csrfName = $this->flextype->container('csrf')->getTokenName(); - $csrfValue = $this->flextype->container('csrf')->getTokenValue(); + $csrfNameKey = flextype('csrf')->getTokenNameKey(); + $csrfValueKey = flextype('csrf')->getTokenValueKey(); + $csrfName = flextype('csrf')->getTokenName(); + $csrfValue = flextype('csrf')->getTokenValue(); return [ 'csrf' => [ @@ -72,7 +67,7 @@ public function getFunctions() : array */ public function csrf() : string { - return '' . - ''; + return '' . + ''; } } diff --git a/twig/EmitterTwigExtension.php b/twig/EmitterTwigExtension.php index 2271f70..23305e0 100644 --- a/twig/EmitterTwigExtension.php +++ b/twig/EmitterTwigExtension.php @@ -14,17 +14,12 @@ class EmitterTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -33,7 +28,7 @@ public function __construct($flextype) public function getGlobals() : array { return [ - 'emitter' => new EmitterTwig($this->flextype), + 'emitter' => new EmitterTwig(), ]; } } @@ -43,14 +38,14 @@ class EmitterTwig /** * Flextype Application */ - protected $flextype; + /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -58,7 +53,7 @@ public function __construct($flextype) */ public function emit($event) { - return $this->flextype->container('emitter')->emit($event); + return flextype('emitter')->emit($event); } /** @@ -66,6 +61,6 @@ public function emit($event) */ public function emitBatch(array $events) { - return $this->flextype->container('emitter')->emitBatch($events); + return flextype('emitter')->emitBatch($events); } } diff --git a/twig/EntriesTwigExtension.php b/twig/EntriesTwigExtension.php index 3c34681..2458f02 100644 --- a/twig/EntriesTwigExtension.php +++ b/twig/EntriesTwigExtension.php @@ -14,26 +14,13 @@ class EntriesTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - - /** - * Constructor - */ - public function __construct($flextype) - { - $this->flextype = $flextype; - } - /** * Register Global variables in an extension */ public function getGlobals() : array { return [ - 'entries' => new EntriesTwig($this->flextype), + 'entries' => new EntriesTwig(), ]; } } @@ -43,14 +30,14 @@ class EntriesTwig /** * Flextype Application */ - protected $flextype; + /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -58,7 +45,7 @@ public function __construct($flextype) */ public function fetch(string $path, bool $collection = false, array $filter = []) : array { - return $this->flextype->container('entries')->fetch($path, $collection, $filter); + return flextype('entries')->fetch($path, $collection, $filter); } /** @@ -66,7 +53,7 @@ public function fetch(string $path, bool $collection = false, array $filter = [] */ public function fetchSingle(string $path) : array { - return $this->flextype->container('entries')->fetch($path); + return flextype('entries')->fetch($path); } /** @@ -74,6 +61,6 @@ public function fetchSingle(string $path) : array */ public function fetchCollection(string $path, array $filter = []) : array { - return $this->flextype->container('entries')->fetchCollection($path, $filter); + return flextype('entries')->fetchCollection($path, $filter); } } diff --git a/twig/FlashTwigExtension.php b/twig/FlashTwigExtension.php index 1768ec6..bfb7ea8 100644 --- a/twig/FlashTwigExtension.php +++ b/twig/FlashTwigExtension.php @@ -13,17 +13,12 @@ class FlashTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -47,9 +42,9 @@ public function getFunctions() : array public function getMessages(?string $key = null) : array { if ($key !== null) { - return $this->flextype->container('flash')->getMessage($key); + return flextype('flash')->getMessage($key); } - return $this->flextype->container('flash')->getMessages(); + return flextype('flash')->getMessages(); } } diff --git a/twig/GlobalVarsTwigExtension.php b/twig/GlobalVarsTwigExtension.php index e860fdf..d55e02c 100644 --- a/twig/GlobalVarsTwigExtension.php +++ b/twig/GlobalVarsTwigExtension.php @@ -15,17 +15,12 @@ class GlobalVarsTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** diff --git a/twig/JsonTwigExtension.php b/twig/JsonTwigExtension.php index eeb03a1..c836f84 100644 --- a/twig/JsonTwigExtension.php +++ b/twig/JsonTwigExtension.php @@ -13,17 +13,12 @@ class JsonTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -57,7 +52,7 @@ public function getFilters() : array */ public function encode($input) : string { - return $this->flextype->container('json')->encode($input); + return flextype('json')->encode($input); } /** @@ -65,6 +60,6 @@ public function encode($input) : string */ public function decode(string $input, bool $cache = true) { - return $this->flextype->container('json')->decode($input, $cache); + return flextype('json')->decode($input, $cache); } } diff --git a/twig/MarkdownTwigExtension.php b/twig/MarkdownTwigExtension.php index 3db0094..6d2a7b5 100644 --- a/twig/MarkdownTwigExtension.php +++ b/twig/MarkdownTwigExtension.php @@ -13,17 +13,12 @@ class MarkdownTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -44,7 +39,7 @@ public function getFilters() : array public function markdown($input, bool $cache = true) : string { if (!empty($input)) { - return $this->container['markdown']->parse($input, $cache); + return flextype('markdown')->parse($input, $cache); } return ''; diff --git a/twig/RegistryTwigExtension.php b/twig/RegistryTwigExtension.php index 648f718..f17ccb3 100644 --- a/twig/RegistryTwigExtension.php +++ b/twig/RegistryTwigExtension.php @@ -14,17 +14,13 @@ class RegistryTwigExtension extends AbstractExtension implements GlobalsInterface { - /** - * Flextype Application - */ - protected $flextype; /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -33,7 +29,7 @@ public function __construct($flextype) public function getGlobals() : array { return [ - 'registry' => new RegistryTwig($this->flextype), + 'registry' => new RegistryTwig(), ]; } } @@ -43,14 +39,14 @@ class RegistryTwig /** * Flextype Application */ - protected $flextype; + /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -60,7 +56,7 @@ public function __construct($flextype) */ public function dump() : array { - return $this->flextype->container('registry')->dump(); + return flextype('registry')->dump(); } /** @@ -71,7 +67,7 @@ public function dump() : array */ public function has(string $name) : bool { - return $this->flextype->container('registry')->has($name); + return flextype('registry')->has($name); } /** @@ -83,7 +79,7 @@ public function has(string $name) : bool */ public function set(string $name, $value = null) : void { - $this->flextype->container('registry')->set($name, $value); + flextype('registry')->set($name, $value); } /** @@ -95,6 +91,6 @@ public function set(string $name, $value = null) : void */ public function get(string $name, $default = null) { - return $this->flextype->container('registry')->get($name, $default); + return flextype('registry')->get($name, $default); } } diff --git a/twig/ShortcodeTwigExtension.php b/twig/ShortcodeTwigExtension.php index e570e3c..b996303 100644 --- a/twig/ShortcodeTwigExtension.php +++ b/twig/ShortcodeTwigExtension.php @@ -13,17 +13,12 @@ class ShortcodeTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -44,7 +39,7 @@ public function getFilters() : array public function shortcode($value) : string { if (!empty($value)) { - return $this->flextype->container('shortcode')->process($value); + return flextype('shortcode')->process($value); } return ''; diff --git a/twig/UrlTwigExtension.php b/twig/UrlTwigExtension.php index 43da04a..d8295e1 100644 --- a/twig/UrlTwigExtension.php +++ b/twig/UrlTwigExtension.php @@ -15,17 +15,12 @@ class UrlTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -45,8 +40,8 @@ public function getFunctions() : array */ public function url() : string { - if ($this->flextype->container('registry')->has('flextype.settings.url') && $this->flextype->container('registry')->get('flextype.settings.url') != '') { - return $this->flextype->container('registry')->get('flextype.settings.url'); + if (flextype('registry')->has('flextype.settings.url') && flextype('registry')->get('flextype.settings.url') != '') { + return flextype('registry')->get('flextype.settings.url'); } else { return Uri::createFromEnvironment(new Environment($_SERVER))->getBaseUrl(); } diff --git a/twig/YamlTwigExtension.php b/twig/YamlTwigExtension.php index 77d4d97..105a9f0 100644 --- a/twig/YamlTwigExtension.php +++ b/twig/YamlTwigExtension.php @@ -13,17 +13,12 @@ class YamlTwigExtension extends AbstractExtension { - /** - * Flextype Application - */ - protected $flextype; - /** * Constructor */ - public function __construct($flextype) + public function __construct() { - $this->flextype = $flextype; + } /** @@ -57,7 +52,7 @@ public function getFilters() : array */ public function encode($input) : string { - return $this->flextype->container('yaml')->encode($input); + return flextype('yaml')->encode($input); } /** @@ -65,6 +60,6 @@ public function encode($input) : string */ public function decode(string $input, bool $cache = true) { - return $this->flextype->container('yaml')->decode($input, $cache); + return flextype('yaml')->decode($input, $cache); } }