Example #1
0
 /**
  * @inheritdoc
  */
 public function render()
 {
     LoggerRegistry::debug('View::render()');
     $content = null;
     $this->rendering = true;
     if ($this->getTargetCount() === 2) {
         $request = $this->getRequest();
         // The arguments to the module definition are decorators, set them now
         call_user_func_array(array($this, 'activateDecorators'), $this->getTargetArguments(self::TARGET_LEVEL_MODULE));
         // Create a relevant context
         $context = $this->getEngine()->getViewFactory()->buildViewContext($this, $this->getRequest());
         // Check for and execute a target controller
         $targetController = $context->getTargetController($this, $request);
         $targetControllerResult = null;
         if (!is_null($targetController) && is_callable($targetController)) {
             $targetControllerResult = TypeUtilities::invokeCallable($targetController, null, array($this, $request), $this->getTargetArguments(self::TARGET_LEVEL_METHOD) ?: array());
         }
         // A result of false means don't render anything.
         if ($targetControllerResult !== false) {
             // Use the context to render the result
             $content = $context->render($this->getEngine()->getViewFactory()->getRendererRegistry(), $targetControllerResult) ?: '';
             // Decorate using active decorators
             foreach ($this->getActiveDecorators() as $active) {
                 $decorator = $this->getEngine()->getViewFactory()->getDecoratorRegistry()->getDecorator($active['name']);
                 $content = TypeUtilities::invokeCallable(array($decorator, 'decorate'), array($content), array($this, $request), $active['arguments']);
             }
         }
     } else {
         // Incorrect number of targets; exactly 2 expected
         $targets = $this->getTargetCount() === 1 ? 'target' : 'targets';
         throw new \LogicException(sprintf('Error in view script; exactly 2 targets expected ("$view->module()->method()"); %d %s encountered', $this->getTargetCount(), $targets));
     }
     // Ensure we are returning a string value
     $this->rendering = false;
     return $content ?: '';
 }
Example #2
0
 /**
  * @param StepInterface $step
  * @param Request $request
  * @param array $values
  *
  * @return Response|null
  */
 protected function executeProcessors(StepInterface $step, Request $request, array $values)
 {
     $response = null;
     foreach ($step->getProcessors() as $processor) {
         if (!$response instanceof Response && $processor->shouldExecute($values)) {
             try {
                 $response = TypeUtilities::invokeCallable($processor->getProcessorMethod(), null, array($request), $processor->getArgumentDefaults());
             } catch (\RuntimeException $exception) {
                 $this->handleProcessorException($processor, $exception);
             }
         }
     }
     return $response;
 }