nystudio107 /
craft-emptycoalesce
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Empty Coalesce plugin for Craft CMS 3.x |
||
| 4 | * |
||
| 5 | * Empty Coalesce adds the ??? operator to Twig that will return the first thing |
||
| 6 | * that is defined, not null, and not empty. |
||
| 7 | * |
||
| 8 | * @link https://nystudio107.com/ |
||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 9 | * @copyright Copyright (c) 2018 nystudio107 |
||
|
0 ignored issues
–
show
|
|||
| 10 | */ |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | namespace nystudio107\emptycoalesce\twigextensions; |
||
| 13 | |||
| 14 | use nystudio107\emptycoalesce\Node\Expression\EmptyCoalesceExpression; |
||
| 15 | |||
| 16 | use Twig\ExpressionParser; |
||
| 17 | use Twig\Extension\AbstractExtension; |
||
| 18 | |||
| 19 | /** |
||
|
0 ignored issues
–
show
|
|||
| 20 | * @author nystudio107 |
||
|
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
| 21 | * @package EmptyCoalesce |
||
|
0 ignored issues
–
show
|
|||
| 22 | * @since 1.0.0 |
||
|
0 ignored issues
–
show
|
|||
| 23 | */ |
||
|
0 ignored issues
–
show
|
|||
| 24 | class EmptyCoalesceTwigExtension extends AbstractExtension |
||
| 25 | { |
||
| 26 | // Public Methods |
||
| 27 | // ========================================================================= |
||
| 28 | |||
| 29 | /** |
||
|
0 ignored issues
–
show
|
|||
| 30 | * @inheritdoc |
||
| 31 | */ |
||
|
0 ignored issues
–
show
|
|||
| 32 | public function getName(): string |
||
| 33 | { |
||
| 34 | return 'EmptyCoalesce'; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
|
0 ignored issues
–
show
|
|||
| 38 | * @inheritdoc |
||
| 39 | */ |
||
|
0 ignored issues
–
show
|
|||
| 40 | public function getFilters(): array |
||
| 41 | { |
||
| 42 | return [ |
||
| 43 | ]; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
|
0 ignored issues
–
show
|
|||
| 47 | * @inheritdoc |
||
| 48 | */ |
||
|
0 ignored issues
–
show
|
|||
| 49 | public function getFunctions(): array |
||
| 50 | { |
||
| 51 | return [ |
||
| 52 | ]; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
|
0 ignored issues
–
show
|
|||
| 56 | * @return array<int, mixed[]> |
||
| 57 | */ |
||
| 58 | public function getOperators(): array |
||
| 59 | { |
||
| 60 | return [ |
||
| 61 | // Unary operators |
||
| 62 | [], |
||
| 63 | // Binary operators |
||
| 64 | [ |
||
| 65 | '???' => [ |
||
| 66 | 'precedence' => 300, |
||
| 67 | 'class' => EmptyCoalesceExpression::class, |
||
| 68 | 'associativity' => ExpressionParser::OPERATOR_RIGHT, |
||
| 69 | ], |
||
| 70 | ], |
||
| 71 | ]; |
||
| 72 | } |
||
| 73 | } |
||
| 74 |