/** * Replace resources links by one link on file, that contains resources links data * @param $html * @throws SpeedOut_DataHandler_Combiner_Exception_PathNotFound * @return null */ public function handleData(&$html) { $this->handlingProcessData = array(); $linksNodes = $this->getLinksNodes($html); if ($linksNodes) { $linksHash = $this->getLinksHash(array_keys($linksNodes)); // combine and store links data if (!$this->storage->isStored($linksHash)) { $combinedData = ''; $baseDir = $this->getLinksBaseDir(); foreach ($linksNodes as $link => $data) { $linkPath = SpeedOut_Utils::getLinkPath(SpeedOut_Utils::getRealLink(html_entity_decode($link), $baseDir), $baseDir); $linkData = $this->getLinkData($linkPath); $combinedData .= $this->getCombinedDataPart($linkData, $linkPath); } $this->handleCombinedData($combinedData); $this->storage->store($linksHash, $combinedData); } $html = str_replace($linksNodes, '', $html); $this->addStringInCommonPlaceholder($html, $this->getCommonLinkHtml($this->storage->getUrl($linksHash))); } }
/** * @dataProvider getLinkPathProvider */ public function testGetLinkPath($baseDir, $link, $expectedPath) { $this->assertEquals($expectedPath, SpeedOut_Utils::getLinkPath($link, $baseDir)); }
protected function replaceImportsInLinkedData(&$linkedFileData, $linkPath) { $linkBaseDir = dirname($linkPath); $importsRegexp = '~@import\\s*?["\'](.*?)["\'].*?;~'; $replaceLinksDataRegexps = array(); $importedLinksPaths =& $this->handlingProcessData[__METHOD__ . 'importsLinksPaths']; if (!$importedLinksPaths) { $importedLinksPaths = array(); } if (SpeedOut_Utils::safePregMatchAll($importsRegexp, $linkedFileData, $m)) { foreach ($m[1] as $i => $importLink) { $importLinkPath = SpeedOut_Utils::getLinkPath($importLink, $linkBaseDir); if (!SpeedOut_Utils::isExternalLink($importLink) && !in_array($importLinkPath, $importedLinksPaths) && $this->isValidInternalLink($importLinkPath, 'combined CSS data')) { $importedLinksPaths[] = $importLinkPath; $replaceLinksDataRegexps['~' . preg_quote($m[0][$i], '~') . '~'] = $this->getLinkData($importLinkPath); } } } foreach ($replaceLinksDataRegexps as $regexp => $replace) { $linkedFileData = SpeedOut_Utils::safePregReplace($regexp, $replace, $linkedFileData, 1); } $linkedFileData = SpeedOut_Utils::safePregReplace($importsRegexp, '', $linkedFileData); }