: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Nextend\Framework\Cache;
use Nextend\Framework\Filesystem\Filesystem;
use Nextend\Framework\Misc\HttpClient;
class CacheGoogleFont extends AbstractCache {
protected $_storageEngine = 'filesystem';
public function __construct() {
parent::__construct('googlefonts', true);
* @return boolean|string The path of the cached file
public function makeCache($url, $extension) {
$hash = $this->generateHash($url);
$fileNameWithExtension = $fileName . '.' . $extension;
$isCached = $this->exists($fileNameWithExtension);
if (!$this->testManifestFile($fileName)) {
$cssContent = HttpClient::get($url);
if ($extension === 'css') {
foreach ($fontExtensions as $this->fontExtension) {
$cssContent = preg_replace_callback('/url\(["\']?(.*?\.' . $this->fontExtension . ')["\']?\)/i', function ($matches) {
$cache = new CacheGoogleFont();
$path = $cache->makeCache($url, $this->fontExtension);
$url = Filesystem::pathToAbsoluteURL($path);
return 'url(' . $url . ')';
$this->set($fileNameWithExtension, $cssContent);
$this->createManifestFile($fileName);
return $this->getPath($fileNameWithExtension);
private function generateHash($url) {
protected function testManifestFile($fileName) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$manifestData = json_decode($this->get($manifestKey), true);
if ($manifestData['mtime'] > strtotime('-30 days')) {
protected function createManifestFile($fileName) {
$this->set($this->getManifestKey($fileName), json_encode($this->getManifestData()));
private function getManifestData() {
protected function getManifestKey($fileName) {
return $fileName . '.manifest';