8000 Add a BC way to access environment operators/expression parsers · Issue #4634 · twigphp/Twig · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Add a BC way to access environment operators/expression parsers #4634
Open
@VincentLanglet

Description

@VincentLanglet

Hi @fabpot

Twig-CS-Fixer use his own Lexer because

  • he needs to keep space/tabs
  • he uses more token types

The implementation worked fine so far, but just got recently broke by the 3.21 release since I inspired my getOperatorRegex implementation by yours

Twig/src/Lexer.php

Lines 547 to 551 in 3468920

$operators = array_merge(
['='],
array_keys($this->env->getUnaryOperators()),
array_keys($this->env->getBinaryOperators())
);
and now getUnaryOperator/getBinaryOperator methods was removed. Of course it was possible since it's internal.

I implemented a fix to follow your new implementation

Twig/src/Lexer.php

Lines 528 to 530 in b54a265

$expressionParsers = ['='];
foreach ($this->env->getExpressionParsers() as $expressionParser) {
$expressionParsers = array_merge($expressionParsers, [$expressionParser->getName()], $expressionParser->getAliases());
(but with some changes since I need to keep the same type for (, [, =>, ... for BC reason). But again getExpressionParsers is internal.

Is there a way to write

$expressionParsers = ['='];
foreach ($this->env->getExpressionParsers() as $expressionParser) {
     $expressionParsers = array_merge($expressionParsers, [$expressionParser->getName()], $expressionParser->getAliases());
}

without an internal method ? Would it be OK to make getExpressionParsers part of the API ?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0