From 5f680c39df55de53def3a8fd9b6f38bbd8885168 Mon Sep 17 00:00:00 2001 From: Marion Newlevant Date: Fri, 24 Aug 2018 11:43:39 -0700 Subject: [PATCH] version 2.0.5 - adds === and !== --- CHANGELOG.md | 4 ++++ README.md | 6 ++++++ composer.json | 2 +- .../Expression_Binary_Equivalent.php | 11 +++++++++++ .../Expression_Binary_NotEquivalent.php | 11 +++++++++++ .../TwigPerversionTwigExtension.php | 19 +++++++++++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/twigextensions/Expression_Binary_Equivalent.php create mode 100644 src/twigextensions/Expression_Binary_NotEquivalent.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cf6b14..afd998a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Twig Perversion Changelog +## 2.0.5 - 2018.08.24 +### Added +* Added `===`, and `!==` operators. + ## 2.0.4 - 2018.07.16 ### Added * Added `string`, `float`, `int`, and `bool` typecast filters. diff --git a/README.md b/README.md index c003afd..524c595 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Making twig do things it really shouldn't. Twig is not intended to be a general purpose programming language, and there are some things that really don't belong in the language. This plugin adds a few of those things anyway. - `{% break %}`, `{% continue %}`, and `{% return %}` tags +- `===` and `!==` operators - `is numeric` test - `json_decode` filter - `array_splice` filter @@ -57,6 +58,11 @@ or A macro with a `{% return %}` tag will return whatever the return value is (which can be a complex expression). Any other output generated by the macro will be discarded. +### Operators +- **===** and **!==** + + Compares two values for equivalence, using php's `===` and `!==` operators. + ### Tests - **Numeric** diff --git a/composer.json b/composer.json index 3a4fee4..2eec901 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "marionnewlevant/twig-perversion", "description": "Making twig do things it really shouldn't", - "version": "2.0.4", + "version": "2.0.5", "type": "craft-plugin", "keywords": [ "craft", "craftcms", "plugin", "twigperversion" diff --git a/src/twigextensions/Expression_Binary_Equivalent.php b/src/twigextensions/Expression_Binary_Equivalent.php new file mode 100644 index 0000000..fbc8c6e --- /dev/null +++ b/src/twigextensions/Expression_Binary_Equivalent.php @@ -0,0 +1,11 @@ +raw('==='); + } +} \ No newline at end of file diff --git a/src/twigextensions/Expression_Binary_NotEquivalent.php b/src/twigextensions/Expression_Binary_NotEquivalent.php new file mode 100644 index 0000000..a519b1a --- /dev/null +++ b/src/twigextensions/Expression_Binary_NotEquivalent.php @@ -0,0 +1,11 @@ +raw('!=='); + } +} \ No newline at end of file diff --git a/src/twigextensions/TwigPerversionTwigExtension.php b/src/twigextensions/TwigPerversionTwigExtension.php index ea591e9..1d51f34 100644 --- a/src/twigextensions/TwigPerversionTwigExtension.php +++ b/src/twigextensions/TwigPerversionTwigExtension.php @@ -78,6 +78,25 @@ public function getFilters() ]; } + public function getOperators() + { + return [ + [], + [ + '===' => [ + 'precedence' => 20, + 'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_Equivalent', + 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT, + ], + '!==' => [ + 'precedence' => 20, + 'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_NotEquivalent', + 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT, + ], + ], + ]; + } + /** * Cast value as a string. *