-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.php
39 lines (34 loc) · 1.05 KB
/
helpers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use FeatureToggle\Api;
use FeatureToggle\Concerns\Toggle;
use FeatureToggle\Contracts\Api as FeatureToggleApi;
if (! function_exists('feature_toggle_api')) {
/**
* @param string|null $provider
* @return Api|FeatureToggleApi|\FeatureToggle\Contracts\ToggleProvider
*
* @throws RuntimeException
*/
function feature_toggle_api(?string $provider = null)
{
/** @var FeatureToggleApi|Api $featureToggleApi */
$featureToggleApi = app(FeatureToggleApi::class);
if (! $provider) {
return $featureToggleApi;
}
return $featureToggleApi->getProvider($provider);
}
}
if (! function_exists('feature_toggle')) {
/**
* @param string $name
* @param string|bool|int $checkActive
* @return bool
*/
function feature_toggle(string $name, $checkActive = true)
{
$isActive = feature_toggle_api()->isActive($name);
$checkActive = Toggle::calculateIsActive($checkActive);
return $checkActive === true ? $isActive : ! $isActive;
}
}