예제 #1
0
 public function executeTwig($templateName, CodingContext $context, CodingExecutionResult $codingExecutionResult)
 {
     $errorHandler = TwigErrorHandler::register();
     try {
         $output = $this->getTwigEnvironment()->render($templateName, $context->getVariables());
         $codingExecutionResult->setOutput($output);
     } catch (TwigException $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $codingExecutionResult->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $codingExecutionResult->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
     return $codingExecutionResult;
 }
예제 #2
0
 /**
  * Execute the code and modify the CodingExecutionResult
  *
  * @param string $rootDir Where all the files have been placed
  * @param string $entryPointFilename
  * @param CodingContext $context
  * @param CodingExecutionResult $result
  */
 public function executeCode($rootDir, $entryPointFilename, CodingContext $context, CodingExecutionResult $result)
 {
     Debug::enable();
     $errorHandler = TwigErrorHandler::register();
     $twig = $this->getTwigEnvironment($rootDir);
     try {
         $output = $twig->render($entryPointFilename, $context->getVariables());
         $result->setOutput($output);
     } catch (TwigException $error) {
         $result->setLanguageError($error->getMessage());
     } catch (\Twig_Error $error) {
         // not doing anything special here... but in the future, we might
         // fetch more information about line numbers, etc
         $result->setLanguageError($error->getMessage());
     } catch (\Exception $error) {
         $result->setLanguageError($error->getMessage());
     }
     $errorHandler->restore();
 }
예제 #3
0
 /**
  * Execute the code and modify the CodingExecutionResult
  *
  * @param string $rootDir Where all the files have been placed
  * @param string $entryPointFilename
  * @param CodingContext $context
  * @param CodingExecutionResult $result
  */
 public function executeCode($rootDir, $entryPointFilename, CodingContext $context, CodingExecutionResult $result)
 {
     // makes all notices/warning into exceptions, which is good!
     Debug::enable();
     $languageError = null;
     extract($context->getVariables());
     ob_start();
     try {
         require $rootDir . '/' . $entryPointFilename;
     } catch (\ErrorException $e) {
         $message = sprintf('%s in %s on line %s', $e->getMessage(), $e->getFile(), $e->getLine());
         $languageError = $message;
     }
     $contents = ob_get_contents();
     ob_end_clean();
     $result->setOutput($contents);
     $result->setLanguageError(ActivityRunner::cleanError($languageError, $rootDir));
     $result->setDeclaredVariables(get_defined_vars());
 }