Exemplo n.º 1
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;
 }