tjvb/laravel-githash 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tjvb/laravel-githash

Composer 安装命令:

composer require tjvb/laravel-githash

包简介

Get the current git hash from your project, show it in your blade or add it to your logs.

README 文档

README

Latest Stable Version Pipeline status Coverage report Tested on PHP 8.0 to 8.5 Tested on Laravel 8 to 12 Latest Unstable Version

PHP Version Require Laravel Version Require PHPMD PHPStan ECS

License

Purpose

The goal for this is to give a simplified way to get the git hash from your code. This hash can be showed in the admin interface, added to your logs, and used for everything you can imaging.

Installation

The basic installation is adding this project with composer: composer require tjvb/laravel-githash.

Manual register the service provider.

If you disable the package discovery you need to add TJVB\LaravelGitHash\GitHashServiceProvider::class, to the providers array in config/app.php

Log

The package provides a way to add the githash to add the hash and the short hash to the logs. This is enabled by default.

Blade component

This package adds a default blade component that you can use with <x-githash></x-githash> to show the short and githash on your (admin) pages. This has the option add a version statement short or long to only show on of the versions. <x-githash version="short"></x-githash>

About command

If the Laravel about command is available it will add information about the hash and the cache status. This can be disabled in the config.

Other usages

There ar a lot of options to add the hash to other parts in your application. This can be done with injecting the \TJVB\LaravelGitHash\Contracts\GitHashLoader, this provides the getGitHash function that returns a TJVB\GitHash\Values\GitHash value object that provides the hash() and short() function.

use TJVB\LaravelGitHash\Contracts\GitHashLoader;

public function example(GitHashLoader $gitHashLoader)
{
    echo $gitHashLoader->getGitHash()->hash();
} 

Customization and configuration

After publishing the config file with php artisan vendor:publish you can change the bindings for the different classes.
It is important to have the cache file pointed to a place that isn't shared between your deployments.

env file variables

In the default configuration there are different ENV variables that can be used.

NameDefaultDescription
GITHASH_REPO_PATHbase_path()The path to the git repository, depending on the finder this need to be the root of the repository, or it can be any path in the repository.
GITHASH_CACHE_ENABLEDnullIf the cache needs to be enabled, if null it will be enabled if debug is disabled.
GITHASH_ABOUT_ENABLEDtrueIf information about the hash and the cache status needs to be added to the Laravel About command.
GITHASH_LOG_CONTEXT_ENABLEDtrueIf the hash needs to be added to the log context.

Finders

This package use tjvb/githash to provide the hash. This has different finders available. You can fill a specific finder to use. If you leave it empty it will add the default finders. (With the default factory it means all the finders from that project.)

Different blade component view

After publishing the blade file php artisan vendor:publish you can change the blade. The location after publishing will be resources/views/vendor/githash/githash.blade.php here you can edit the blade how you want it.

Custom implementations

It is possible to overwrite the different classes, this can be done by implementing the interfaces and update the config file. The config file contains the implementations and has a comment to point to the correct interface to implement.

Cache

This package uses a file to cache the hash. The cache with a file is used because this should be faster than getting the cache every time it is wanted. (Also depending on the finder and the repository size). It doesn't use the building Laravel cache to prevent the usage of a shared cache. With this file cache it is possible to see that by example one queue runner use another code version than the other runners. This can be helpful in debugging any problems.

Usage without git on your server

Depending on the way you deploy your application it is possible that you don't have the repository information available. For this it will also be useful to write the hash to the cache file.

Envoyer example

If you use Envoyer you don't have the git repository on your server. And the full storage dir will be shared between your deployments. That needs some customization.
First update your configuration to have a cache file outside the shared directory.

// in config/githash.php
    'cache_file' => base_path('githash.cache'),

Then add a new deployment hook that will be executed before you install your composer dependencies to place the hash in the cache file:

cd {{release}}

echo {{sha}} > githash.cache

With these changes you will have the cache file without the need to have the repository on the server and can use the hash on the wanted locations.

Changelog

We (try to) document all the changes in CHANGELOG so read it for more information.

Contributing

You are welcome to contribute, read about it in CONTRIBUTING

License

The MIT License (MIT). Please see License File for more information.

tjvb/laravel-githash 适用场景与选型建议

tjvb/laravel-githash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.38k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 10 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「hash」 「laravel」 「tjvb」 「githash」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 tjvb/laravel-githash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 tjvb/laravel-githash 我们能提供哪些服务?
定制开发 / 二次开发

基于 tjvb/laravel-githash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 19.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-21