Created
October 19, 2017 11:33
-
-
Save mmodrow/760daa967a92d029a496ebfdcab25e09 to your computer and use it in GitHub Desktop.
Cache breaker for gitted projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* add a cache breaking get parameter to an url, that's based on the local git dir timestamp | |
* @return string | |
*/ | |
public function getCachebrokenUrl($url = "") { | |
$version = $this->getVersionHash(); | |
$cachebrokenUrl = preg_replace("/((?:href|src)=\"[^?\"]*)(\")/", "$1?version=".$version."$2", $url); | |
return $cachebrokenUrl; | |
} | |
/** | |
* gets the .git directory's timestamp as unique id of a shop version | |
* @return bool|int | |
*/ | |
protected function getGitFolderDate(){ | |
return filemtime(self::LOCAL_PROJECT_BASE_PATH.DS.".git"); | |
} | |
/** | |
* get hashed version of the git timestamp | |
* @return string | |
*/ | |
protected function getVersionHash(){ | |
return hash("sha256", $this->getGitFolderDate()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment