diff --git a/htdocs/backend.php b/htdocs/backend.php index 262fb4b..c0973c0 100644 --- a/htdocs/backend.php +++ b/htdocs/backend.php @@ -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(); diff --git a/lib/Util/Debug.php b/lib/Util/Debug.php index 9503c99..efdf946 100644 --- a/lib/Util/Debug.php +++ b/lib/Util/Debug.php @@ -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; + } + } } ?>