: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace Nextend\Framework\Cache;
class CacheImage extends AbstractCache {
protected $_storageEngine = 'filesystem';
public function __construct($group) {
parent::__construct($group, true);
protected function getScope() {
public function setLazy($lazy) {
* @param callable $callable
* @param array $parameters
public function makeCache($fileExtension, $callable, $parameters = array(), $hash = false) {
$hash = $this->generateHash($fileExtension, $callable, $parameters);
if (strpos($parameters[1], '?') !== false) {
$fileNameParts = explode('?', $parameters[1]);
$keepFileName = pathinfo($fileNameParts[0], PATHINFO_FILENAME);
$keepFileName = pathinfo($parameters[1], PATHINFO_FILENAME);
$fileName = $hash . (!empty($keepFileName) ? '/' . $keepFileName : '');
$fileNameWithExtension = $fileName . '.' . $fileExtension;
$isCached = $this->exists($fileNameWithExtension);
if (!$this->testManifestFile($fileName, $parameters[1])) {
array_unshift($parameters, $this->getPath($fileNameWithExtension));
call_user_func_array($callable, $parameters);
$this->createManifestFile($fileName, $parameters[2]);
return $this->getPath($fileNameWithExtension);
private function generateHash($fileExtension, $callable, $parameters) {
return md5(json_encode(array(
protected function testManifestFile($fileName, $originalFile) {
$manifestKey = $this->getManifestKey($fileName);
if ($this->exists($manifestKey)) {
$manifestData = json_decode($this->get($manifestKey), true);
$newManifestData = $this->getManifestData($originalFile);
if ($manifestData['mtime'] == $newManifestData['mtime']) {
// Backward compatibility
$this->createManifestFile($fileName, $originalFile);
protected function createManifestFile($fileName, $originalFile) {
$this->set($this->getManifestKey($fileName), json_encode($this->getManifestData($originalFile)));
private function getManifestData($originalFile) {
if (strpos($originalFile, '//') !== false) {
$manifestData['mtime'] = $this->getRemoteMTime($originalFile);
$manifestData['mtime'] = filemtime($originalFile);
private function getRemoteMTime($url) {
if (ini_get('allow_url_fopen')) {
$h = get_headers($url, 1);
if (is_array($h) && strpos($h[0], '200') !== false) {
foreach ($h as $k => $v) {
if (strtolower(trim($k)) == "last-modified") {
return (new DateTime($v))->getTimestamp();
protected function getManifestKey($fileName) {
return $fileName . '.manifest';