Example #1
0
 public function __invoke(Evaluate\Chunk $chunk, Evaluate\Context $context, Evaluate\Bodies $bodies, Evaluate\Parameters $params)
 {
     //evaluate key here
     if (!isset($params->{'key'})) {
         $chunk->setError('Key parameter required');
     }
     $key = $params->{'key'};
     //just eval body with some special state
     return $chunk->render($bodies->block, $context->pushState(new Evaluate\State((object) ['__selectInfo' => (object) ['selectComparisonSatisfied' => false, 'key' => $key]])));
 }
Example #2
0
 public function __invoke(Evaluate\Chunk $chunk, Evaluate\Context $context, Evaluate\Bodies $bodies)
 {
     $result = $context->get('key');
     if ($result === NULL) {
         $chunk->setError('Key required');
     }
     $method = $context->get('method');
     if ($method === NULL) {
         $chunk->setError('Method required');
     }
     $operand = $context->get('operand');
     switch ($method) {
         case 'add':
             $result += $operand;
             break;
         case 'subtract':
             $result -= $operand;
             break;
         case 'multiply':
             $result *= $operand;
             break;
         case 'divide':
             $result /= $operand;
             break;
         case 'mod':
             $result %= $operand;
             break;
         case 'abs':
             $result = abs($result);
             break;
         case 'floor':
             $result = floor($result);
             break;
         case 'ceil':
             $result = ceil($result);
             break;
         default:
             $chunk->setError('Unknown method: ' . $method);
     }
     //no bodies means just write
     if ($bodies == NULL || $bodies->block == NULL) {
         return $chunk->write($result);
     } else {
         //just eval body with some special state
         return $chunk->render($bodies->block, $context->pushState(new Evaluate\State((object) ['__selectInfo' => (object) ['selectComparisonSatisfied' => false, 'key' => $result]])));
     }
 }