createForMalformedFunction() public static méthode

public static createForMalformedFunction ( string $value ) : MalformedFunctionException
$value string
Résultat MalformedFunctionException
 public function testTestCreateForMalformedFunction()
 {
     $exception = ExpressionLanguageExceptionFactory::createForMalformedFunction('foo');
     $this->assertEquals('The value "foo" contains an unclosed function.', $exception->getMessage());
     $this->assertEquals(0, $exception->getCode());
     $this->assertNull($exception->getPrevious());
 }
Exemple #2
0
 /**
  * Regroup tokens together by detecting when the function starts, closes or when it is nested.
  *
  * @param string $originalValue
  * @param array  $tokens
  *
  * @return array
  */
 private function buildTree(string $originalValue, array $tokens) : array
 {
     $tree = [];
     $functions = [];
     foreach ($tokens as $key => $value) {
         if ($this->tokenizer->isOpeningToken($value)) {
             $functions[$key] = null;
             // The value here is ignored
             continue;
         }
         if ($this->tokenizer->isClosingToken($value)) {
             if (false === $this->tokenizer->isTheLastFunction($functions)) {
                 end($functions);
                 $lastFunctionKey = key($functions);
                 if (null === $lastFunctionKey) {
                     throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
                 }
                 unset($functions[$lastFunctionKey]);
                 continue;
             }
             end($functions);
             $lastFunctionKey = key($functions);
             $this->append($tree, $tokens, $lastFunctionKey, $key);
             unset($functions[$lastFunctionKey]);
             continue;
         }
         if ($this->tokenizer->functionIsNotClosed($functions)) {
             continue;
         }
         $tree[] = $value;
     }
     if ([] !== $functions) {
         throw ExpressionLanguageExceptionFactory::createForMalformedFunction($originalValue);
     }
     return $tree;
 }