Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/LaunchDarkly/ApcLDDFeatureRequester.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace LaunchDarkly;


/**
* Feature requester from an LDD-populated redis, with APC caching
* @deprecated Per the docs (http://php.net/manual/en/intro.apc.php):
Expand All @@ -10,10 +9,12 @@
*
* @package LaunchDarkly
*/
class ApcLDDFeatureRequester extends LDDFeatureRequester {
class ApcLDDFeatureRequester extends LDDFeatureRequester
{
protected $_expiration = 30;

function __construct($baseUri, $sdkKey, $options) {
public function __construct($baseUri, $sdkKey, $options)
{
parent::__construct($baseUri, $sdkKey, $options);

if (isset($options['apc_expiration'])) {
Expand All @@ -31,13 +32,13 @@ protected function fetch($key, &$success = null)
return \apc_fetch($key, $success);
}

protected function get_from_cache($key) {
protected function get_from_cache($key)
{
$key = self::make_cache_key($key);
$enabled = $this->fetch($key);
if ($enabled === false) {
return null;
}
else {
} else {
return $enabled;
}
}
Expand All @@ -53,11 +54,13 @@ protected function add($key, $var, $ttl = 0)
return \apc_add($key, $var, $ttl);
}

protected function store_in_cache($key, $val) {
protected function store_in_cache($key, $val)
{
$this->add($this->make_cache_key($key), $val, $this->_expiration);
}

private function make_cache_key($name) {
private function make_cache_key($name)
{
return $this->_features_key.'.'.$name;
}
}
}
22 changes: 12 additions & 10 deletions src/LaunchDarkly/CurlEventPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,25 @@ class CurlEventPublisher implements EventPublisher
private $_ssl;
private $_curl = '/usr/bin/env curl';

function __construct($sdkKey, array $options = array()) {
public function __construct($sdkKey, array $options = array())
{
$this->_sdkKey = $sdkKey;

$eventsUri = LDClient::DEFAULT_EVENTS_URI;
if (isset($options['events_uri'])) {
$eventsUri = $options['events_uri'];
}
$url = parse_url(rtrim($eventsUri,'/'));
$url = parse_url(rtrim($eventsUri, '/'));
$this->_host = $url['host'];
$this->_ssl = $url['scheme'] === 'https';
if (isset($url['port'])) {
$this->_port = $url['port'];
}
else {
} else {
$this->_port = $this->_ssl ? 443 : 80;
}
if (isset($url['path'])) {
$this->_path = $url['path'];
}
else {
} else {
$this->_path = '';
}

Expand All @@ -47,13 +46,15 @@ function __construct($sdkKey, array $options = array()) {
}
}

public function publish($payload) {
public function publish($payload)
{
$args = $this->createArgs($payload);

return $this->makeRequest($args);
}

private function createArgs($payload) {
private function createArgs($payload)
{
$scheme = $this->_ssl ? "https://" : "http://";
$args = " -X POST";
$args.= " -H 'Content-Type: application/json'";
Expand All @@ -65,9 +66,10 @@ private function createArgs($payload) {
return $args;
}

private function makeRequest($args) {
private function makeRequest($args)
{
$cmd = $this->_curl . " " . $args . ">> /dev/null 2>&1 &";
shell_exec($cmd);
return true;
}
}
}
9 changes: 5 additions & 4 deletions src/LaunchDarkly/EvaluationException.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<?php
namespace LaunchDarkly;


use Exception;

class EvaluationException extends Exception {
class EvaluationException extends Exception
{
/**
* EvaluationException constructor.
* @param string $message
*/
public function __construct($message) {
public function __construct($message)
{
parent::__construct($message);
}
}
}
5 changes: 3 additions & 2 deletions src/LaunchDarkly/EventPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/**
* Provides a transport mechanism for sending events to the LaunchDarkly service.
*/
interface EventPublisher {
interface EventPublisher
{
/**
* @param string $sdkKey The SDK key for your account
* @param mixed[] $options Client configuration settings
Expand All @@ -18,4 +19,4 @@ public function __construct($sdkKey, array $options);
* @return bool Whether the events were successfully published
*/
public function publish($payload);
}
}
Loading