Heim >Backend-Entwicklung >PHP-Tutorial >PHP得到当前GIT分支的代码

PHP得到当前GIT分支的代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-28 08:25:452629Durchsuche

由于研发,测试,生产环境不同,反馈问题经常不能正确定位环境,可在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><br>var content = '{{ getGitinfo() }} ';<br>var div = document.createElement("div");<br>div.style = "font-size:24px; position: absolute;background:#ee6666;padding-left:20px;";<br>div.innerHTML = content;<br>var first=document.body.firstChild;<br>document.body.insertBefore(div,first);<br></script>
@endif

以上就介绍了 PHP得到当前GIT分支的代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn