: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return $this->addCSSFileWithContent($file, file_get_contents($file));
private function addCSSFileWithContent($file, $fileContent) {
$path = 'css/' . basename($file);
$this->basePath = dirname($file);
$this->baseUrl = Filesystem::pathToAbsoluteURL($this->basePath);
$fileContent = preg_replace_callback('#url\([\'"]?([^"\'\)]+)[\'"]?\)#', array(
$this->files[$path] = $fileContent;
return Html::style($path, true, array(
'media' => 'screen, print'
public function replaceCSSImage($matches) {
if (substr($matches[1], 0, 5) == 'data:') return $matches[0];
if (substr($matches[1], 0, 4) == 'http') {
$exploded = explode('?', $matches[1]);
$path = ResourceTranslator::toPath(ResourceTranslator::urlToResource($exploded[0]));
if (strpos($path, $this->basePath) === 0) {
$exploded = explode('?', $matches[1]);
return str_replace($matches[1], 'assets/' . $this->addFile($path) . '?' . $exploded[1], $matches[0]);
if (substr($matches[1], 0, 2) == '//') return $matches[0];
$exploded = explode('?', $matches[1]);
$path = realpath($this->basePath . '/' . $exploded[0]);
return 'url(' . str_replace(array(
), '//', $this->baseUrl) . '/' . $matches[1] . ')';
return str_replace($matches[1], 'assets/' . $this->addFile($path), $matches[0]);
protected function addFile($path) {
$path = Filesystem::convertToRealDirectorySeparator($path);
if (!isset($this->imageTranslation[$path])) {
$fileName = strtolower(basename($path));
while (in_array($fileName, $this->usedNames)) {
$fileName = $this->uniqueCounter . $fileName;
$this->usedNames[] = $fileName;
$this->files['css/assets/' . $fileName] = file_get_contents($path);
$this->imageTranslation[$path] = $fileName;
$fileName = $this->imageTranslation[$path];