From 238053f04db99116fbd81139921fce65c22f1a76 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 11 Feb 2022 10:41:11 -0300 Subject: [PATCH 1/6] removed http logic from repo --- CHANGES.txt | 3 + CONTRIBUTORS-GUIDE.md | 11 +- composer.json | 1 - src/SplitIO/Component/Http/MethodEnum.php | 12 - src/SplitIO/Component/Http/ResponseHelper.php | 14 - src/SplitIO/Component/Http/Uri.php | 251 ------------------ src/SplitIO/Component/Utils/functions.php | 92 ------- src/SplitIO/Engine/Splitter.php | 2 +- src/SplitIO/Version.php | 2 +- 9 files changed, 12 insertions(+), 376 deletions(-) delete mode 100644 src/SplitIO/Component/Http/MethodEnum.php delete mode 100644 src/SplitIO/Component/Http/ResponseHelper.php delete mode 100644 src/SplitIO/Component/Http/Uri.php diff --git a/CHANGES.txt b/CHANGES.txt index 120d55bc..daaf68e9 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,6 @@ +7.1.1 (Feb 11, 2021) + - Removed unused logic for HTTP and requests dependency. + 7.1.0 (Dec 3, 2021) - Added a new option to use when running Redis in cluster mode called `keyHashTags` which receives a list of hashtags from which the SDK will randomly pick one to use on the generated instance. diff --git a/CONTRIBUTORS-GUIDE.md b/CONTRIBUTORS-GUIDE.md index dad9b7f8..fa78c01a 100644 --- a/CONTRIBUTORS-GUIDE.md +++ b/CONTRIBUTORS-GUIDE.md @@ -6,26 +6,29 @@ Split SDK is an open source project and we welcome feedback and contribution. Th ### Development process -1. Fork the repository and create a topic branch from `development` branch. Please use a descriptive name for your branch. +1. Fork the repository and create a topic branch from `develop` branch. Please use a descriptive name for your branch. 2. While developing, use descriptive messages in your commits. Avoid short or meaningless sentences like "fix bug". 3. Make sure to add tests for both positive and negative cases. 4. Run the build script and make sure it runs with no errors. 5. Run all tests and make sure there are no failures. 6. `git push` your changes to GitHub within your topic branch. -7. Open a Pull Request(PR) from your forked repo and into the `development` branch of the original repository. +7. Open a Pull Request(PR) from your forked repo and into the `develop` branch of the original repository. 8. When creating your PR, please fill out all the fields of the PR template, as applicable, for the project. -9. Check for conflicts once the pull request is created to make sure your PR can be merged cleanly into `development`. +9. Check for conflicts once the pull request is created to make sure your PR can be merged cleanly into `develop`. 10. Keep an eye out for any feedback or comments from Split's SDK team. ### Building the SDK + - `composer install` ### Running tests + - `vendor/bin/phpunit -c phpunit.xml.dist --testsuite integration` ### Linting and other useful checks + - `vendor/bin/phpcs --ignore=functions.php --standard=PSR2 src/` -# Contact +## Contact If you have any other questions or need to contact us directly in a private manner send us a note at sdks@split.io diff --git a/composer.json b/composer.json index c2de7162..4cc2621b 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,6 @@ "php": ">=7.3", "psr/log": "~1.0", "predis/predis": "^1.1.9", - "rmccue/requests": "^1.8.1", "symfony/yaml": ">=5.3" }, diff --git a/src/SplitIO/Component/Http/MethodEnum.php b/src/SplitIO/Component/Http/MethodEnum.php deleted file mode 100644 index bc7dd521..00000000 --- a/src/SplitIO/Component/Http/MethodEnum.php +++ /dev/null @@ -1,12 +0,0 @@ -= 200 && $statusCode < 300; - } -} diff --git a/src/SplitIO/Component/Http/Uri.php b/src/SplitIO/Component/Http/Uri.php deleted file mode 100644 index 34c52eb1..00000000 --- a/src/SplitIO/Component/Http/Uri.php +++ /dev/null @@ -1,251 +0,0 @@ - 80, - 'https' => 443, - ); - - private static $charUnreserved = 'a-zA-Z0-9_\-\.~'; - private static $charSubDelims = '!\$&\'\(\)\*\+,;='; - private static $replaceQuery = array('=' => '%3D', '&' => '%26'); - - /** @var string Uri scheme. */ - private $scheme = ''; - - /** @var string Uri user info. */ - private $userInfo = ''; - - /** @var string Uri user info. */ - private $user = ''; - - /** @var string Uri user info. */ - private $pass = ''; - - /** @var string Uri host. */ - private $host = ''; - - /** @var int|null Uri port. */ - private $port; - - /** @var string Uri path. */ - private $path = ''; - - /** @var string Uri query string. */ - private $query = ''; - - /** @var string Uri fragment. */ - private $fragment = ''; - - /** - * @param string $uri URI to parse and wrap. - */ - public function __construct($uri = '') - { - if ($uri != null) { - $parts = parse_url($uri); - if ($parts === false) { - throw new \InvalidArgumentException("Unable to parse URI: $uri"); - } - $this->applyParts($parts); - } - } - - public function getScheme() - { - return $this->scheme; - } - - public function getAuthority() - { - if (empty($this->host)) { - return ''; - } - - $authority = $this->host; - if (!empty($this->userInfo)) { - $authority = $this->userInfo . '@' . $authority; - } - - if ($this->isNonStandardPort($this->scheme, $this->host, $this->port)) { - $authority .= ':' . $this->port; - } - - return $authority; - } - - public function getUserInfo() - { - return $this->userInfo; - } - - public function getUser() - { - return $this->user; - } - - public function getPass() - { - return $this->pass; - } - - public function getHost() - { - return $this->host; - } - - public function getPort() - { - return $this->port; - } - - public function getPath() - { - return $this->path == null ? '' : $this->path; - } - - public function getQuery() - { - return $this->query; - } - - public function getFragment() - { - return $this->fragment; - } - - /** - * Apply parse_url parts to a URI. - * - * @param $parts Array of parse_url parts to apply. - */ - private function applyParts(array $parts) - { - $this->scheme = isset($parts['scheme']) - ? $this->filterScheme($parts['scheme']) - : ''; - $this->userInfo = isset($parts['user']) ? $parts['user'] : ''; - $this->user = isset($parts['user']) ? $parts['user'] : ''; - $this->pass = isset($parts['pass']) ? $parts['pass'] : ''; - $this->host = isset($parts['host']) ? $parts['host'] : ''; - $this->port = !empty($parts['port']) - ? $this->filterPort($this->scheme, $this->host, $parts['port']) - : null; - $this->path = isset($parts['path']) - ? $this->filterPath($parts['path']) - : ''; - $this->query = isset($parts['query']) - ? $this->filterQueryAndFragment($parts['query']) - : ''; - $this->fragment = isset($parts['fragment']) - ? $this->filterQueryAndFragment($parts['fragment']) - : ''; - - if (isset($parts['pass'])) { - $this->userInfo .= ':' . $parts['pass']; - } - } - - /** - * Is a given port non-standard for the current scheme? - * - * @param string $scheme - * @param string $host - * @param int $port - * @return bool - */ - private static function isNonStandardPort($scheme, $host, $port) - { - if (!$scheme && $port) { - return true; - } - - if (!$host || !$port) { - return false; - } - - return !isset(static::$schemes[$scheme]) || $port !== static::$schemes[$scheme]; - } - - /** - * @param string $scheme - * - * @return string - */ - private function filterScheme($scheme) - { - $scheme = strtolower($scheme); - $scheme = rtrim($scheme, ':/'); - - return $scheme; - } - - /** - * @param string $scheme - * @param string $host - * @param int $port - * - * @return int|null - * - * @throws \InvalidArgumentException If the port is invalid. - */ - private function filterPort($scheme, $host, $port) - { - if (null !== $port) { - $port = (int) $port; - if (1 > $port || 0xffff < $port) { - throw new \InvalidArgumentException( - sprintf('Invalid port: %d. Must be between 1 and 65535', $port) - ); - } - } - - return $this->isNonStandardPort($scheme, $host, $port) ? $port : null; - } - - /** - * Filters the path of a URI - * - * @param $path - * - * @return string - */ - private function filterPath($path) - { - return preg_replace_callback( - '/(?:[^' . self::$charUnreserved . self::$charSubDelims . ':@\/%]+|%(?![A-Fa-f0-9]{2}))/', - array($this, 'rawurlencodeMatchZero'), - $path - ); - } - - /** - * Filters the query string or fragment of a URI. - * - * @param $str - * - * @return string - */ - private function filterQueryAndFragment($str) - { - return preg_replace_callback( - '/(?:[^' . self::$charUnreserved . self::$charSubDelims . '%:@\/\?]+|%(?![A-Fa-f0-9]{2}))/', - array($this, 'rawurlencodeMatchZero'), - $str - ); - } - - private function rawurlencodeMatchZero(array $match) - { - return rawurlencode($match[0]); - } -} diff --git a/src/SplitIO/Component/Utils/functions.php b/src/SplitIO/Component/Utils/functions.php index 4db2cff7..424cb723 100644 --- a/src/SplitIO/Component/Utils/functions.php +++ b/src/SplitIO/Component/Utils/functions.php @@ -4,98 +4,6 @@ */ namespace SplitIO\Component\Utils; -defined('SPLITIO_URL') || define('SPLITIO_URL', 'https://sdk.split.io'); -defined('SPLITIO_EVENTS_URL') || define('SPLITIO_EVENTS_URL', 'https://events.split.io'); - -function setEnvironment($env) -{ - putenv('SPLITIO_PHP_SDK_ENV='.$env); -} - -function getEnvironment() -{ - $env = getenv('SPLITIO_PHP_SDK_ENV'); - if (empty($env)) { - return 'production'; - } else { - return $env; - } -} - -/** - * @param null $env - * @param bool|false $set - * @return bool|string - */ -function environment($env = null, $set = false) -{ - if ($env !== null && $set) { - setEnvironment($env); - } elseif ($env !== null && ! $set) { - if ($env == getEnvironment()) { - return true; - } else { - return false; - } - } - - return getEnvironment(); -} - -function getSplitServerUrl() -{ - $env = environment(); - - switch ($env) { - case 'development': - return getenv('SPLITIO_DEV_URL'); - break; - - case 'loadtesting': - return getenv('SPLITIO_LOADTESTING_URL'); - break; - - case 'testing': - return getenv('SPLITIO_TESTING_URL'); - break; - - case 'staging': - return getenv('SPLITIO_STAGE_URL'); - break; - - case 'production': - default: - return SPLITIO_URL; - } -} - -function getSplitEventsUrl() -{ - $env = environment(); - - switch ($env) { - case 'development': - return getenv('SPLITIO_EVENTS_DEV_URL'); - break; - - case 'loadtesting': - return getenv('SPLITIO_EVENTS_LOADTESTING_URL'); - break; - - case 'testing': - return getenv('SPLITIO_EVENTS_TESTING_URL'); - break; - - case 'staging': - return getenv('SPLITIO_EVENTS_STAGE_URL'); - break; - - case 'production': - default: - return SPLITIO_EVENTS_URL; - } -} - function isAssociativeArray($arr) { if (!is_array($arr)) { diff --git a/src/SplitIO/Engine/Splitter.php b/src/SplitIO/Engine/Splitter.php index 3ec5e4ec..ac78fe9f 100644 --- a/src/SplitIO/Engine/Splitter.php +++ b/src/SplitIO/Engine/Splitter.php @@ -38,7 +38,7 @@ public function getTreatment($key, $seed, $partitions, $algo) SplitApp::logger()->debug($logMsg); $bucket = self::getBucket($algo, $key, $seed); - SplitApp::logger()->info("Butcket: ".$bucket); + SplitApp::logger()->info("Bucket: ".$bucket); $accumulatedSize = 0; foreach ($partitions as $partition) { diff --git a/src/SplitIO/Version.php b/src/SplitIO/Version.php index f6d34498..448853ad 100644 --- a/src/SplitIO/Version.php +++ b/src/SplitIO/Version.php @@ -3,5 +3,5 @@ class Version { - const CURRENT = '7.1.0'; + const CURRENT = '7.1.1-rc1'; } From 29c0cc1bcd7452f64619f5ebba60abd37ffeb22d Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 11 Feb 2022 10:57:07 -0300 Subject: [PATCH 2/6] removed import --- src/SplitIO/Sdk.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SplitIO/Sdk.php b/src/SplitIO/Sdk.php index 35d67130..26c3f51e 100644 --- a/src/SplitIO/Sdk.php +++ b/src/SplitIO/Sdk.php @@ -1,7 +1,6 @@ Date: Fri, 11 Feb 2022 11:15:40 -0300 Subject: [PATCH 3/6] removed Process component --- src/SplitIO/Component/Process/Process.php | 135 ---------------------- 1 file changed, 135 deletions(-) delete mode 100644 src/SplitIO/Component/Process/Process.php diff --git a/src/SplitIO/Component/Process/Process.php b/src/SplitIO/Component/Process/Process.php deleted file mode 100644 index 13c08466..00000000 --- a/src/SplitIO/Component/Process/Process.php +++ /dev/null @@ -1,135 +0,0 @@ -userCommand = $cmd; - $this->pipes = array(); - $this->processInformation = array(); - - $this->status = self::STATUS_READY; - - $this->stderrBuffer = ""; - $this->stdoutBuffer = ""; - } - - public function __destruct() - { - if (is_resource($this->process)) { - @proc_terminate($this->process); - } - } - - public function getCommandLine() - { - return $this->userCommand; - } - - public function start() - { - $descriptor = array( - array('pipe', 'r'), - array('pipe', 'w'), // stdout - array('pipe', 'w'), // stderr - ); - - $this->process = proc_open($this->userCommand, $descriptor, $this->pipes); - - if (!is_resource($this->process)) { - throw new \RuntimeException('Unable to launch a new process.'); - } - - $this->status = self::STATUS_STARTED; - - $this->updateStatus(); - } - - public function isStarted() - { - return $this->status != self::STATUS_READY; - } - - public function wait() - { - while ($this->isRunning()) { - usleep(1000); - } - - return; - } - - public function getPid() - { - return $this->isRunning() ? $this->processInformation['pid'] : null; - } - - public function isRunning() - { - $this->updateStatus(); - - return isset($this->processInformation['running']) ? $this->processInformation['running'] : false; - } - - public function getStdout() - { - $buff = $this->stdoutBuffer; - $this->stdoutBuffer = ""; - return $buff; - } - - public function getStderr() - { - $buff = $this->stderrBuffer; - $this->stderrBuffer = ""; - return $buff; - } - - private function updateStatus() - { - if (!is_resource($this->process)) { - return; - } - - $this->stdoutBuffer .= PHP_EOL . stream_get_contents($this->pipes[1]); - $this->stderrBuffer .= PHP_EOL . stream_get_contents($this->pipes[2]); - - $this->processInformation = proc_get_status($this->process); - - $running = $this->processInformation['running']; - - if (!$running) { - $this->close(); - } - } - - private function close() - { - foreach ($this->pipes as $pipe) { - fclose($pipe); - } - $this->pipes = array(); - - if (is_resource($this->process)) { - proc_close($this->process); - } - } -} From 1d8e59333f8ae2adc11e427c7728dde0246040a3 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 11 Feb 2022 11:16:11 -0300 Subject: [PATCH 4/6] updated version for test --- src/SplitIO/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SplitIO/Version.php b/src/SplitIO/Version.php index 448853ad..82c55f86 100644 --- a/src/SplitIO/Version.php +++ b/src/SplitIO/Version.php @@ -3,5 +3,5 @@ class Version { - const CURRENT = '7.1.1-rc1'; + const CURRENT = '7.1.1-rc2'; } From a4cf6cd57d19e061c0b5a623a8a063da2ea0b82c Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Fri, 11 Feb 2022 18:13:51 -0300 Subject: [PATCH 5/6] added error handling on manager --- src/SplitIO/Sdk/Manager/SplitManager.php | 50 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/SplitIO/Sdk/Manager/SplitManager.php b/src/SplitIO/Sdk/Manager/SplitManager.php index 38e667d1..d3ecd8a0 100644 --- a/src/SplitIO/Sdk/Manager/SplitManager.php +++ b/src/SplitIO/Sdk/Manager/SplitManager.php @@ -13,8 +13,14 @@ class SplitManager implements SplitManagerInterface { public function splitNames() { - $cache = new SplitCache(); - return $cache->getSplitNames(); + try { + $cache = new SplitCache(); + return $cache->getSplitNames(); + } catch (\Exception $e) { + SplitApp::logger()->critical('splitNames method is throwing exceptions'); + SplitApp::logger()->critical($e->getMessage()); + return []; + } } /** @@ -22,9 +28,15 @@ public function splitNames() */ public function splits() { - $cache = new SplitCache(); - $rawSplits = $cache->getAllSplits(); - return array_map('self::parseSplitView', $rawSplits); + try { + $cache = new SplitCache(); + $rawSplits = $cache->getAllSplits(); + return array_map('self::parseSplitView', $rawSplits); + } catch (\Exception $e) { + SplitApp::logger()->critical('splits method is throwing exceptions'); + SplitApp::logger()->critical($e->getMessage()); + return []; + } } /** @@ -33,20 +45,26 @@ public function splits() */ public function split($featureName) { - $featureName = InputValidator::validateFeatureName($featureName, 'split'); - if (is_null($featureName)) { - return null; - } + try { + $featureName = InputValidator::validateFeatureName($featureName, 'split'); + if (is_null($featureName)) { + return null; + } - $cache = new SplitCache(); - $raw = $cache->getSplit($featureName); - if (is_null($raw)) { - SplitApp::logger()->warning("split: you passed " . $featureName - . " that does not exist in this environment, please double check what Splits exist" - . " in the web console."); + $cache = new SplitCache(); + $raw = $cache->getSplit($featureName); + if (is_null($raw)) { + SplitApp::logger()->warning("split: you passed " . $featureName + . " that does not exist in this environment, please double check what Splits exist" + . " in the web console."); + return null; + } + return self::parseSplitView($raw); + } catch (\Exception $e) { + SplitApp::logger()->critical('split method is throwing exceptions'); + SplitApp::logger()->critical($e->getMessage()); return null; } - return self::parseSplitView($raw); } /** From 09157fe4fcd88c6cabd1e493e772914c49e34536 Mon Sep 17 00:00:00 2001 From: Matias Melograno Date: Thu, 10 Mar 2022 15:22:12 -0300 Subject: [PATCH 6/6] rollback changes in manager of err handling --- src/SplitIO/Sdk/Manager/SplitManager.php | 50 ++++++++---------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/SplitIO/Sdk/Manager/SplitManager.php b/src/SplitIO/Sdk/Manager/SplitManager.php index d3ecd8a0..38e667d1 100644 --- a/src/SplitIO/Sdk/Manager/SplitManager.php +++ b/src/SplitIO/Sdk/Manager/SplitManager.php @@ -13,14 +13,8 @@ class SplitManager implements SplitManagerInterface { public function splitNames() { - try { - $cache = new SplitCache(); - return $cache->getSplitNames(); - } catch (\Exception $e) { - SplitApp::logger()->critical('splitNames method is throwing exceptions'); - SplitApp::logger()->critical($e->getMessage()); - return []; - } + $cache = new SplitCache(); + return $cache->getSplitNames(); } /** @@ -28,15 +22,9 @@ public function splitNames() */ public function splits() { - try { - $cache = new SplitCache(); - $rawSplits = $cache->getAllSplits(); - return array_map('self::parseSplitView', $rawSplits); - } catch (\Exception $e) { - SplitApp::logger()->critical('splits method is throwing exceptions'); - SplitApp::logger()->critical($e->getMessage()); - return []; - } + $cache = new SplitCache(); + $rawSplits = $cache->getAllSplits(); + return array_map('self::parseSplitView', $rawSplits); } /** @@ -45,26 +33,20 @@ public function splits() */ public function split($featureName) { - try { - $featureName = InputValidator::validateFeatureName($featureName, 'split'); - if (is_null($featureName)) { - return null; - } + $featureName = InputValidator::validateFeatureName($featureName, 'split'); + if (is_null($featureName)) { + return null; + } - $cache = new SplitCache(); - $raw = $cache->getSplit($featureName); - if (is_null($raw)) { - SplitApp::logger()->warning("split: you passed " . $featureName - . " that does not exist in this environment, please double check what Splits exist" - . " in the web console."); - return null; - } - return self::parseSplitView($raw); - } catch (\Exception $e) { - SplitApp::logger()->critical('split method is throwing exceptions'); - SplitApp::logger()->critical($e->getMessage()); + $cache = new SplitCache(); + $raw = $cache->getSplit($featureName); + if (is_null($raw)) { + SplitApp::logger()->warning("split: you passed " . $featureName + . " that does not exist in this environment, please double check what Splits exist" + . " in the web console."); return null; } + return self::parseSplitView($raw); } /**