-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdemo.php
112 lines (89 loc) · 3.26 KB
/
demo.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Cache\ChainCache;
use Doctrine\Common\Cache\FilesystemCache;
use Kevinrob\GuzzleCache\Storage\DoctrineCacheStorage;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Rox\Core\Consts\Environment;
use Rox\Core\Logging\LoggerFactory;
use Rox\Core\Logging\MonologLoggerFactory;
use Rox\Server\Flags\RoxFlag;
use Rox\Server\Rox;
use Rox\Server\RoxOptions;
use Rox\Server\RoxOptionsBuilder;
const DEFAULT_API_KEY = '5e6a3533d3319d76d1ca33fd';
const DEFAULT_DEV_MODE_KEY = '297c23e7fcb68e54c513dcca';
require __DIR__ . '/vendor/autoload.php';
class Container
{
public $demoFlag;
public function __construct()
{
$this->demoFlag = new RoxFlag();
}
}
$apiKey = getenv('ROLLOUT_API_KEY') ?: DEFAULT_API_KEY;
$devModeKey = getenv('ROLLOUT_DEV_MODE_KEY') ?: DEFAULT_DEV_MODE_KEY;
$roxOptionsBuilder = (new RoxOptionsBuilder())
->setDevModeKey($devModeKey)
->setNetworkConfigurationsOptions(new NetworkConfigurationsOptions(
'https://api.test.rollout.io/device/get_configuration',
'https://rox-conf.test.rollout.io',
'https://api.test.rollout.io/device/update_state_store',
'https://rox-state.test.rollout.io',
'https://analytic.test.rollout.io',
'https://notify.bugsnag.com'
));
echo '<pre>';
if (!isset($_GET['nolog'])) {
// Example of setting up custom logging handlers. By default it outputs log records
// to stderr, and default log level is ERROR. Here we're setting custom logging handlers
// to output to filesystem instead with DEBUG log level.
//
// It's also possible to specify custom log record processors by calling
// MonologLoggerFactory::setDefaultProcessors() function. More info can be found in
// Monolog documentation https://github.com/Seldaek/monolog/blob/master/doc/01-usage.md.
//
// Another option for users is to implement their own Logger Factory and pass it to Rox via
// LoggerFactory::setup() method.
//
// If no logging is needed one can call LoggerFactory::setup(new NullLoggerFactory()).
//
// Note LoggerFactory::setup() must be called before Rox::register() and Rox::setup().
$logFile = join(DIRECTORY_SEPARATOR, [
sys_get_temp_dir(),
'rollout',
'logs',
'demo.log'
]);
echo "Logging to {$logFile}\n";
LoggerFactory::setup((new MonologLoggerFactory())
->setDefaultHandlers([
new StreamHandler($logFile, Logger::DEBUG)
]));
}
if (!isset($_GET['nocache'])) {
// Sample caching setup using Doctrine example from https://github.com/Kevinrob/guzzle-cache-middleware
$roxOptionsBuilder
->setCacheStorage(new DoctrineCacheStorage(
new ChainCache([
new ArrayCache(),
new FilesystemCache('/tmp/rollout/cache'),
])
))
->setLogCacheHitsAndMisses(true)
->setConfigFetchIntervalInSeconds(30);
echo "Using cache...\n";
} else {
echo "NOT using cache...\n";
}
$con = new Container();
Rox::register('demo', $con);
Rox::setup($apiKey, new RoxOptions($roxOptionsBuilder));
if ($con->demoFlag->isEnabled()) {
echo "demo.demoFlag: FEATURE IS ON\n";
} else {
echo "demo.demoFlag: FEATURE IS OFF\n";
}
echo '</pre>';