added commit hash to VZ_VERSION

This commit is contained in:
Steffen Vogel 2011-02-24 23:14:56 +01:00
parent ba71b1655f
commit 125240b701
2 changed files with 23 additions and 2 deletions

View file

@ -32,8 +32,6 @@ use Volkszaehler\Controller;
// enable strict error reporting
error_reporting(E_ALL | E_STRICT);
// TODO replace by state class
define('VZ_VERSION', 0.2);
define('VZ_DIR', realpath(__DIR__ . '/..'));
// class autoloading
@ -48,6 +46,14 @@ foreach ($classLoaders as $loader) {
$loader->register(); // register on SPL autoload stack
}
if ($hash = Util\Debug::getCurrentCommit()) { // append git sha1 hash to version
define('VZ_COMMIT', $hash);
define('VZ_VERSION', '0.2.git-' . substr(VZ_COMMIT, -8));
}
else {
define('VZ_VERSION', '0.2');
}
Util\Configuration::load(VZ_DIR . '/etc/volkszaehler.conf');
$r = new Router();

View file

@ -149,6 +149,21 @@ class Debug {
* @todo encapsulate in state class? or inherit from singleton class?
*/
public static function getInstance() { return self::$instance; }
/**
* Tries to determine the current SHA1 hash of your git commit
*
* @return string the hash
*/
public static function getCurrentCommit() {
if (file_exists(VZ_DIR . '/.git/HEAD')) {
$head = file_get_contents(VZ_DIR . '/.git/HEAD');
return substr(file_get_contents(VZ_DIR . '/.git/' . substr($head, strpos($head, ' ')+1, -1)), 0, -1);
}
else {
return FALSE;
}
}
}
?>