Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Messenger] Added check if json_encode succeeded #35137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 7, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ private function getContainerBuilder(): ContainerBuilder
$refl->setAccessible(true);
$refl->setValue($parameterBag, true);

$passConfig = $container->getCompilerPassConfig();
$passConfig->setRemovingPasses([]);
$passConfig->setAfterRemovingPasses([]);

$skippedIds = $kernelContainer->getRemovedIds();
$skippedIds = [];
foreach ($container->getServiceIds() as $serviceId) {
if (0 === strpos($serviceId, '.errored.')) {
$skippedIds[$serviceId] = true;
}
}
}

$container->setParameter('container.build_hash', 'lint_container');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ public function process(ContainerBuilder $container)
if (ChainAdapter::class === $class) {
$adapters = [];
foreach ($adapter->getArgument(0) as $provider => $adapter) {
$chainedPool = $adapter = new ChildDefinition($adapter);
if ($adapter instanceof ChildDefinition) {
$chainedPool = $adapter;
} else {
$chainedPool = $adapter = new ChildDefinition($adapter);
}

$chainedTags = [\is_int($provider) ? [] : ['provider' => $provider]];
$chainedClass = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
namespace Symfony\Component\Cache\Tests\DependencyInjection;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\ChainAdapter;
use Symfony\Component\Cache\Adapter\RedisAdapter;
use Symfony\Component\Cache\DependencyInjection\CachePoolPass;
use Symfony\Component\DependencyInjection\ChildDefinition;
Expand Down Expand Up @@ -174,4 +176,42 @@ public function testThrowsExceptionWhenCachePoolTagHasUnknownAttributes()

$this->cachePoolPass->process($container);
}

public function testChainAdapterPool()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.container_class', 'app');
$container->setParameter('kernel.project_dir', 'foo');

$container->register('cache.adapter.array', ArrayAdapter::class)
->addTag('cache.pool');
$container->register('cache.adapter.apcu', ApcuAdapter::class)
->setArguments([null, 0, null])
->addTag('cache.pool');
$container->register('cache.chain', ChainAdapter::class)
->addArgument(['cache.adapter.array', 'cache.adapter.apcu'])
->addTag('cache.pool');
$container->setDefinition('cache.app', new ChildDefinition('cache.chain'))
->addTag('cache.pool');
$container->setDefinition('doctrine.result_cache_pool', new ChildDefinition('cache.app'))
->addTag('cache.pool');

$this->cachePoolPass->process($container);

$appCachePool = $container->getDefinition('cache.app');
$this->assertInstanceOf(ChildDefinition::class, $appCachePool);
$this->assertSame('cache.chain', $appCachePool->getParent());

$chainCachePool = $container->getDefinition('cache.chain');
$this->assertNotInstanceOf(ChildDefinition::class, $chainCachePool);
$this->assertCount(2, $chainCachePool->getArgument(0));
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[0]);
$this->assertSame('cache.adapter.array', $chainCachePool->getArgument(0)[0]->getParent());
$this->assertInstanceOf(ChildDefinition::class, $chainCachePool->getArgument(0)[1]);
$this->assertSame('cache.adapter.apcu', $chainCachePool->getArgument(0)[1]->getParent());

$doctrineCachePool = $container->getDefinition('doctrine.result_cache_pool');
$this->assertInstanceOf(ChildDefinition::class, $doctrineCachePool);
$this->assertSame('cache.app', $doctrineCachePool->getParent());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\EnvNotFoundException;
Expand Down Expand Up @@ -219,6 +220,10 @@ private function checkType(Definition $checkedDefinition, $value, \ReflectionPar
return;
}

if (\in_array($type, ['callable', 'Closure'], true) && $value instanceof ServiceClosureArgument) {
return;
}

if ('iterable' === $type && (\is_array($value) || $value instanceof \Traversable || $value instanceof IteratorArgument)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Compiler\CheckTypeDeclarationsPass;
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand Down Expand Up @@ -697,4 +698,28 @@ public function testProcessHandleClosureForCallable()

$this->addToAssertionCount(1);
}

public function testProcessSuccessWhenPassingServiceClosureArgumentToCallable()
{
$container = new ContainerBuilder();

$container->register('bar', BarMethodCall::class)
->addMethodCall('setCallable', [new ServiceClosureArgument(new Reference('foo'))]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}

public function testProcessSuccessWhenPassingServiceClosureArgumentToClosure()
{
$container = new ContainerBuilder();

$container->register('bar', BarMethodCall::class)
->addMethodCall('setClosure', [new ServiceClosureArgument(new Reference('foo'))]);

(new CheckTypeDeclarationsPass(true))->process($container);

$this->addToAssertionCount(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ public function setIterable(iterable $iterable)
public function setCallable(callable $callable): void
{
}

public function setClosure(\Closure $closure): void
{
}
}
11 changes: 8 additions & 3 deletions 11 src/Symfony/Component/HttpClient/HttplugClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Http\Client\Exception\RequestException;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient as HttplugInterface;
use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\Psr17FactoryDiscovery;
use Http\Message\RequestFactory;
use Http\Message\StreamFactory;
Expand Down Expand Up @@ -75,9 +76,13 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
}

$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
try {
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
} catch (NotFoundException $e) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
}
}

$this->waitLoop = new HttplugWaitLoop($this->client, $this->promisePool, $this->responseFactory, $this->streamFactory);
Expand Down
11 changes: 8 additions & 3 deletions 11 src/Symfony/Component/HttpClient/Psr18Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\HttpClient;

use Http\Discovery\Exception\NotFoundException;
use Http\Discovery\Psr17FactoryDiscovery;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
Expand Down Expand Up @@ -68,9 +69,13 @@ public function __construct(HttpClientInterface $client = null, ResponseFactoryI
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\Psr18Client" as no PSR-17 factories have been provided. Try running "composer require nyholm/psr7".');
}

$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
try {
$psr17Factory = class_exists(Psr17Factory::class, false) ? new Psr17Factory() : null;
$this->responseFactory = $this->responseFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findResponseFactory();
$this->streamFactory = $this->streamFactory ?? $psr17Factory ?? Psr17FactoryDiscovery::findStreamFactory();
} catch (NotFoundException $e) {
throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\HttplugClient" as no PSR-17 factories have been found. Try running "composer require nyholm/psr7".', 0, $e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ public function testGetNonBlocking()
$redis->del('messenger-getnonblocking');
}

public function testJsonError()
{
$redis = new \Redis();

$connection = Connection::fromDsn('redis://localhost/json-error', [], $redis);

try {
$connection->add("\xB1\x31", []);
} catch (TransportException $e) {
}

$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
}

public function testMaxEntries()
{
$redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
'uniqid' => uniqid('', true),
]);

if (false === $message) {
throw new TransportException(json_last_error_msg());
}

$score = (int) ($this->getCurrentTimeInMilliseconds() + $delayInMs);
$added = $this->connection->zadd($this->queue, ['NX'], $score, $message);
} else {
Expand All @@ -256,6 +260,10 @@ public function add(string $body, array $headers, int $delayInMs = 0): void
'headers' => $headers,
]);

if (false === $message) {
throw new TransportException(json_last_error_msg());
}

if ($this->maxEntries) {
$added = $this->connection->xadd($this->stream, '*', ['message' => $message], $this->maxEntries, true);
} else {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.