/** * Looks if the cached contents are older than the modified dates of any of the given files * Pass a ResourceFinder instance rather than an array to prevent the (potentially expensive) call to ResourceFinder->find() in production. * @param string|array|ResourceFinder $mOriginalFilePath */ public function isOutdated($mOriginalFilePath) { if (ErrorHandler::isProduction()) { //Files are never out of date in production (clear the cache manually when deploying)… no need to check return false; } if ($mOriginalFilePath instanceof ResourceFinder) { $mOriginalFilePath = $mOriginalFilePath->find(); } if ($mOriginalFilePath === null) { return false; } if (!is_array($mOriginalFilePath)) { $mOriginalFilePath = array($mOriginalFilePath); } foreach ($mOriginalFilePath as $sOriginalFilePath) { if ($sOriginalFilePath instanceof FileResource) { $sOriginalFilePath = $sOriginalFilePath->getFullPath(); } $iFileModDate = 0; if (file_exists($sOriginalFilePath)) { $iFileModDate = filemtime($sOriginalFilePath); } if ($this->isOlderThan($iFileModDate)) { return true; } } return false; }
/** * @return bool|string|FileResource|array the matched path(s) */ public function find() { if ($this->mResult === false) { if (!$this->bNoCache && ErrorHandler::isProduction()) { $oCache = new Cache(serialize($this), 'resource_finder', CachingStrategyFile::create()); if ($oCache->entryExists()) { $this->mResult = $oCache->getContentsAsVariable(); } else { $this->mResult = $this->doFind(); $oCache->setContents($this->mResult, true); } } else { $this->mResult = $this->doFind(); } } return $this->mResult; }