codingpaws/gitlab-feature
Composer 安装命令:
composer require codingpaws/gitlab-feature
包简介
Use GitLab Feature Flags in your Laravel app
README 文档
README
Use GitLab feature flags in your Laravel app.
Getting Started
- Set up feature flags in a project in your GitLab instance.
Install this library in your project.
composer require codingpaws/gitlab-featurePublish the configuration
php artisan vendor:publish --provider=CodingPaws\\GitLabFeature\\FeatureServiceProviderGo to your project’s feature flags and click on Configure

- Add entries to your
.envconfigGITLAB_INSTANCE_IDto the instance ID shown in the Configure modalGITLAB_API_URLto the API url shown in the Configure modalGITLAB_ENV_NAMEto your environment name which you use in your feature flag rollout strategies.
Usage in PHP
When you want to check a feature flag in PHP, such as controllers or models, you can use the Feature class:
use CodingPaws\GitLabFeature\Feature;
if (Feature::enabled('colored_shopping_cart')) {
echo '<div class="shopping-cart__colored" />';
}
if (Feature::disabled('date-format-24h')) {
$dateFormat = DATE_FORMAT_AMPM;
}
Usage in Blade
Importing in blade makes the views hard to read. In views you can use the provided helpers methods:
@if(feature_enabled('new_design'))
<link rel="stylesheet" href="/static/design-2021.css" />
@endif
@unless(feature_disabled('lazyload'))
<script src="/js/lazyload.min.js" defer async></script>
@endif
Feature flag cache
Feature flags are cached using the Laravel Cache system.
This improves your site’s performance and reduces the load on your GitLab
instance. The cache duration can be configured in your
config/gitlab_feature.php config file using the cache_duration entry. The
standard environment variable is GITLAB_CACHE_DURATION. By default, the cache
duration is set to 5 minutes.
You can manually clear the cache as well and force a reload of all feature
flags by using the refresh method:
use CodingPaws\GitLabFeature\Feature;
Feature::refresh();
Custom User IDs
By default Auth::id() is used to roll out feature flags based on a user’s ID.
You can register a custom User ID resolver if you want to roll out the flags
based on a different ID or the username:
use CodingPaws\GitLabFeature\UserIdResolver;
class MyIdResolver extends UserIdResolver
{
public function resolve(): int|string|null
{
return Auth::user()?->name;
}
}
UserIdResolver::register(new MyIdResolver);
Viewing all available feature flags
When debugging problems or working with A/B tests, it can be helpful to see the
state of all feature flags. To get a list of all feature flags and whether they
are enabled or not, use the all method:
use CodingPaws\GitLabFeature\Feature;
$flags = Feature::all();
echo $flags['cool_feature'] ? 'enabled' : 'disabled';
How to mock feature flags
Mocking of feature flags can be done through Laravel facade mocking of
the Feature facade:
use CodingPaws\GitLabFeature\Feature;
Feature::shouldReceive('enabled')
->with('cool_feature')
->once()
->andReturn(true);
Feature::enabled('cool_feature'); // returns `true`
SSL troubleshooting
On certain platforms or depending on your GitLab instance configuration—this does not apply to the GitLab.com SaaS platform—the in-built SSL verification can sometimes cause issues and not work. We’ve had problems in development environments on Windows, even though OpenSSL was installed.
For cases where SSL verification fails, you can disable it by setting the
gitlab_feature.disable_verification to true. By default, you can set the
GITLAB_DISABLE_VERIFICATION environment variable to true.
codingpaws/gitlab-feature 适用场景与选型建议
codingpaws/gitlab-feature 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.13k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flag」 「feature」 「gitlab」 「ab test」 「featureflag」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codingpaws/gitlab-feature 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codingpaws/gitlab-feature 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codingpaws/gitlab-feature 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
Cold template caches that can be flagged and automatically invalidated.
Laravel Eloquent boolean & timestamp flagged attributes behavior.
Bitwise flag setting for Yii 2.x
PHP GitLab generic API client (not stick to any version)
A collection of monolog handlers using PSR-18 http client
统计信息
- 总下载量: 5.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-24