-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from splitio/feat/manager
add support for manager methods [WIP]
- Loading branch information
Showing
45 changed files
with
1,502 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
use \SplitIO\ThinSdk\Factory; | ||
|
||
$factory = Factory::withConfig([ | ||
'transfer' => [ | ||
'address' => '../../splitd/splitd.sock', | ||
'type' => 'unix-stream', | ||
], | ||
'logging' => [ | ||
'level' => \Psr\Log\LogLevel::DEBUG, | ||
], | ||
]); | ||
|
||
$manager = $factory->manager(); | ||
$names = $manager->splitNames(); | ||
print_r($names); | ||
var_dump($manager->split($names[0])); | ||
var_dump($manager->splits()); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
require_once '../vendor/autoload.php'; | ||
|
||
use \SplitIO\ThinSdk\Factory; | ||
use \SplitIO\ThinSdk\Utils\ImpressionListener; | ||
use \SplitIO\ThinSdk\Models\Impression; | ||
|
||
class CustomListener implements ImpressionListener | ||
{ | ||
public function accept(Impression $i, ?array $a) | ||
{ | ||
echo "got an impression for: key=" . $i->getKey() | ||
. " feat=" . $i->getFeature() | ||
. " treatment=" . $i->getTreatment() | ||
. " label=" . $i->getLabel() | ||
. " cn=" . $i->getChangeNumber() | ||
. " #attrs=" . (($a == null) ? 0 : count($a)) . "\n"; | ||
} | ||
} | ||
|
||
$factory = Factory::withConfig([ | ||
'transfer' => [ | ||
'address' => '../../splitd/splitd.sock', | ||
'type' => 'unix-stream', | ||
], | ||
'logging' => [ | ||
'level' => \Psr\Log\LogLevel::INFO, | ||
], | ||
'utils' => [ | ||
'impressionListener' => new CustomListener(), | ||
], | ||
]); | ||
|
||
$client = $factory->client(); | ||
print_r($client->getTreatmentWithConfig("key", null, "feature1", ['age' => 22])); | ||
print_r($client->getTreatmentsWithConfig("key", null, ["feature1", "feature2"], ['age' => 22])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace SplitIO\ThinSdk\Config; | ||
|
||
use SplitIO\ThinSdk\ClientInterface; | ||
use SplitIO\ThinSdk\ManagerInterface; | ||
use SplitIO\ThinSdk\Fallback\AlwaysControlClient; | ||
use SplitIO\ThinSdk\Fallback\AlwaysEmptyManager; | ||
|
||
|
||
class Fallback | ||
{ | ||
private /*bool*/ $disable; | ||
private /*ClientInterface*/ $customUserClient; | ||
private /*ManagerInterface*/ $customUserManager; | ||
|
||
private function __construct(bool $disable, ?ClientInterface $client, ?ManagerInterface $manager) | ||
{ | ||
$this->disable = $disable; | ||
$this->customUserClient = $client; | ||
$this->customUserManager = $manager; | ||
} | ||
|
||
public function disable(): bool | ||
{ | ||
return $this->disable; | ||
} | ||
|
||
public function client(): ?ClientInterface | ||
{ | ||
return $this->customUserClient; | ||
} | ||
|
||
public function manager(): ?ManagerInterface | ||
{ | ||
return $this->customUserManager; | ||
} | ||
|
||
public static function fromArray(array $config): Fallback | ||
{ | ||
$d = self::default(); | ||
return new Fallback( | ||
$config['disable'] ?? $d->disable(), | ||
$config['client'] ?? $d->client(), | ||
$config['manager'] ?? $d->manager() | ||
); | ||
} | ||
|
||
public static function default(): Fallback | ||
{ | ||
return new Fallback(false, new AlwaysControlClient(), new AlwaysEmptyManager()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace SplitIO\ThinSdk\Fallback; | ||
|
||
use SplitIO\ThinSdk\ClientInterface; | ||
|
||
class AlwaysControlClient implements ClientInterface | ||
{ | ||
public function getTreatment(string $key, ?string $bucketingKey, string $feature, ?array $attributes): string | ||
{ | ||
return "control"; | ||
} | ||
|
||
public function getTreatmentWithConfig(string $key, ?string $bucketingKey, string $feature, ?array $attributes): array | ||
{ | ||
return ['treatment' => 'control', 'config' => null]; | ||
} | ||
|
||
public function getTreatments(string $key, ?string $bucketingKey, array $features, ?array $attributes): array | ||
{ | ||
return array_reduce($features, function ($carry, $item) { | ||
$carry[$item] = "control"; | ||
return $carry; | ||
}, []); | ||
} | ||
|
||
public function getTreatmentsWithConfig(string $key, ?string $bucketingKey, array $features, ?array $attributes): array | ||
{ | ||
return array_reduce($features, function ($carry, $item) { | ||
$carry[$item] = ['treatment' => 'control', 'config' => null]; | ||
return $carry; | ||
}, []); | ||
} | ||
|
||
public function track(string $key, string $trafficType, string $eventType, ?float $value = null, ?array $properties = null): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace SplitIO\ThinSdk\Fallback; | ||
|
||
use SplitIO\ThinSdk\ManagerInterface; | ||
use SplitIO\ThinSdk\SplitView; | ||
|
||
class AlwaysEmptyManager implements ManagerInterface | ||
{ | ||
public function splitNames(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function split(string $name): ?SplitView | ||
{ | ||
return null; | ||
} | ||
|
||
public function splits(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace SplitIO\ThinSdk\Fallback; | ||
|
||
class FallbackDisabledException extends \Exception | ||
{ | ||
|
||
private /*\Exception*/ $wrapped; | ||
|
||
public function __construct(\Exception $wrapped) | ||
{ | ||
$this->wrapped = $wrapped; | ||
} | ||
|
||
public function wrapped(): \Exception | ||
{ | ||
return $this->wrapped; | ||
} | ||
} |
Oops, something went wrong.