/** * Post processes the parsed CSSDocument object. * * Handles removal of ignored values and resolving of @import rules. * * @todo Should CSSIgnoredValue exist ? * Another solution would be to add values only if they are not === null, * i.e. in CSSList::append(), CSSRule::addValue() etc... **/ private function postParse($oDoc) { $aCharsets = array(); $aImports = array(); $aContents = $oDoc->getContents(); foreach ($aContents as $i => $oItem) { if ($oItem instanceof CSSIgnoredValue) { unset($aContents[$i]); } else { if ($oItem instanceof CSSCharset) { $aCharsets[] = $oItem; unset($aContents[$i]); } else { if ($oItem instanceof CSSImport) { $aImports[] = $oItem; unset($aContents[$i]); } } } } $aImportedItems = array(); $aImportOptions = array_merge($this->getOptions(), array('output_encoding' => $this->sCharset, 'base_url' => null)); foreach ($aImports as $oImport) { if ($this->getOption('resolve_imports')) { $parser = new CSSParser($aImportOptions); $sPath = $oImport->getLocation()->getURL()->getString(); $bIsAbsUrl = CSSUrlUtils::isAbsUrl($sPath); if ($this->sImportMode == self::IMPORT_URL || $bIsAbsUrl) { if (!in_array($sPath, $this->aLoadedFiles)) { $oImportedDoc = $parser->parseURL($sPath, $this->aLoadedFiles); $this->aLoadedFiles = $parser->getLoadedFiles(); $aImportedContents = $oImportedDoc->getContents(); } } else { if ($this->sImportMode == self::IMPORT_FILE) { $sPath = realpath($sPath); if (!in_array($sPath, $this->aLoadedFiles)) { $oImportedDoc = $parser->parseFile($sPath, $this->aLoadedFiles); $this->aLoadedFiles = $parser->getLoadedFiles(); $aImportedContents = $oImportedDoc->getContents(); } } } if ($oImport->getMediaQuery() !== null) { $sMediaQuery = $oImport->getMediaQuery(); $oMediaQuery = new CSSMediaQuery(); $oMediaQuery->setQuery($sMediaQuery); $oMediaQuery->setContents($aImportedContents); $aImportedContents = array($oMediaQuery); } } else { $aImportedContents = array($oImport); } $aImportedItems = array_merge($aImportedItems, $aImportedContents); } $aContents = array_merge($aImportedItems, $aContents); if (isset($aCharsets[0])) { array_unshift($aContents, $aCharsets[0]); } $oDoc->setContents($aContents); }