Skip to content

Instantly share code, notes, and snippets.

@bootell
Created November 10, 2016 06:08
Show Gist options
  • Save bootell/06d07f205b24eaa7661005042d41442c to your computer and use it in GitHub Desktop.
Save bootell/06d07f205b24eaa7661005042d41442c to your computer and use it in GitHub Desktop.
PHP程序自动获取版本号(git hash or file's modified time)
<?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