vendor/doctrine/orm/lib/Doctrine/ORM/Query/TreeWalkerChain.php line 97

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\ORM\Query;
  4. use Doctrine\ORM\Mapping\ClassMetadata;
  5. use function array_diff;
  6. use function array_keys;
  7. /**
  8.  * Represents a chain of tree walkers that modify an AST and finally emit output.
  9.  * Only the last walker in the chain can emit output. Any previous walkers can modify
  10.  * the AST to influence the final output produced by the last walker.
  11.  */
  12. class TreeWalkerChain implements TreeWalker
  13. {
  14.     /**
  15.      * The tree walkers.
  16.      *
  17.      * @var TreeWalker[]
  18.      * @psalm-var TreeWalkerChainIterator
  19.      */
  20.     private $_walkers;
  21.     /**
  22.      * The query components of the original query (the "symbol table") that was produced by the Parser.
  23.      *
  24.      * @var array<string, array<string, mixed>>
  25.      * @psalm-var array<string, array{
  26.      *                metadata: ClassMetadata,
  27.      *                parent: string,
  28.      *                relation: mixed[],
  29.      *                map: mixed,
  30.      *                nestingLevel: int,
  31.      *                token: array
  32.      *            }>
  33.      */
  34.     private $_queryComponents;
  35.     /**
  36.      * Returns the internal queryComponents array.
  37.      *
  38.      * {@inheritDoc}
  39.      */
  40.     public function getQueryComponents()
  41.     {
  42.         return $this->_queryComponents;
  43.     }
  44.     /**
  45.      * {@inheritdoc}
  46.      *
  47.      * @return void
  48.      */
  49.     public function setQueryComponent($dqlAlias, array $queryComponent)
  50.     {
  51.         $requiredKeys = ['metadata''parent''relation''map''nestingLevel''token'];
  52.         if (array_diff($requiredKeysarray_keys($queryComponent))) {
  53.             throw QueryException::invalidQueryComponent($dqlAlias);
  54.         }
  55.         $this->_queryComponents[$dqlAlias] = $queryComponent;
  56.     }
  57.     /**
  58.      * {@inheritdoc}
  59.      */
  60.     public function __construct($query$parserResult, array $queryComponents)
  61.     {
  62.         $this->_queryComponents $queryComponents;
  63.         $this->_walkers         = new TreeWalkerChainIterator($this$query$parserResult);
  64.     }
  65.     /**
  66.      * Adds a tree walker to the chain.
  67.      *
  68.      * @param string $walkerClass The class of the walker to instantiate.
  69.      *
  70.      * @return void
  71.      */
  72.     public function addTreeWalker($walkerClass)
  73.     {
  74.         $this->_walkers[] = $walkerClass;
  75.     }
  76.     /**
  77.      * {@inheritdoc}
  78.      *
  79.      * @return void
  80.      */
  81.     public function walkSelectStatement(AST\SelectStatement $AST)
  82.     {
  83.         foreach ($this->_walkers as $walker) {
  84.             $walker->walkSelectStatement($AST);
  85.             $this->_queryComponents $walker->getQueryComponents();
  86.         }
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      *
  91.      * @return void
  92.      */
  93.     public function walkSelectClause($selectClause)
  94.     {
  95.         foreach ($this->_walkers as $walker) {
  96.             $walker->walkSelectClause($selectClause);
  97.         }
  98.     }
  99.     /**
  100.      * {@inheritdoc}
  101.      *
  102.      * @return void
  103.      */
  104.     public function walkFromClause($fromClause)
  105.     {
  106.         foreach ($this->_walkers as $walker) {
  107.             $walker->walkFromClause($fromClause);
  108.         }
  109.     }
  110.     /**
  111.      * {@inheritdoc}
  112.      *
  113.      * @return void
  114.      */
  115.     public function walkFunction($function)
  116.     {
  117.         foreach ($this->_walkers as $walker) {
  118.             $walker->walkFunction($function);
  119.         }
  120.     }
  121.     /**
  122.      * {@inheritdoc}
  123.      *
  124.      * @return void
  125.      */
  126.     public function walkOrderByClause($orderByClause)
  127.     {
  128.         foreach ($this->_walkers as $walker) {
  129.             $walker->walkOrderByClause($orderByClause);
  130.         }
  131.     }
  132.     /**
  133.      * {@inheritdoc}
  134.      *
  135.      * @return void
  136.      */
  137.     public function walkOrderByItem($orderByItem)
  138.     {
  139.         foreach ($this->_walkers as $walker) {
  140.             $walker->walkOrderByItem($orderByItem);
  141.         }
  142.     }
  143.     /**
  144.      * {@inheritdoc}
  145.      *
  146.      * @return void
  147.      */
  148.     public function walkHavingClause($havingClause)
  149.     {
  150.         foreach ($this->_walkers as $walker) {
  151.             $walker->walkHavingClause($havingClause);
  152.         }
  153.     }
  154.     /**
  155.      * {@inheritdoc}
  156.      *
  157.      * @return void
  158.      */
  159.     public function walkJoin($join)
  160.     {
  161.         foreach ($this->_walkers as $walker) {
  162.             $walker->walkJoin($join);
  163.         }
  164.     }
  165.     /**
  166.      * {@inheritdoc}
  167.      *
  168.      * @return void
  169.      */
  170.     public function walkSelectExpression($selectExpression)
  171.     {
  172.         foreach ($this->_walkers as $walker) {
  173.             $walker->walkSelectExpression($selectExpression);
  174.         }
  175.     }
  176.     /**
  177.      * {@inheritdoc}
  178.      *
  179.      * @return void
  180.      */
  181.     public function walkQuantifiedExpression($qExpr)
  182.     {
  183.         foreach ($this->_walkers as $walker) {
  184.             $walker->walkQuantifiedExpression($qExpr);
  185.         }
  186.     }
  187.     /**
  188.      * {@inheritdoc}
  189.      *
  190.      * @return void
  191.      */
  192.     public function walkSubselect($subselect)
  193.     {
  194.         foreach ($this->_walkers as $walker) {
  195.             $walker->walkSubselect($subselect);
  196.         }
  197.     }
  198.     /**
  199.      * {@inheritdoc}
  200.      *
  201.      * @return void
  202.      */
  203.     public function walkSubselectFromClause($subselectFromClause)
  204.     {
  205.         foreach ($this->_walkers as $walker) {
  206.             $walker->walkSubselectFromClause($subselectFromClause);
  207.         }
  208.     }
  209.     /**
  210.      * {@inheritdoc}
  211.      *
  212.      * @return void
  213.      */
  214.     public function walkSimpleSelectClause($simpleSelectClause)
  215.     {
  216.         foreach ($this->_walkers as $walker) {
  217.             $walker->walkSimpleSelectClause($simpleSelectClause);
  218.         }
  219.     }
  220.     /**
  221.      * {@inheritdoc}
  222.      *
  223.      * @return void
  224.      */
  225.     public function walkSimpleSelectExpression($simpleSelectExpression)
  226.     {
  227.         foreach ($this->_walkers as $walker) {
  228.             $walker->walkSimpleSelectExpression($simpleSelectExpression);
  229.         }
  230.     }
  231.     /**
  232.      * {@inheritdoc}
  233.      *
  234.      * @return void
  235.      */
  236.     public function walkAggregateExpression($aggExpression)
  237.     {
  238.         foreach ($this->_walkers as $walker) {
  239.             $walker->walkAggregateExpression($aggExpression);
  240.         }
  241.     }
  242.     /**
  243.      * {@inheritdoc}
  244.      *
  245.      * @return void
  246.      */
  247.     public function walkGroupByClause($groupByClause)
  248.     {
  249.         foreach ($this->_walkers as $walker) {
  250.             $walker->walkGroupByClause($groupByClause);
  251.         }
  252.     }
  253.     /**
  254.      * {@inheritdoc}
  255.      *
  256.      * @return void
  257.      */
  258.     public function walkGroupByItem($groupByItem)
  259.     {
  260.         foreach ($this->_walkers as $walker) {
  261.             $walker->walkGroupByItem($groupByItem);
  262.         }
  263.     }
  264.     /**
  265.      * {@inheritdoc}
  266.      *
  267.      * @return void
  268.      */
  269.     public function walkUpdateStatement(AST\UpdateStatement $AST)
  270.     {
  271.         foreach ($this->_walkers as $walker) {
  272.             $walker->walkUpdateStatement($AST);
  273.         }
  274.     }
  275.     /**
  276.      * {@inheritdoc}
  277.      *
  278.      * @return void
  279.      */
  280.     public function walkDeleteStatement(AST\DeleteStatement $AST)
  281.     {
  282.         foreach ($this->_walkers as $walker) {
  283.             $walker->walkDeleteStatement($AST);
  284.         }
  285.     }
  286.     /**
  287.      * {@inheritdoc}
  288.      *
  289.      * @return void
  290.      */
  291.     public function walkDeleteClause(AST\DeleteClause $deleteClause)
  292.     {
  293.         foreach ($this->_walkers as $walker) {
  294.             $walker->walkDeleteClause($deleteClause);
  295.         }
  296.     }
  297.     /**
  298.      * {@inheritdoc}
  299.      *
  300.      * @return void
  301.      */
  302.     public function walkUpdateClause($updateClause)
  303.     {
  304.         foreach ($this->_walkers as $walker) {
  305.             $walker->walkUpdateClause($updateClause);
  306.         }
  307.     }
  308.     /**
  309.      * {@inheritdoc}
  310.      *
  311.      * @return void
  312.      */
  313.     public function walkUpdateItem($updateItem)
  314.     {
  315.         foreach ($this->_walkers as $walker) {
  316.             $walker->walkUpdateItem($updateItem);
  317.         }
  318.     }
  319.     /**
  320.      * {@inheritdoc}
  321.      *
  322.      * @return void
  323.      */
  324.     public function walkWhereClause($whereClause)
  325.     {
  326.         foreach ($this->_walkers as $walker) {
  327.             $walker->walkWhereClause($whereClause);
  328.         }
  329.     }
  330.     /**
  331.      * {@inheritdoc}
  332.      *
  333.      * @return void
  334.      */
  335.     public function walkConditionalExpression($condExpr)
  336.     {
  337.         foreach ($this->_walkers as $walker) {
  338.             $walker->walkConditionalExpression($condExpr);
  339.         }
  340.     }
  341.     /**
  342.      * {@inheritdoc}
  343.      *
  344.      * @return void
  345.      */
  346.     public function walkConditionalTerm($condTerm)
  347.     {
  348.         foreach ($this->_walkers as $walker) {
  349.             $walker->walkConditionalTerm($condTerm);
  350.         }
  351.     }
  352.     /**
  353.      * {@inheritdoc}
  354.      *
  355.      * @return void
  356.      */
  357.     public function walkConditionalFactor($factor)
  358.     {
  359.         foreach ($this->_walkers as $walker) {
  360.             $walker->walkConditionalFactor($factor);
  361.         }
  362.     }
  363.     /**
  364.      * {@inheritdoc}
  365.      *
  366.      * @return void
  367.      */
  368.     public function walkConditionalPrimary($condPrimary)
  369.     {
  370.         foreach ($this->_walkers as $walker) {
  371.             $walker->walkConditionalPrimary($condPrimary);
  372.         }
  373.     }
  374.     /**
  375.      * {@inheritdoc}
  376.      *
  377.      * @return void
  378.      */
  379.     public function walkExistsExpression($existsExpr)
  380.     {
  381.         foreach ($this->_walkers as $walker) {
  382.             $walker->walkExistsExpression($existsExpr);
  383.         }
  384.     }
  385.     /**
  386.      * {@inheritdoc}
  387.      *
  388.      * @return void
  389.      */
  390.     public function walkCollectionMemberExpression($collMemberExpr)
  391.     {
  392.         foreach ($this->_walkers as $walker) {
  393.             $walker->walkCollectionMemberExpression($collMemberExpr);
  394.         }
  395.     }
  396.     /**
  397.      * {@inheritdoc}
  398.      *
  399.      * @return void
  400.      */
  401.     public function walkEmptyCollectionComparisonExpression($emptyCollCompExpr)
  402.     {
  403.         foreach ($this->_walkers as $walker) {
  404.             $walker->walkEmptyCollectionComparisonExpression($emptyCollCompExpr);
  405.         }
  406.     }
  407.     /**
  408.      * {@inheritdoc}
  409.      *
  410.      * @return void
  411.      */
  412.     public function walkNullComparisonExpression($nullCompExpr)
  413.     {
  414.         foreach ($this->_walkers as $walker) {
  415.             $walker->walkNullComparisonExpression($nullCompExpr);
  416.         }
  417.     }
  418.     /**
  419.      * {@inheritdoc}
  420.      *
  421.      * @return void
  422.      */
  423.     public function walkInExpression($inExpr)
  424.     {
  425.         foreach ($this->_walkers as $walker) {
  426.             $walker->walkInExpression($inExpr);
  427.         }
  428.     }
  429.     /**
  430.      * {@inheritdoc}
  431.      *
  432.      * @return void
  433.      */
  434.     public function walkInstanceOfExpression($instanceOfExpr)
  435.     {
  436.         foreach ($this->_walkers as $walker) {
  437.             $walker->walkInstanceOfExpression($instanceOfExpr);
  438.         }
  439.     }
  440.     /**
  441.      * {@inheritdoc}
  442.      *
  443.      * @return void
  444.      */
  445.     public function walkLiteral($literal)
  446.     {
  447.         foreach ($this->_walkers as $walker) {
  448.             $walker->walkLiteral($literal);
  449.         }
  450.     }
  451.     /**
  452.      * {@inheritdoc}
  453.      *
  454.      * @return void
  455.      */
  456.     public function walkBetweenExpression($betweenExpr)
  457.     {
  458.         foreach ($this->_walkers as $walker) {
  459.             $walker->walkBetweenExpression($betweenExpr);
  460.         }
  461.     }
  462.     /**
  463.      * {@inheritdoc}
  464.      *
  465.      * @return void
  466.      */
  467.     public function walkLikeExpression($likeExpr)
  468.     {
  469.         foreach ($this->_walkers as $walker) {
  470.             $walker->walkLikeExpression($likeExpr);
  471.         }
  472.     }
  473.     /**
  474.      * {@inheritdoc}
  475.      *
  476.      * @return void
  477.      */
  478.     public function walkStateFieldPathExpression($stateFieldPathExpression)
  479.     {
  480.         foreach ($this->_walkers as $walker) {
  481.             $walker->walkStateFieldPathExpression($stateFieldPathExpression);
  482.         }
  483.     }
  484.     /**
  485.      * {@inheritdoc}
  486.      *
  487.      * @return void
  488.      */
  489.     public function walkComparisonExpression($compExpr)
  490.     {
  491.         foreach ($this->_walkers as $walker) {
  492.             $walker->walkComparisonExpression($compExpr);
  493.         }
  494.     }
  495.     /**
  496.      * {@inheritdoc}
  497.      *
  498.      * @return void
  499.      */
  500.     public function walkInputParameter($inputParam)
  501.     {
  502.         foreach ($this->_walkers as $walker) {
  503.             $walker->walkInputParameter($inputParam);
  504.         }
  505.     }
  506.     /**
  507.      * {@inheritdoc}
  508.      *
  509.      * @return void
  510.      */
  511.     public function walkArithmeticExpression($arithmeticExpr)
  512.     {
  513.         foreach ($this->_walkers as $walker) {
  514.             $walker->walkArithmeticExpression($arithmeticExpr);
  515.         }
  516.     }
  517.     /**
  518.      * {@inheritdoc}
  519.      *
  520.      * @return void
  521.      */
  522.     public function walkArithmeticTerm($term)
  523.     {
  524.         foreach ($this->_walkers as $walker) {
  525.             $walker->walkArithmeticTerm($term);
  526.         }
  527.     }
  528.     /**
  529.      * {@inheritdoc}
  530.      *
  531.      * @return void
  532.      */
  533.     public function walkStringPrimary($stringPrimary)
  534.     {
  535.         foreach ($this->_walkers as $walker) {
  536.             $walker->walkStringPrimary($stringPrimary);
  537.         }
  538.     }
  539.     /**
  540.      * {@inheritdoc}
  541.      *
  542.      * @return void
  543.      */
  544.     public function walkArithmeticFactor($factor)
  545.     {
  546.         foreach ($this->_walkers as $walker) {
  547.             $walker->walkArithmeticFactor($factor);
  548.         }
  549.     }
  550.     /**
  551.      * {@inheritdoc}
  552.      *
  553.      * @return void
  554.      */
  555.     public function walkSimpleArithmeticExpression($simpleArithmeticExpr)
  556.     {
  557.         foreach ($this->_walkers as $walker) {
  558.             $walker->walkSimpleArithmeticExpression($simpleArithmeticExpr);
  559.         }
  560.     }
  561.     /**
  562.      * {@inheritdoc}
  563.      *
  564.      * @return void
  565.      */
  566.     public function walkPathExpression($pathExpr)
  567.     {
  568.         foreach ($this->_walkers as $walker) {
  569.             $walker->walkPathExpression($pathExpr);
  570.         }
  571.     }
  572.     /**
  573.      * {@inheritdoc}
  574.      *
  575.      * @return void
  576.      */
  577.     public function walkResultVariable($resultVariable)
  578.     {
  579.         foreach ($this->_walkers as $walker) {
  580.             $walker->walkResultVariable($resultVariable);
  581.         }
  582.     }
  583.     /**
  584.      * {@inheritdoc}
  585.      *
  586.      * @return void
  587.      */
  588.     public function getExecutor($AST)
  589.     {
  590.     }
  591. }