pokemon-showdown-client/githooks/update-version-query-strings
Cathy J. Fitzpatrick 56cc3f0de4 Change version script for PHP 5.2
The live web server runs PHP 5.2, which apparently does not
support anonymous functions, so the anonymous funciton has
been removed from update-version-query-strings.
2013-01-26 00:25:01 -07:00

25 lines
653 B
PHP
Executable File

#!/usr/bin/env php
<?php
/**
* This script parses index.php and sets the version query string of each
* resource to be the MD5 hash of that resource. This script should be executed
* from the base directory of the repository.
*
* On the live web server, this script is set as the following git hooks:
* post-commit, post-checkout, post-merge, post-rewrite
*/
define('SOURCE_FILE', 'index.php');
function replaceMatch($m) {
$hash = md5_file($m[2]);
return "${m[1]}=\"/${m[2]}?${hash}\"";
}
file_put_contents(SOURCE_FILE,
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
'replaceMatch',
file_get_contents(SOURCE_FILE))
);