PHP得到当前GIT分支的代码

来源:互联网 发布:今日头条 源码 编辑:程序博客网 时间:2024/06/06 17:53

由于研发,测试,生产环境不同,反馈问题经常不能正确定位环境,可在WEB界面的显著位置中显示当前的环境 


   public static function getGitinfo()

    {


        if (\App::environment() == "product") {
            $host = '生产';


        } elseif (\App::environment() == "testing") {
            $host = '测试';
        } else {
            $host = '本机';
        }


        //获取分支名
        $branch = @file_get_contents(base_path() . '/.git/HEAD');
        if (!empty($branch)) {
            $branch = trim($branch);
            $i      = strripos($branch, '/');
            $branch = substr($branch, $i + 1);
        }


        return $host . "【" . $branch . "】";


    }




//非生产才显示

@if (!App::environment()=='production' )


<script>
var content = '{{ getGitinfo() }}      ';
var div = document.createElement("div");
div.style = "font-size:24px; position: absolute;background:#ee6666;padding-left:20px;";
div.innerHTML = content;
var first=document.body.firstChild;
document.body.insertBefore(div,first);
</script>
@endif

0 0
原创粉丝点击