-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path07-manual-unleash-object.php
60 lines (56 loc) · 2.51 KB
/
07-manual-unleash-object.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
<?php
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Discovery\Psr18ClientDiscovery;
use Unleash\Client\Client\DefaultRegistrationService;
use Unleash\Client\Configuration\UnleashConfiguration;
use Unleash\Client\DefaultUnleash;
use Unleash\Client\Metrics\DefaultMetricsHandler;
use Unleash\Client\Metrics\DefaultMetricsSender;
use Unleash\Client\Repository\DefaultUnleashRepository;
use Unleash\Client\Stickiness\MurmurHashCalculator;
use Unleash\Client\Strategy\ApplicationHostnameStrategyHandler;
use Unleash\Client\Strategy\DefaultStrategyHandler;
use Unleash\Client\Strategy\GradualRolloutRandomStrategyHandler;
use Unleash\Client\Strategy\GradualRolloutSessionIdStrategyHandler;
use Unleash\Client\Strategy\GradualRolloutStrategyHandler;
use Unleash\Client\Strategy\GradualRolloutUserIdStrategyHandler;
use Unleash\Client\Strategy\IpAddressStrategyHandler;
use Unleash\Client\Strategy\UserIdStrategyHandler;
use Unleash\Client\Variant\DefaultVariantHandler;
require_once __DIR__ . '/_common.php';
$stickinessCalculator = new MurmurHashCalculator();
$gradualRolloutStrategyHandler = new GradualRolloutStrategyHandler($stickinessCalculator);
$strategies = [
$gradualRolloutStrategyHandler,
new ApplicationHostnameStrategyHandler(),
new DefaultStrategyHandler(),
new IpAddressStrategyHandler(),
new UserIdStrategyHandler(),
// you can skip these three if you don't use the deprecated strategies
new GradualRolloutRandomStrategyHandler($gradualRolloutStrategyHandler),
new GradualRolloutSessionIdStrategyHandler($gradualRolloutStrategyHandler),
new GradualRolloutUserIdStrategyHandler($gradualRolloutStrategyHandler),
];
$httpClient = Psr18ClientDiscovery::find();
$httpFactory = Psr17FactoryDiscovery::findRequestFactory();
$configuration = (new UnleashConfiguration(
$appUrl,
$appName,
$instanceId,
))->setHeaders([
'Authorization' => $apiKey,
]);
// add any other configuration to the configuration object, like cache configuration etc.
$repository = new DefaultUnleashRepository($httpClient, $httpFactory, $configuration);
$registrationService = new DefaultRegistrationService($httpClient, $httpFactory, $configuration);
$metricsSender = new DefaultMetricsSender($httpClient, $httpFactory, $configuration);
$metricsHandler = new DefaultMetricsHandler($metricsSender, $configuration);
$variantHandler = new DefaultVariantHandler($stickinessCalculator);
$unleash = new DefaultUnleash(
$strategies,
$repository,
$registrationService,
$configuration,
$metricsHandler,
$variantHandler,
);