Created
November 10, 2016 06:08
-
-
Save bootell/06d07f205b24eaa7661005042d41442c to your computer and use it in GitHub Desktop.
PHP程序自动获取版本号(git hash or file's modified time)
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
<?php | |
namespace bootell\models; | |
class Versional | |
{ | |
/** | |
* Get git hash | |
* | |
* @param int $num | |
* @return string | |
*/ | |
public static function getGitHash($num = 7) | |
{ | |
$git_hash = exec('git rev-parse HEAD'); | |
if ($git_hash && is_string($git_hash)) { | |
$version = substr($git_hash, 0, $num); | |
return $version; | |
} | |
return 0; | |
} | |
/** | |
* Get modified time by given directory | |
* | |
* @param $dir | |
* @return string | |
*/ | |
public static function getModifiedTime($dir) | |
{ | |
if(file_exists($_SERVER['DOCUMENT_ROOT'] . $dir) ) { | |
$version = filemtime($_SERVER['DOCUMENT_ROOT'] . $dir); | |
return $version; | |
} | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment