public function testToUrl() { self::assertEquals('/path/to/url', PathHelper::toURL('/var/www/example.com/public/path/to/url', '/var/www/example.com/public/')); self::assertEquals('/path/to/url', PathHelper::toURL('/var/www/example.com/public/path/to/url', '/var/www/example.com/public/')); self::assertEquals('/path/to/url', PathHelper::toURL('/var/www/example.com/public/path/to/url', '/var/www/example.com/public')); self::assertEquals('/path/to/url', PathHelper::toURL('C:\\www\\example.com\\public\\path\\to\\url', 'C:\\www\\example.com\\public\\')); self::assertEquals('/path/to/url', PathHelper::toURL('/var/www/example.com/public/path/to/url', '\\var\\www\\example.com\\public')); }
protected function generateAssetsTest(AssetsCollection $assets_collection, $compiled_path, $compress = true) { $config = $this->container['assets']; if ($compress) { $dump = $assets_collection->dumpCompress($config['path']); } else { $dump = $assets_collection->dump($config['path']); } if (false === @file_put_contents($compiled_path, $dump)) { throw new \RuntimeException('Unable to write file ' . $compiled_path); } return PathHelper::toURL($compiled_path, PUBLIC_PATH); }
/** * @param string $assets_dir * * @return string * * @throws \RuntimeException */ protected function replaceRelativeLinks($assets_dir) { $file = fopen($this->getPath(), 'rb'); $asset_text = fread($file, filesize($this->getPath())); fclose($file); chdir(dirname($this->getPath())); $urls_old = []; $urls_new = []; preg_match_all('#url\\(([\'"]?[^/\'"][^\'"]*[\'"]?)\\)#imU', $asset_text, $urls_old); $urls = array_unique($urls_old[1]); foreach ($urls as $url) { $urls_new[] = "'" . PathHelper::toURL(realpath(trim($url, '"\'')), PUBLIC_PATH) . "'"; } $asset_text = str_replace($urls, $urls_new, $asset_text); $this->temp_path = $assets_dir . basename($this->getPath()); if (false === @file_put_contents($this->temp_path, $asset_text)) { throw new \RuntimeException('Unable to write file ' . $this->temp_path); } return $this->temp_path; }