PHP code example of featurevisor / featurevisor-php
1. Go to this page and download the library: Download featurevisor/featurevisor-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
featurevisor / featurevisor-php example snippets
use function Featurevisor\createInstance;
$datafileUrl = "https://cdn.yoursite.com/datafile.json";
$datafileContent = file_get_contents($datafileUrl);
$datafileContent = json_decode($datafileContent, true);
$f = createInstance([
"datafile" => $datafileContent
]);
use function Featurevisor\createInstance;
use function Featurevisor\createLogger;
$f = createInstance([
"logger" => createLogger([
"level" => "debug",
]),
]);
$f = createInstance([
"logLevel" => "debug",
]);
$f->setLogLevel("debug");
use function Featurevisor\createInstance;
use function Featurevisor\createLogger;
$f = createInstance([
"logger" => createLogger([
"level" => "info",
"handler" => function ($level, $message, $details) {
// do something with the log
},
]),
]);
$unsubscribe = $f->on('datafile_set', function ($event) {
$revision = $event['revision']; // new revision
$previousRevision = $event['previousRevision'];
$revisionChanged = $event['revisionChanged']; // true if revision has changed
// list of feature keys that have new updates,
// and you should re-evaluate them
$features = $event['features'];
// handle here
});
// stop listening to the event
$unsubscribe();
$unsubscribe = $f->on('context_set', function ($event) {
$replaced = $event['replaced']; // true if context was replaced
$context = $event['context']; // the new context
echo "Context set";
});
$unsubscribe = $f->on('sticky_set', function ($event) {
$replaced = $event['replaced']; // true if sticky features got replaced
$features = $event['features']; // list of all affected feature keys
echo "Sticky features set";
});