8000 Merge branch '4.4' into 5.3 · symfony/symfony@b460e07 · GitHub
[go: up one dir, main page]

Skip to content

Commit b460e07

Browse files
committed
Merge branch '4.4' into 5.3
* 4.4: Throw exception if incompatible version of psr/simple-cache is used [DependencyInjection] copy synthetic status when resolving child definitions [HttpClient] Fix Failed to open stream: Too many open files [Console] use STDOUT/ERR in ConsoleOutput to save opening too many file descriptors [Cache] Set mtime of cache files 1 year into future if they do not expire [DependencyInjection] remove arbitratry limitation to exclude inline services from bindings
2 parents 6cdfd71 + 8a0ed01 commit b460e07

File tree

10 files changed

+49
-15
lines changed

10 files changed

+49
-15
lines changed

src/Symfony/Component/Cache/Psr16Cache.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
use Symfony\Component\Cache\Exception\InvalidArgumentException;
2020
use Symfony\Component\Cache\Traits\ProxyTrait;
2121

22+
if (null !== (new \ReflectionMethod(CacheInterface::class, 'get'))->getReturnType()) {
23+
throw new \LogicException('psr/simple-cache 3.0+ is not compatible with this version of symfony/cache. Please upgrade symfony/cache to 6.0+ or downgrade psr/simple-cache to 1.x or 2.x.');
24+
}
25+
2226
/**
2327
* Turns a PSR-6 cache into a PSR-16 one.
2428
*

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function write(string $file, string $data, int $expiresAt = null)
109109
fclose($h);
110110

111111
if (null !== $expiresAt) {
112-
touch($this->tmp, $expiresAt);
112+
touch($this->tmp, $expiresAt ?: time() + 31556952); // 1 year in seconds
113113
}
114114

115115
return rename($this->tmp, $file);

src/Symfony/Component/Console/Output/ConsoleOutput.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,20 @@ private function openOutputStream()
153153
return fopen('php://output', 'w');
154154
}
155155

156-
return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w');
156+
// Use STDOUT when possible to prevent from opening too many file descriptors
157+
return \defined('STDOUT') ? \STDOUT : (@fopen('php://stdout', 'w') ?: fopen('php://output', 'w'));
157158
}
158159

159160
/**
160161
* @return resource
161162
*/
162163
private function openErrorStream()
163164
{
164-
return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w');
165+
if (!$this->hasStderrSupport()) {
166+
return fopen('php://output', 'w');
167+
}
168+
169+
// Use STDERR when possible to prevent from opening too many file descriptors
170+
return \defined('STDERR') ? \STDERR : (@fopen('php://stderr', 'w') ?: fopen('php://output', 'w'));
165171
}
166172
}

src/Symfony/Component/DependencyInjection/Compiler/ResolveChildDefinitionsPass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ private function doResolveDefinition(ChildDefinition $definition): Definition
115115

116116
$def->setBindings($definition->getBindings() + $parentDef->getBindings());
117117

118+
$def->setSynthetic($definition->isSynthetic());
119+
118120
// overwrite with values specified in the decorator
119121
$changes = $definition->getChanges();
120122
if (isset($changes['class'])) {

src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
1313

1414
use Symfony\Component\DependencyInjection\Argument\BoundArgument;
15-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1615
use Symfony\Component\DependencyInjection\Loader\Configurator\DefaultsConfigurator;
1716
use Symfony\Component\DependencyInjection\Loader\Configurator\InstanceofConfigurator;
18-
use Symfony\Component\DependencyInjection\Reference;
1917

2018
trait BindTrait
2119
{
@@ -34,9 +32,6 @@ trait BindTrait
3432
final public function bind(string $nameOrFqcn, $valueOrRef): self
3533
{
3634
$valueOrRef = static::processValue($valueOrRef, true);
37-
if (!preg_match('/^(?:(?:array|bool|float|int|string|iterable)[ \t]*+)?\$/', $nameOrFqcn) && !$valueOrRef instanceof Reference) {
38-
throw new InvalidArgumentException(sprintf('Invalid binding for service "%s": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "%s".', $this->id, $nameOrFqcn));
39-
}
4035
$bindings = $this->definition->getBindings();
4136
$type = $this instanceof DefaultsConfigurator ? BoundArgument::DEFAULTS_BINDING : ($this instanceof InstanceofConfigurator ? BoundArgument::INSTANCEOF_BINDING : BoundArgument::SERVICE_BINDING);
4237
$bindings[$nameOrFqcn] = new BoundArgument($valueOrRef, true, $type, $this->path ?? null);

src/Symfony/Component/DependencyInjection/Tests/Compiler/ResolveChildDefinitionsPassTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,21 @@ public function testProcessDetectsChildDefinitionIndirectCircularReference()
421421

422422
$this->process($container);
423423
}
424+
425+
public function testProcessCopiesSyntheticStatus()
426+
{
427+
$container = new ContainerBuilder();
428+
429+
$container->register('parent');
430+
431+
$container
432+
->setDefinition('child', new ChildDefinition('parent'))
433+
->setSynthetic(true)
434+
;
435+
436+
$this->process($container);
437+
438+
$def = $container->getDefinition('child');
439+
$this->assertTrue($def->isSynthetic());
440+
}
424441
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/Prototype/Foo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#[When(env: 'dev')]
99
class Foo implements FooInterface, Sub\BarInterface
1010
{
11-
public function __construct($bar = null, iterable $foo = null)
11+
public function __construct($bar = null, iterable $foo = null, object $baz = null)
1212
{
1313
}
1414

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/defaults.expected.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ services:
1515
- t: { a: b }
1616
autowire: true
1717
autoconfigure: true
18-
arguments: ['@bar', !tagged_iterator foo]
18+
arguments: ['@bar', !tagged_iterator foo, !service { class: Baz }]
1919
bar:
2020
class: Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Foo
2121
public: true
2222
tags:
2323
- t: { a: b }
2424
autowire: true
25-
arguments: [null, !tagged_iterator foo]
25+
arguments: [null, !tagged_iterator foo, !service { class: Baz }]
2626
calls:
2727
- [setFoo, ['@bar']]
2828

src/Symfony/Component/DependencyInjection/Tests/Fixtures/config/defaults.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
->tag('t', ['a' => 'b'])
1616
->bind(Foo::class, service('bar'))
1717
->bind('iterable $foo', tagged_iterator('foo'))
18+
->bind('object $baz', inline('Baz'))
1819
->public();
1920

2021
$s->set(Foo::class)->args([service('bar')])->public();

src/Symfony/Component/HttpClient/Internal/CurlClientState.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424
final class CurlClientState extends ClientState
2525
{
26-
/** @var \CurlMultiHandle|resource */
26+
/** @var \CurlMultiHandle|resource|null */
2727
public $handle;
28-
/** @var \CurlShareHandle|resource */
28+
/** @var \CurlShareHandle|resource|null */
2929
public $share;
3030
/** @var PushedResponse[] */
3131
public $pushedResponses = [];
@@ -68,8 +68,17 @@ public function __construct(int $maxHostConnections, int $maxPendingPushes)
6868
return;
6969
}
7070

71-
curl_multi_setopt($this->handle, \CURLMOPT_PUSHFUNCTION, function ($parent, $pushed, array $requestHeaders) use ($maxPendingPushes) {
72-
return $this->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
71+
// Clone to prevent a circular reference
72+
$multi = clone $this;
73+
$multi->handle = null;
74+
$multi->share = null;
75+
$multi->pushedResponses = &$this->pushedResponses;
76+
$multi->logger = &$this->logger;
77+
$multi->handlesActivity = &$this->handlesActivity;
78+
$multi->openHandles = &$this->openHandles;
79+
80+
curl_multi_setopt($this->handle, \CURLMOPT_PUSHFUNCTION, static function ($parent, $pushed, array $requestHeaders) use ($multi, $maxPendingPushes) {
81+
return $multi->handlePush($parent, $pushed, $requestHeaders, $maxPendingPushes);
7382
});
7483
}
7584

0 commit comments

Comments
 (0)
0