Example #1
0
use SeerUK\Frost\Condition\CallableCondition;
use SeerUK\Frost\Condition\VotingCondition;
$features = [new Feature("example.voting.affirmative", new VotingCondition(VotingCondition::STRATEGY_AFFIRMATIVE, [new CallableCondition(function () : bool {
    return false;
}), new CallableCondition(function () : bool {
    return true;
}), new CallableCondition(function () : bool {
    return false;
})])), new Feature("example.voting.consensus", new VotingCondition(VotingCondition::STRATEGY_CONSENSUS, [new CallableCondition(function () : bool {
    return true;
}), new CallableCondition(function () : bool {
    return true;
}), new CallableCondition(function () : bool {
    return false;
})])), new Feature("example.voting.unanimous", new VotingCondition(VotingCondition::STRATEGY_UNANIMOUS, [new CallableCondition(function () : bool {
    return true;
}), new CallableCondition(function () : bool {
    return true;
}), new CallableCondition(function () : bool {
    return true;
})]))];
$director = new FeatureDirector();
$director->addFeatures($features);
foreach ($features as $feature) {
    /** @var Feature $feature */
    if ($director->isEnabled($feature->getName())) {
        echo "Feature '{$feature->getName()}' is enabled!\n";
    } else {
        echo "Feature '{$feature->getName()}' is not enabled.\n";
    }
}
Example #2
0
 /**
  * @expectedException \RuntimeException
  */
 public function testIsEnabledThrowsOnUnknownFeature()
 {
     $director = new FeatureDirector([]);
     $director->isEnabled("test.is-enabled.unknown");
 }
Example #3
0
<?php

require __DIR__ . "/../vendor/autoload.php";
/**
 * This file is part of the frost package.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the LICENSE is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use SeerUK\Frost\Feature;
use SeerUK\Frost\FeatureDirector;
use SeerUK\Frost\Condition\CallableCondition;
$feature = new Feature("example.context", new CallableCondition(function (array $context) : bool {
    $requiredDate = new DateTimeImmutable("2015-01-01");
    return $context["created"] > $requiredDate->getTimestamp();
}));
$director = new FeatureDirector();
$director->addFeature($feature);
$users = [["username" => "A", "created" => 1428842585], ["username" => "B", "created" => 1321639398]];
foreach ($users as $user) {
    if ($director->isEnabled("example.context", $user)) {
        echo "Feature 'example.context' is enabled for user '{$user["username"]}'.\n";
    } else {
        echo "Feature 'example.context' is not enabled for user '{$user["username"]}'.\n";
    }
}
Example #4
0
<?php

require __DIR__ . "/../vendor/autoload.php";
/**
 * This file is part of the frost package.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the LICENSE is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
use SeerUK\Frost\Feature;
use SeerUK\Frost\FeatureDirector;
use SeerUK\Frost\Condition\CallableCondition;
$features = [new Feature("example.basic", new CallableCondition(function () : bool {
    return true;
}))];
$director = new FeatureDirector();
$director->addFeatures($features);
if ($director->isEnabled("example.basic")) {
    echo "Feature 'example.basic' is enabled!\n";
} else {
    echo "Feature 'example.basic' is not enabled.\n";
}