Example #1
0
 /**
  * @dataProvider sourcesProvider
  */
 public function testParses($source)
 {
     $context = new ParserContext();
     $context->setString($source)->setBaseDirectory(__DIR__);
     $template = $context->parse();
     $this->assertInstanceOf('\\Skrz\\Templating\\Engine\\AST\\TemplateNode', $template);
 }
 public function __construct($context, $reason = null)
 {
     $this->context = $context;
     if (is_object($reason) || is_array($reason)) {
         $this->info = (object) $reason;
     }
     parent::__construct("Parsing failed for " . $this->context->getFile() . ($this->info !== null ? " @ " . $this->info->line . ":" . $this->info->column . ", expected " . implode(", ", $this->info->expected) : " - " . $reason));
 }
Example #3
0
 public function engineProvider()
 {
     $simpleClassName = basename(str_replace("\\", "/", __CLASS__));
     self::$temporaryDirectory = __DIR__ . "/{$simpleClassName}.d";
     @mkdir(self::$temporaryDirectory, 0777);
     // SMARTY
     $smarty = new \Smarty();
     $smarty->template_dir = __DIR__;
     $smarty->compile_dir = self::$temporaryDirectory;
     $smarty->default_modifiers = array('escape:"html"');
     // SKRZ
     $parserContext = new ParserContext();
     $parserContext->setFile("Page.tpl")->addPath(__DIR__);
     $compilerContext = new CompilerContext();
     $compilerContext->setParserContext($parserContext)->setNamespace("Skrz\\Templating\\Engine")->setClassName("PageView")->setTemplate($parserContext->parse())->setAppPath(__DIR__ . "/../../../..")->setOutputFileName(self::$temporaryDirectory . "/PageView.php");
     file_put_contents(self::$temporaryDirectory . "/PageView.php", $compilerContext->compile());
     require_once self::$temporaryDirectory . "/PageView.php";
     $skrz = new \Skrz\Templating\Engine\PageView();
     return array(array("SMARTY", $smarty, 10), array("SKRZ", $skrz, 10), array("SMARTY", $smarty, 100), array("SKRZ", $skrz, 100), array("SMARTY", $smarty, 1000), array("SKRZ", $skrz, 1000), array("SMARTY", $smarty, 10000), array("SKRZ", $skrz, 10000));
 }
Example #4
0
 public function resolveFileName()
 {
     $path = $this->path;
     if (!in_array($this->baseDirectory, $this->path)) {
         $path[] = $this->baseDirectory;
     }
     if ($this->string === null) {
         if ($this->file === null || $this->file === self::STRING_PSEUDO_FILE) {
             throw new ParserException($this, "either string or file has to be supplied to context");
         }
         $fileName = null;
         if ($this->file[0] === "/") {
             $fileName = $this->file;
         } elseif ($this->file[0] === ".") {
             if (!$this->parent) {
                 throw new ParserException($this, "Relative file '{$this->file}' and no parent context.");
             }
             $fileName = dirname($this->parent->resolveFileName()) . "/" . $this->file;
         } else {
             foreach ($path as $directory) {
                 if (file_exists($directory . "/" . $this->file)) {
                     $fileName = $directory . "/" . $this->file;
                     break;
                 }
             }
             if ($fileName === null) {
                 throw new ParserException($this, "File '{$this->file}' was not found in path.");
             }
         }
         $this->fileName = $fileName;
         if (!in_array($this->fileName, $this->allFileNames)) {
             $this->allFileNames[] = $this->fileName;
         }
     }
     if ($this->file === null) {
         $this->file = $this->fileName = self::STRING_PSEUDO_FILE;
     }
     return $this->fileName;
 }