bug #24251 [PropertyAccess] Set a NullLogger in ApcuAdapter when Apcu is disabled in CLI (iamluc)

This PR was merged into the 3.3 branch.

Discussion
----------

[PropertyAccess] Set a NullLogger in ApcuAdapter when Apcu is disabled in CLI

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Same check as in https://github.com/symfony/symfony/pull/23390/files#diff-a5185cd58702e8e073786794a423cb27R112

Commits
-------

4a01cd8 Set a NullLogger in ApcuAdapter when Apcu is disabled in CLI
This commit is contained in:
Nicolas Grekas 2017-09-26 12:13:39 +02:00
commit acbb2ab9ec
2 changed files with 5 additions and 2 deletions

View File

@ -116,7 +116,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
}
$apcu = new ApcuAdapter($namespace, (int) $defaultLifetime / 5, $version);
if ('cli' === PHP_SAPI && !ini_get('apc.enable_cli')) {
if ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli')) {
$apcu->setLogger(new NullLogger());
} elseif (null !== $logger) {
$apcu->setLogger($logger);

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\PropertyAccess;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\NullAdapter;
@ -928,7 +929,9 @@ class PropertyAccessor implements PropertyAccessorInterface
}
$apcu = new ApcuAdapter($namespace, $defaultLifetime / 5, $version);
if (null !== $logger) {
if ('cli' === \PHP_SAPI && !ini_get('apc.enable_cli')) {
$apcu->setLogger(new NullLogger());
} elseif (null !== $logger) {
$apcu->setLogger($logger);
}