Skip to content

Commit

Permalink
Version 2.0.5 - spaceship operator
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Oct 15, 2018
1 parent 5f680c3 commit 4d75d1d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Making twig do things it really shouldn&#39;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
Expand Down Expand Up @@ -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.

- **&lt;=&gt;**

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**

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
11 changes: 11 additions & 0 deletions src/twigextensions/Expression_Binary_Spaceship.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace marionnewlevant\twigperversion\twigextensions;

class Expression_Binary_Spaceship extends \Twig_Node_Expression_Binary
{
public function operator(\Twig_Compiler $compiler)
{
return $compiler->raw('<=>');
}
}
5 changes: 5 additions & 0 deletions src/twigextensions/TwigPerversionTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
];
}
Expand Down

0 comments on commit 4d75d1d

Please sign in to comment.