Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65b34cb

Browse files
committed
Fix ini_get() for boolean values
1 parent 63c74f7 commit 65b34cb

File tree

19 files changed

+30
-30
lines changed

19 files changed

+30
-30
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__
6363
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
6464
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
6565
}
66-
if (extension_loaded('openssl') && ini_get('allow_url_fopen') && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
66+
if (extension_loaded('openssl') && filter_var(ini_get('allow_url_fopen'), FILTER_VALIDATE_BOOLEAN) && !isset($_SERVER['http_proxy']) && !isset($_SERVER['https_proxy'])) {
6767
$remoteZip = "https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip";
6868
$remoteZipStream = @fopen($remoteZip, 'rb');
6969
if (!$remoteZipStream) {
@@ -214,7 +214,7 @@ if ($components) {
214214
// STATUS_STACK_BUFFER_OVERRUN (-1073740791/0xC0000409)
215215
// STATUS_ACCESS_VIOLATION (-1073741819/0xC0000005)
216216
// STATUS_HEAP_CORRUPTION (-1073740940/0xC0000374)
217-
if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !ini_get('apc.enable_cli') || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
217+
if ($procStatus && ('\\' !== DIRECTORY_SEPARATOR || !extension_loaded('apcu') || !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN) || !in_array($procStatus, array(-1073740791, -1073741819, -1073740940)))) {
218218
$exit = $procStatus;
219219
echo "\033[41mKO\033[0m $component\n\n";
220220
} else {

src/Symfony/Bundle/FrameworkBundle/Command/AboutCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
8484
array('Architecture', (PHP_INT_SIZE * 8).' bits'),
8585
array('Intl locale', class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'),
8686
array('Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'),
87-
array('OPcache', \extension_loaded('Zend OPcache') && ini_get('opcache.enable') ? 'true' : 'false'),
88-
array('APCu', \extension_loaded('apcu') && ini_get('apc.enabled') ? 'true' : 'false'),
87+
array('OPcache', \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'),
88+
array('APCu', \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'),
8989
array('Xdebug', \extension_loaded('xdebug') ? 'true' : 'false'),
9090
);
9191

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public static function createSystemCache($namespace, $defaultLifetime, $version,
117117
}
118118

119119
$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
120-
if ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli')) {
120+
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
121121
$apcu->setLogger(new NullLogger());
122122
} elseif (null !== $logger) {
123123
$apcu->setLogger($logger);

src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function __construct($file, AdapterInterface $fallbackPool)
4040
{
4141
$this->file = $file;
4242
$this->pool = $fallbackPool;
43-
$this->zendDetectUnicode = ini_get('zend.detect_unicode');
43+
$this->zendDetectUnicode = filter_var(ini_get('zend.detect_unicode'), FILTER_VALIDATE_BOOLEAN);
4444
$this->createCacheItem = \Closure::bind(
4545
function ($key, $value, $isHit) {
4646
$item = new CacheItem();
@@ -68,7 +68,7 @@ function ($key, $value, $isHit) {
6868
public static function create($file, CacheItemPoolInterface $fallbackPool)
6969
{
7070
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
71-
if ((\PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || \defined('HHVM_VERSION')) {
71+
if ((\PHP_VERSION_ID >= 70000 && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) || \defined('HHVM_VERSION')) {
7272
if (!$fallbackPool instanceof AdapterInterface) {
7373
$fallbackPool = new ProxyAdapter($fallbackPool);
7474
}

src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function __construct($namespace = '', $defaultLifetime = 0, $directory =
3636

3737
$e = new \Exception();
3838
$this->includeHandler = function () use ($e) { throw $e; };
39-
$this->zendDetectUnicode = ini_get('zend.detect_unicode');
39+
$this->zendDetectUnicode = filter_var(ini_get('zend.detect_unicode'), FILTER_VALIDATE_BOOLEAN);
4040
}
4141
}

src/Symfony/Component/Cache/Simple/PhpArrayCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct($file, CacheInterface $fallbackPool)
3636
{
3737
$this->file = $file;
3838
$this->pool = $fallbackPool;
39-
$this->zendDetectUnicode = ini_get('zend.detect_unicode');
39+
$this->zendDetectUnicode = filter_var(ini_get('zend.detect_unicode'), FILTER_VALIDATE_BOOLEAN);
4040
}
4141

4242
/**
@@ -51,7 +51,7 @@ public function __construct($file, CacheInterface $fallbackPool)
5151
public static function create($file, CacheInterface $fallbackPool)
5252
{
5353
// Shared memory is available in PHP 7.0+ with OPCache enabled and in HHVM
54-
if ((\PHP_VERSION_ID >= 70000 && ini_get('opcache.enable')) || \defined('HHVM_VERSION')) {
54+
if ((\PHP_VERSION_ID >= 70000 && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) || \defined('HHVM_VERSION')) {
5555
return new static($file, $fallbackPool);
5656
}
5757

src/Symfony/Component/Cache/Simple/PhpFilesCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ public function __construct($namespace = '', $defaultLifetime = 0, $directory =
3636

3737
$e = new \Exception();
3838
$this->includeHandler = function () use ($e) { throw $e; };
39-
$this->zendDetectUnicode = ini_get('zend.detect_unicode');
39+
$this->zendDetectUnicode = filter_var(ini_get('zend.detect_unicode'), FILTER_VALIDATE_BOOLEAN);
4040
}
4141
}

src/Symfony/Component/Cache/Tests/Adapter/ApcuAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ class ApcuAdapterTest extends AdapterTestCase
2424

2525
public function createCachePool($defaultLifetime = 0)
2626
{
27-
if (!\function_exists('apcu_fetch') || !ini_get('apc.enabled')) {
27+
if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN)) {
2828
$this->markTestSkipped('APCu extension is required.');
2929
}
30-
if ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli')) {
30+
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
3131
if ('testWithCliSapi' !== $this->getName()) {
3232
$this->markTestSkipped('apc.enable_cli=1 is required.');
3333
}

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function provideServersSetting()
137137
'localhost',
138138
11222,
139139
);
140-
if (ini_get('memcached.use_sasl')) {
140+
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
141141
yield array(
142142
'memcached://user:[email protected]?weight=50',
143143
'127.0.0.1',
@@ -154,7 +154,7 @@ public function provideServersSetting()
154154
'/var/local/run/memcached.socket',
155155
0,
156156
);
157-
if (ini_get('memcached.use_sasl')) {
157+
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
158158
yield array(
159159
'memcached://user:password@/var/local/run/memcached.socket?weight=25',
160160
'/var/local/run/memcached.socket',

src/Symfony/Component/Cache/Tests/Simple/ApcuCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class ApcuCacheTest extends CacheTestCase
2323

2424
public function createSimpleCache($defaultLifetime = 0)
2525
{
26-
if (!\function_exists('apcu_fetch') || !ini_get('apc.enabled') || ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli'))) {
26+
if (!\function_exists('apcu_fetch') || !filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN) || ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))) {
2727
$this->markTestSkipped('APCu extension is required.');
2828
}
2929
if ('\\' === \DIRECTORY_SEPARATOR) {

src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function provideServersSetting()
146146
'localhost',
147147
11222,
148148
);
149-
if (ini_get('memcached.use_sasl')) {
149+
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
150150
yield array(
151151
'memcached://user:[email protected]?weight=50',
152152
'127.0.0.1',
@@ -163,7 +163,7 @@ public function provideServersSetting()
163163
'/var/local/run/memcached.socket',
164164
0,
165165
);
166-
if (ini_get('memcached.use_sasl')) {
166+
if (filter_var(ini_get('memcached.use_sasl'), FILTER_VALIDATE_BOOLEAN)) {
167167
yield array(
168168
'memcached://user:password@/var/local/run/memcached.socket?weight=25',
169169
'/var/local/run/memcached.socket',

src/Symfony/Component/Cache/Traits/ApcuTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ trait ApcuTrait
2323
{
2424
public static function isSupported()
2525
{
26-
return \function_exists('apcu_fetch') && ini_get('apc.enabled');
26+
return \function_exists('apcu_fetch') && filter_var(ini_get('apc.enabled'), FILTER_VALIDATE_BOOLEAN);
2727
}
2828

2929
private function init($namespace, $defaultLifetime, $version)
@@ -75,7 +75,7 @@ protected function doHave($id)
7575
*/
7676
protected function doClear($namespace)
7777
{
78-
return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || ini_get('apc.enable_cli'))
78+
return isset($namespace[0]) && class_exists('APCuIterator', false) && ('cli' !== \PHP_SAPI || filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN))
7979
? apcu_delete(new \APCuIterator(sprintf('/^%s/', preg_quote($namespace, '/')), APC_ITER_KEY))
8080
: apcu_clear_cache();
8181
}

src/Symfony/Component/Cache/Traits/PhpFilesTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait PhpFilesTrait
3030

3131
public static function isSupported()
3232
{
33-
return \function_exists('opcache_invalidate') && ini_get('opcache.enable');
33+
return \function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN);
3434
}
3535

3636
/**
@@ -40,7 +40,7 @@ public function prune()
4040
{
4141
$time = time();
4242
$pruned = true;
43-
$allowCompile = 'cli' !== \PHP_SAPI || ini_get('opcache.enable_cli');
43+
$allowCompile = 'cli' !== \PHP_SAPI || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN);
4444

4545
set_error_handler($this->includeHandler);
4646
try {
@@ -119,7 +119,7 @@ protected function doSave(array $values, $lifetime)
119119
{
120120
$ok = true;
121121
$data = array($lifetime ? time() + $lifetime : PHP_INT_MAX, '');
122-
$allowCompile = 'cli' !== \PHP_SAPI || ini_get('opcache.enable_cli');
122+
$allowCompile = 'cli' !== \PHP_SAPI || filter_var(ini_get('opcache.enable_cli'), FILTER_VALIDATE_BOOLEAN);
123123

124124
foreach ($values as $key => $value) {
125125
if (null === $value || \is_object($value)) {

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/AbstractSessionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function destroy($sessionId)
131131
if (\PHP_VERSION_ID < 70000) {
132132
$this->prefetchData = null;
133133
}
134-
if (!headers_sent() && ini_get('session.use_cookies')) {
134+
if (!headers_sent() && filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN)) {
135135
if (!$this->sessionName) {
136136
throw new \LogicException(sprintf('Session name cannot be empty, did you forget to call "parent::open()" in "%s"?.', \get_class($this)));
137137
}
@@ -159,7 +159,7 @@ public function destroy($sessionId)
159159
header($h, false);
160160
}
161161
} else {
162-
setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure'), ini_get('session.cookie_httponly'));
162+
setcookie($this->sessionName, '', 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), filter_var(ini_get('session.cookie_secure'), FILTER_VALIDATE_BOOLEAN), filter_var(ini_get('session.cookie_httponly'), FILTER_VALIDATE_BOOLEAN));
163163
}
164164
}
165165

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ protected function doRead($sessionId)
637637
throw new \RuntimeException('Failed to read session: INSERT reported a duplicate id but next SELECT did not return any data.');
638638
}
639639

640-
if (!ini_get('session.use_strict_mode') && self::LOCK_TRANSACTIONAL === $this->lockMode && 'sqlite' !== $this->driver) {
640+
if (!filter_var(ini_get('session.use_strict_mode'), FILTER_VALIDATE_BOOLEAN) && self::LOCK_TRANSACTIONAL === $this->lockMode && 'sqlite' !== $this->driver) {
641641
// In strict mode, session fixation is not possible: new sessions always start with a unique
642642
// random id, so that concurrency is not possible and this code path can be skipped.
643643
// Exclusive-reading of non-existent rows does not block, so we need to do an insert to block

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function start()
137137
throw new \RuntimeException('Failed to start the session: already started by PHP.');
138138
}
139139

140-
if (ini_get('session.use_cookies') && headers_sent($file, $line)) {
140+
if (filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN) && headers_sent($file, $line)) {
141141
throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
142142
}
143143

src/Symfony/Component/HttpFoundation/Tests/Fixtures/response-functional/common.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ error_reporting(-1);
2222
ini_set('html_errors', 0);
2323
ini_set('display_errors', 1);
2424

25-
if (ini_get('xdebug.default_enable')) {
25+
if (filter_var(ini_get('xdebug.default_enable'), FILTER_VALIDATE_BOOLEAN)) {
2626
xdebug_disable();
2727
}
2828

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/PdoSessionHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function testReadLockedConvertsStreamToString()
160160
if (\defined('HHVM_VERSION')) {
161161
$this->markTestSkipped('PHPUnit_MockObject cannot mock the PDOStatement class on HHVM. See https://github.com/sebastianbergmann/phpunit-mock-objects/pull/289');
162162
}
163-
if (ini_get('session.use_strict_mode')) {
163+
if (filter_var(ini_get('session.use_strict_mode'), FILTER_VALIDATE_BOOLEAN)) {
164164
$this->markTestSkipped('Strict mode needs no locking for new sessions.');
165165
}
166166

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ public static function createCache($namespace, $defaultLifetime, $version, Logge
910910
}
911911

912912
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version);
913-
if ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli')) {
913+
if ('cli' === \PHP_SAPI && !filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOLEAN)) {
914914
$apcu->setLogger(new NullLogger());
915915
} elseif (null !== $logger) {
916916
$apcu->setLogger($logger);

0 commit comments

Comments
 (0)