diff --git a/lib/ApiRequestor.php b/lib/ApiRequestor.php index 0328112b8..4c6d4fa8e 100644 --- a/lib/ApiRequestor.php +++ b/lib/ApiRequestor.php @@ -255,6 +255,27 @@ private static function _formatAppInfo($appInfo) return null; } + /** + * @static + * + * @param string $disabledFunctionsOutput - String value of the 'disable_function' setting, as output by \ini_get('disable_functions') + * @param string $functionName - Name of the function we are interesting in seeing whether or not it is disabled + * @param mixed $disableFunctionsOutput + * + * @return bool + */ + private static function _isDisabled($disableFunctionsOutput, $functionName) + { + $disabledFunctions = \explode(',', $disableFunctionsOutput); + foreach ($disabledFunctions as $disabledFunction) { + if (\trim($disabledFunction) === $functionName) { + return true; + } + } + + return false; + } + /** * @static * @@ -268,7 +289,7 @@ private static function _defaultHeaders($apiKey, $clientInfo = null) $uaString = 'Stripe/v1 PhpBindings/' . Stripe::VERSION; $langVersion = \PHP_VERSION; - $uname_disabled = \in_array('php_uname', \explode(',', \ini_get('disable_functions')), true); + $uname_disabled = static::_isDisabled(\ini_get('disable_functions'), 'php_uname'); $uname = $uname_disabled ? '(disabled)' : \php_uname(); $appInfo = Stripe::getAppInfo(); diff --git a/tests/Stripe/ApiRequestorTest.php b/tests/Stripe/ApiRequestorTest.php index db741d577..c5e798298 100644 --- a/tests/Stripe/ApiRequestorTest.php +++ b/tests/Stripe/ApiRequestorTest.php @@ -576,4 +576,38 @@ public function testHeaderStripeAccountRequestOptions() ); Charge::create([], ['stripe_account' => 'acct_123']); } + + public function testIsDisabled() + { + $reflector = new \ReflectionClass(\Stripe\ApiRequestor::class); + $method = $reflector->getMethod('_isDisabled'); + $method->setAccessible(true); + + $result = $method->invoke(null, '', 'php_uname'); + static::assertFalse($result); + + $result = $method->invoke(null, 'exec', 'php_uname'); + static::assertFalse($result); + + $result = $method->invoke(null, 'exec, procopen', 'php_uname'); + static::assertFalse($result); + + $result = $method->invoke(null, 'exec,procopen', 'php_uname'); + static::assertFalse($result); + + $result = $method->invoke(null, 'exec,php_uname', 'php_uname'); + static::assertTrue($result); + + $result = $method->invoke(null, 'exec, php_uname', 'php_uname'); + static::assertTrue($result); + + $result = $method->invoke(null, 'php_uname, exec', 'php_uname'); + static::assertTrue($result); + + $result = $method->invoke(null, 'procopen,php_uname, exec', 'php_uname'); + static::assertTrue($result); + + $result = $method->invoke(null, 'procopen, php_uname, exec', 'php_uname'); + static::assertTrue($result); + } }