collab-corp/laravel-feature-toggle

基于配置的Laravel功能开关。

dev-master 2019-09-13 13:09 UTC

This package is auto-updated.

Last update: 2024-09-13 23:41:41 UTC


README

内容

安装

适用于Laravel ~5

composer require collab-corp/laravel-feature-toggle

与任何包一样,刷新Composer自动加载器是个好主意。

composer dump-autoload

配置

要发布features.php配置文件,运行以下命令:vendor:publish

php artisan vendor:publish --provider="\CollabCorp\LaravelFeatureToggle\FeatureToggleServiceProvider"

然后你可以根据需要配置你的配置,可以使用回调或可调用字符串作为值。

绑定回调

当你的功能配置中有许多回调时,将回调绑定到别名会使这个过程变得轻松。

Feature::bind('evaluation', function ($user, ...$dependencies) {
	// logic.

	return (boolean) $result;
});

除了让Laravel通过容器注入依赖项之外,还可以在逗号分隔的列表中指定值。

在你的配置...

// config/features.php
<?php return [
	// ...
	'my_feature' => 'env:local,development'
];

在你的服务提供者...

Feature::bind('env', function ($user, array $enviroments) {
	return app()->enviroment($enviroments);
});

现在你就可以开始了。

使用

此包添加了@features blade指令,它输出添加功能函数到window的JavaScript。

你还可以在blade文件中检查功能,如下所示

@feature('name')
	// Feature is enabled
@else
	// Feature is disabled
@endfeature

在你的应用程序代码中,你可以简单地调用

 use Feature;

 Feature::isEnabled('name');
 Feature::isDisabled('name');

在JavaScript中评估功能

要在前端评估功能开关,只需将@features添加到你的blade文件中。通常在头部。

这将向你的window添加一个bool feature(value)辅助函数。

测试

composer test

问题

如果你发现任何漏洞,请通过电子邮件发送给我:jonas.kerwin.hansen@gmail.com。

对于问题,请在Github上创建一个问题。

许可证

laravel-feature-toggle是在MIT许可证下免费软件。