diff --git a/CHANGELOG.md b/CHANGELOG.md index afd998a..dbacbde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Twig Perversion Changelog +## 2.0.6 - 2018.09.14 +### Added +* Added `<=>` operator. ([spaceship operator](http://php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op)) + ## 2.0.5 - 2018.08.24 ### Added * Added `===`, and `!==` operators. diff --git a/README.md b/README.md index 524c595..c360a1b 100644 --- a/README.md +++ b/README.md @@ -3,7 +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 +- `===`, `!==`, and `<=>` operators - `is numeric` test - `json_decode` filter - `array_splice` filter @@ -63,6 +63,10 @@ A macro with a `{% return %}` tag will return whatever the return value is (whic Compares two values for equivalence, using php's `===` and `!==` operators. +- **<=>** + + Compares two values using php's [`<=>` (spaceship)](http://php.net/manual/en/migration70.new-features.php#migration70.new-features.spaceship-op) operator. Returns `-1`, `0`, or `1` when the first argument is respectively less than, equal to, or greater than the second. + ### Tests - **Numeric** diff --git a/composer.json b/composer.json index 2eec901..896bad2 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.5", + "version": "2.0.6", "type": "craft-plugin", "keywords": [ "craft", "craftcms", "plugin", "twigperversion" diff --git a/src/twigextensions/Expression_Binary_Spaceship.php b/src/twigextensions/Expression_Binary_Spaceship.php new file mode 100644 index 0000000..4577c04 --- /dev/null +++ b/src/twigextensions/Expression_Binary_Spaceship.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 1d51f34..02da436 100644 --- a/src/twigextensions/TwigPerversionTwigExtension.php +++ b/src/twigextensions/TwigPerversionTwigExtension.php @@ -93,6 +93,11 @@ public function getOperators() 'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_NotEquivalent', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT, ], + '<=>' => [ + 'precedence' => 20, + 'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_Spaceship', + 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT, + ], ], ]; }