Author: Elliot Levin (elliotlevin@hotmail.com)
Inheritance: extends MutatorOperation
 public function visitApply(Operations\Apply $operation)
 {
     $function = $operation->getMutatorFunction();
     $parameters = $function->getParameters();
     // Ensure that calls to apply take the row array by reference
     // because the function will not actually modify the original
     // array if running in PHP.
     if (!$parameters->hasValue() || !$parameters->getValue()->isPassedByReference()) {
         throw new PinqDemoSqlException('Call to ->apply(function): must take the first parameter by reference.');
     }
     $setters = [];
     foreach ($function->getBodyExpressionsUntilReturn() as $expression) {
         // Ensure matches: $row['column'] = ...
         if (!$expression instanceof O\AssignmentExpression || !$expression->getAssignTo() instanceof O\IndexExpression || !$expression->getAssignTo()->getIndex() instanceof O\ValueExpression || !$expression->getAssignTo()->getValue()->equals($parameters->getValue()->asVariable())) {
             throw new PinqDemoSqlException("Call to ->apply(...) must only contain statements in the form \$row['column'] = value, invalid statement found: {$expression->compileDebug()}");
         }
         // Convert any compound assignment operators into expanded form:
         // x += y becomes x = x + y
         $expression = $expression->toBinaryOperationEquivalent();
         $column = $expression->getAssignTo()->getIndex()->getValue();
         $setterSql = $this->compilation->expressionCompiler->compile($expression->getAssignmentValue(), $function);
         $setters[$column] = $setterSql;
     }
     $this->compileUpdate($setters);
 }
 public function visitApply(Operations\Apply $operation)
 {
     $this->collection->apply($this->parameters[$operation->getMutatorFunction()->getCallableId()]);
 }
Exemple #3
0
 public function visitApply(Operations\Apply $operation)
 {
     $this->compilation->append('Update the values according to the function: ');
     $this->compilation->appendFunction($operation->getMutatorFunction());
 }
 public function visitApply(Operations\Apply $operation)
 {
     return parent::visitApply($operation->update($this->expressionProcessor->processFunction($operation->getMutatorFunction())));
 }