Пример #1
0
 /**
  * @inherit()
  */
 public function parse($resource)
 {
     $this->environment->setSourceFile($resource);
     $loader = new \Twig_Loader_Filesystem(array($this->environment->getSourceDirectory()));
     $resource = str_replace($this->environment->getSourceDirectory(), '', $resource);
     $twig = new TwigEnvironment($loader);
     $twig->addExtension(new Extension($this->environment));
     $content = $twig->render($resource, array('app' => $this->environment));
     return $content;
 }
Пример #2
0
 /**
  * Will parse a given file, and will write it to output directory
  *
  * @param string $resource filename of source file
  * @param string $output directory of destination
  * @throws \Exception
  */
 public function parse($resource, $output)
 {
     printf('file %s' . PHP_EOL, $resource);
     $pathinfo = pathinfo($resource);
     $extension = $pathinfo['extension'];
     $this->environment->setSourceFile($resource);
     $parser = $this->configuration->getParserForFileExtension($extension);
     if (!$parser instanceof ParserInterface) {
         throw new \Exception('No parser found. Have you initialized any plugins?');
     }
     if ($parser instanceof HasEnvironmentInterface) {
         $parser->setEnvironment($this->environment);
     }
     $content = $parser->parse($resource);
     $output = $parser->getOutputFilename($output);
     file_put_contents($output, $content);
 }