Example #1
0
 /**
  * (@inheritDoc}
  */
 public function createNormalizationStatement(Context $context, Expr $input)
 {
     $valuesVar = new Expr\Variable($context->getUniqueVariableName('values'));
     $statements = [new Expr\Assign($valuesVar, $this->createNormalizationArrayValueStatement())];
     $loopValueVar = new Expr\Variable($context->getUniqueVariableName('value'));
     $loopKeyVar = $this->createLoopKeyStatement($context);
     list($subStatements, $outputExpr) = $this->itemType->createNormalizationStatement($context, $loopValueVar);
     $loopStatements = array_merge($subStatements, [new Expr\Assign($this->createNormalizationLoopOutputAssignement($valuesVar, $loopKeyVar), $outputExpr)]);
     $statements[] = new Stmt\Foreach_($input, $loopValueVar, ['keyVar' => $loopKeyVar, 'stmts' => $loopStatements]);
     return [$statements, $valuesVar];
 }
Example #2
0
 /**
  * (@inheritDoc}
  */
 public function createNormalizationStatement(Context $context, Expr $input)
 {
     $output = new Expr\Variable($context->getUniqueVariableName('value'));
     $statements = [new Expr\Assign($output, $input)];
     foreach ($this->getTypes() as $type) {
         list($typeStatements, $typeOutput) = $type->createNormalizationStatement($context, $input);
         $statements[] = new Stmt\If_($type->createNormalizationConditionStatement($input), ['stmts' => array_merge($typeStatements, [new Expr\Assign($output, $typeOutput)])]);
     }
     return [$statements, $output];
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 protected function createLoopKeyStatement(Context $context)
 {
     return new Expr\Variable($context->getUniqueVariableName('key'));
 }