Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Parser.php
Go to the documentation of this file.
1 <?php
7 
12 class Parser
13 {
19  protected $_operations = ['-', '+', '/', '*'];
20 
27  public function parseExpression($expression)
28  {
29  $stack = [];
30  $expression = trim($expression);
31  foreach ($this->_operations as $operation) {
32  $splittedExpr = preg_split('/\\' . $operation . '/', $expression, -1, PREG_SPLIT_DELIM_CAPTURE);
33  $count = count($splittedExpr);
34  if ($count > 1) {
35  for ($i = 0; $i < $count; $i++) {
36  $stack = array_merge($stack, $this->parseExpression($splittedExpr[$i]));
37  if ($i > 0) {
38  $stack[] = $operation;
39  }
40  }
41  break;
42  }
43  }
44  return empty($stack) ? [$expression] : $stack;
45  }
46 
53  public function isOperation($operation)
54  {
55  return in_array($operation, $this->_operations);
56  }
57 }
$count
Definition: recent.phtml:13
$i
Definition: gallery.phtml:31