Skip to content

Commit 1c884a8

Browse files
committed
updated phpdocs
1 parent ac52618 commit 1c884a8

22 files changed

+1018
-11
lines changed

.phpunit.result.cache

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

ImpressionClient.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Listener;
4+
5+
// Implementation Sample for a Client Listener
6+
class ImpressionClient implements \SplitIO\Sdk\ImpressionListener
7+
{
8+
public function logImpression($data)
9+
{
10+
$impressionLogged = $data['impression'];
11+
$impression = array(
12+
'keyName' => $impressionLogged->getId(),
13+
'treatment' => $impressionLogged->getTreatment(),
14+
'time' => $impressionLogged->getTime(),
15+
'changeNumber' => $impressionLogged->getChangeNumber(),
16+
'label' => $impressionLogged->getLabel(),
17+
'bucketingKey' => $impressionLogged->getBucketingKey()
18+
);
19+
20+
$customData = array(
21+
'impressions' => [
22+
array(
23+
'testName' => $impressionLogged->getFeature(),
24+
'keyImpressions' => [$impression]
25+
)
26+
],
27+
'sdkVersion' => $data['sdk-language-version'],
28+
'machineIP' => $data['instance-id']
29+
);
30+
31+
echo json_encode($customData) ."\n";
32+
33+
//$this->post('http://localhost:9876/impressions', json_encode($customData));
34+
}
35+
36+
/**
37+
* @param $uri
38+
* @param $body
39+
* @return Response
40+
*/
41+
protected function post($uri, $body)
42+
{
43+
$response = \Requests::post($uri, array(), $body);
44+
45+
echo json_encode($response->body) ."\n";
46+
}
47+
}

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Split SDK for PHP
22

3-
[![Build Status](https://api.travis-ci.com/splitio/php-client.svg?branch=master)](https://api.travis-ci.com/splitio/php-client)
3+
[![build status](https://github.com/splitio/php-client/actions/workflows/ci.yml/badge.svg)](https://github.com/splitio/php-client/actions)
4+
[![Latest stable](https://img.shields.io/packagist/v/splitsoftware/split-sdk-php)[https://packagist.org/packages/splitsoftware/split-sdk-php]
5+
[![Documentation](https://img.shields.io/badge/php_client-documentation-informational)](https://help.split.io/hc/en-us/articles/360020350372-PHP-SDK)
46

57
This SDK is designed to work with Split, the platform for controlled rollouts, serving features to your users via the Split feature flag to manage your complete customer experience.
68

cluster.1.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
4+
$parameters = array(
5+
'tcp://10.0.5.10:6379?timeout=3',
6+
'tcp://10.0.5.83:6379?timeout=3',
7+
'tcp://10.0.5.35:6379?timeout=3'
8+
);
9+
10+
$options = [
11+
'cluster' => 'redis',
12+
];
13+
14+
$client = new Predis\Client($parameters, $options);
15+
16+
/*
17+
$client->set('{matias2}foo', 'bar');
18+
$client->set('{matias2}foo1', 'bar');
19+
$client->set('{matias2}foo2', 'bar');
20+
$client->set('{matias2}foo3', 'bar');
21+
$client->set('{matias2}foo4', 'bar');
22+
*/
23+
/*
24+
$keys = array();
25+
foreach ($client as $nodeClient) {
26+
$nodeClientKeys = $nodeClient->keys("{TESTPREFIXEHASH}php71clusterModeMatias:*");
27+
$keys = array_merge($keys, $nodeClientKeys);
28+
}*/
29+
30+
$keys = $client->keys("{TESTPREFIXEHASH}php71clusterModeMatias:*");
31+
32+
echo "COUNT " . count($keys) . "\n";
33+
echo json_encode($keys) . "\n";
34+
35+
//$nodeClient->mget($keys);
36+
37+
echo json_encode(count($client->mget($keys))) . "/n";
38+
39+
40+
41+
// $client = new Predis\Client($parameters, $options);
42+
// $client->set('foo', 'bar');
43+
// echo $client->get('foo');

cluster.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
/*
4+
$parameters = array(
5+
'tcp://10.0.5.10:6379?timeout=3',
6+
'tcp://10.0.5.83:6379?timeout=3',
7+
'tcp://10.0.5.35:6379?timeout=3'
8+
);
9+
10+
$options = [
11+
'cluster' => 'redis',
12+
];
13+
14+
$client = new Predis\Client($parameters, $options);
15+
16+
/*
17+
$client->set('{matias2}foo', 'bar');
18+
$client->set('{matias2}foo1', 'bar');
19+
$client->set('{matias2}foo2', 'bar');
20+
$client->set('{matias2}foo3', 'bar');
21+
$client->set('{matias2}foo4', 'bar');
22+
23+
24+
$keys = array();
25+
foreach ($client as $nodeClient) {
26+
$nodeClientKeys = $nodeClient->keys("{TESTPREFIXEHASH}php71clusterModeMatias:*");
27+
$keys = array_merge($keys, $nodeClientKeys);
28+
}
29+
30+
echo "COUNT " . count($keys) . "\n";
31+
// echo json_encode($keys) . "\n";
32+
33+
//$nodeClient->mget($keys);
34+
35+
echo json_encode($client->mget($keys)) . "/n";
36+
37+
38+
39+
// $client = new Predis\Client($parameters, $options);
40+
// $client->set('foo', 'bar');
41+
// echo $client->get('foo');
42+
43+
*/
44+
$sdkConfig = array(
45+
'log' => array('adapter' => 'stdout', 'level' => 'error'),
46+
'labelsEnabled' => true,
47+
'cache' => array(
48+
'adapter' => 'predis',
49+
'clusterNodes' => array(
50+
'tcp://client-tracker-0001-001.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
51+
'tcp://client-tracker-0001-002.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
52+
'tcp://client-tracker-0002-001.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
53+
'tcp://client-tracker-0002-002.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
54+
'tcp://client-tracker-0003-001.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
55+
'tcp://client-tracker-0003-002.yygsj3.0001.use1.cache.amazonaws.com:6379?timeout=3',
56+
),
57+
'options' => array(
58+
'distributedStrategy' => 'cluster',
59+
'prefix' => 'test:.',
60+
'keyHashTags' => array('{fadon}', '{SPLITIO}')
61+
)
62+
),
63+
);
64+
65+
$splitFactory = \SplitIO\Sdk::factory('YOUR_API_KEY', $sdkConfig);
66+
$splitClient = $splitFactory->client();
67+
$splitManager = $splitFactory->manager();
68+
69+
echo "Something happened here\n";
70+
71+
echo $splitClient->getTreatment('littlespoon', 'PHP_7_1_notInOrOfAfterWorks'), "\n";
72+
73+
74+
// echo $splitClient->getTreatment('pato', 'testing_new_split'), "\n";
75+
// echo $splitClient->getTreatment('martin', 'testing_new_split'), "\n";
76+
// echo $splitClient->getTreatment('matias', 'sample_feature'), "\n";
77+
78+
// echo json_encode($splitManager->split("PHP_7_1_createDeleteUpdateTestShowsInSplitNames"));
79+
80+
echo json_encode($splitManager->splitnames());
81+
82+
//echo json_encode($splitManager->splitNames());

demo.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
4+
use SplitIO\Sdk\Key;
5+
6+
$parameters = array('scheme' => 'tcp',
7+
'host' => 'localhost',
8+
'port' => 6379,
9+
'timeout' => 881,
10+
'database' => 0
11+
);
12+
13+
$sdkConfig = array(
14+
'labelsEnabled' => true,
15+
'cache' => array(
16+
'adapter' => 'predis',
17+
'parameters' => $parameters,
18+
'options' => array('prefix' => 'demo:.')
19+
),
20+
'ipAddress' => true
21+
);
22+
23+
$splitFactory = \SplitIO\Sdk::factory(null, $sdkConfig);
24+
$splitClient = $splitFactory->client();
25+
26+
while (true == true) {
27+
for ($i = 1; $i <= 200; $i++) {
28+
$splitClient->getTreatment('pato', 'testing_new_matias');
29+
}
30+
for ($i = 1; $i <= 100; $i++) {
31+
$splitClient->track('some_key', 'user', 'some', 1);
32+
}
33+
sleep(5);
34+
}

impressionListener.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
4+
require_once 'ImpressionClient.php';
5+
6+
use Listener\ImpressionClient;
7+
8+
$parameters = ['scheme' => 'tcp',
9+
'host' => 'localhost',
10+
'port' => 6379,
11+
'timeout' => 881,
12+
'database' => 0
13+
];
14+
15+
$sdkConfig = array(
16+
'log' => array('adapter' => 'stdout', 'level' => 'error'),
17+
'labelsEnabled' => true,
18+
'impressionListener' => new ImpressionClient(),
19+
'cache' => array(
20+
'adapter' => 'predis',
21+
'parameters' => $parameters,
22+
'options' => array('prefix' => 'listener:')
23+
),
24+
'ipAddress' => null
25+
);
26+
27+
$splitFactory = \SplitIO\Sdk::factory('YOUR_API_KEY', $sdkConfig);
28+
$splitClient = $splitFactory->client();
29+
30+
echo $splitClient->getTreatment('pato', 'testinag_new_split'), "\n";
31+
# echo $splitClient->getTreatment('martin', 'testing_new_split'), "\n";
32+
# echo $splitClient->getTreatment('matias', 'testing_new_split'), "\n";
33+
34+
35+
echo "hostname: " . gethostname() . "\n";
36+
$hostname = gethostname();
37+
echo "hostip: " . gethostbyname($hostname) . "\n";

localhost.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
require_once "vendor/autoload.php";
3+
4+
// $options['splitFile'] = dirname(dirname(__DIR__)).'/sdks/php-client/tests/files/.splits';
5+
$options['log'] = array('adapter' => 'stdout', 'level' => 'warning');
6+
$options['splitFile'] = dirname(dirname(__DIR__)).'/sdks/php-client/tests/files/splits.yml';
7+
// $options['splitFile'] = dirname(dirname(__DIR__)).'/sdks/php-client/tests/files/.splits';
8+
9+
$splitFactory = \SplitIO\Sdk::factory('localhost', $options);
10+
$splitSdk = $splitFactory->client();
11+
$splitManager = $splitFactory->manager();
12+
13+
echo "Something happened here\n";
14+
15+
/*
16+
echo $splitSdk->getTreatment('only_key', 'my_feature') . "\n";
17+
echo $splitSdk->getTreatment('invalid_key', 'my_feature') . "\n";
18+
echo $splitSdk->getTreatment('key', 'my_feature') . "\n";
19+
echo $splitSdk->getTreatment('key2', 'other_feature') . "\n";
20+
echo $splitSdk->getTreatment('test', 'other_feature_2') . "\n";
21+
echo $splitSdk->getTreatment('key', 'other_feature_3') . "\n";
22+
echo $splitSdk->getTreatment('key_whitelist', 'other_feature_3') . "\n";
23+
24+
echo $splitSdk->getTreatment(true, 'other_feature_3') . "\n";
25+
26+
echo json_encode($splitSdk->getTreatments('only_key', array('my_feature', 'other_feature'))) . "\n";
27+
28+
echo json_encode($splitSdk->getTreatments(true, array('my_feature', 'other_feature'))) . "\n";
29+
echo json_encode($splitSdk->getTreatments('only_key', array(true, 'other_feature'))) . "\n";
30+
31+
32+
echo json_encode($splitSdk->getTreatmentWithConfig('only_key', 'my_feature')) . "\n";
33+
echo json_encode($splitSdk->getTreatmentWithConfig('invalid_key', 'my_feature')) . "\n";
34+
echo json_encode($splitSdk->getTreatmentWithConfig('key', 'my_feature')) . "\n";
35+
echo json_encode($splitSdk->getTreatmentWithConfig('key2', 'other_feature')) . "\n";
36+
echo json_encode($splitSdk->getTreatmentWithConfig('test', 'other_feature_2')) . "\n";
37+
echo json_encode($splitSdk->getTreatmentWithConfig('key', 'other_feature_3')) . "\n";
38+
echo json_encode($splitSdk->getTreatmentWithConfig('key_whitelist', 'other_feature_3')) . "\n";
39+
40+
echo json_encode($splitSdk->getTreatmentWithConfig(true, 'other_feature_3')) . "\n";
41+
echo json_encode($splitSdk->getTreatmentWithConfig('key_whitelist', true)) . "\n";
42+
*/
43+
44+
echo json_encode($splitSdk->getTreatmentsWithConfig('only_key', array('my_feature', 'other_feature'))) . "\n";
45+
46+
echo json_encode($splitSdk->getTreatmentsWithConfig(true, array('my_feature', 'other_feature'))) . "\n";
47+
echo json_encode($splitSdk->getTreatmentsWithConfig('only_key', array('my_feature', true))) . "\n";
48+
49+
/*
50+
echo json_encode($splitManager->splitNames()) . "\n";
51+
52+
$splitViews = $splitManager->splits();
53+
54+
foreach ($splitViews as $splitView) {
55+
echo json_encode($splitView->getName()) . "\n";
56+
echo json_encode($splitView->getTrafficType()) . "\n";
57+
echo json_encode($splitView->getKilled()) . "\n";
58+
echo json_encode($splitView->getTreatments()) . "\n";
59+
echo json_encode($splitView->getChangeNumber()) . "\n";
60+
echo json_encode($splitView->getConfigs()) . "\n";
61+
echo "\n";
62+
}
63+
64+
$splitView = $splitManager->split("my_feature");
65+
66+
echo json_encode($splitView->getName()) . "\n";
67+
echo json_encode($splitView->getTrafficType()) . "\n";
68+
echo json_encode($splitView->getKilled()) . "\n";
69+
echo json_encode($splitView->getTreatments()) . "\n";
70+
echo json_encode($splitView->getChangeNumber()) . "\n";
71+
echo json_encode($splitView->getConfigs()) . "\n";
72+
echo "\n";
73+
*/

0 commit comments

Comments
 (0)