Example #1
0
 /**
  * Sets the imported file
  *
  * @param string $pathAbsolute The absolute path
  * @param ImportedFile $file The imported file
  * @param string $path The original path to import
  * @param FileInfo $currentFileInfo
  * @return Importer
  */
 public function setImportedFile($pathAbsolute, ImportedFile $file, $path, FileInfo $currentFileInfo)
 {
     $this->importedFiles[$pathAbsolute] = [$file, $path, $currentFileInfo];
     // save for source map generation
     $this->context->setFileContent($pathAbsolute, $file->getContent());
     return $this;
 }
Example #2
0
 /**
  * Parses a string.
  *
  * @param string $string The string to parse
  * @param string $filename The filename for reference (will be visible in the source map) or path to a fake file which directory will be used for imports
  * @param bool $returnRuleset Return the ruleset?
  *
  * @return $this
  */
 public function parseString($string, $filename = '__string_to_parse__', $returnRuleset = false)
 {
     $string = Util::normalizeString((string) $string);
     // we need unique key
     $key = sprintf('%s[__%s__]', $filename, md5($string));
     // create a dummy information, since we are not parsing a real file,
     // but a string coming from outside
     $this->context->setCurrentFile($filename);
     $importedFile = new ImportedFile($key, $string, time());
     // save information, so the exceptions can handle errors in the string
     // and source map is generated for the string
     $this->context->currentFileInfo->importedFile = $importedFile;
     $this->importer->setImportedFile($key, $importedFile, $key, $this->context->currentFileInfo);
     if ($this->context->sourceMap) {
         $this->context->setFileContent($key, $string);
     }
     $importedFile->setRuleset($ruleset = new RulesetNode([], $this->parse($string)));
     if ($returnRuleset) {
         return $ruleset;
     }
     $this->rules = array_merge($this->rules, $ruleset->rules);
     return $this;
 }