8000 Merge branch '4.0' into 4.1 · symfony/symfony@3dd22cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 3dd22cb

Browse files
Merge branch '4.0' into 4.1
* 4.0: [DI] Fix bad exception on uninitialized references to non-shared services [HttpFoundation] Fix perf issue during MimeTypeGuesser intialization
2 parents 26f3318 + 2b8932f commit 3dd22cb

File tree

5 files changed

+10
-41
lines changed

5 files changed

+10
-41
lines changed

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"twig/twig": "~1.34|~2.4"
4545
},
4646
"conflict": {
47-
"symfony/security": "4.1.0-beta1,4.1.0-beta2",
47+
"symfony/security": "4.1.0-beta1|4.1.0-beta2",
4848
"symfony/var-dumper": "<3.4",
4949
"symfony/event-dispatcher": "<3.4",
5050
"symfony/framework-bundle": "<4.1",

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1514
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1615
use Symfony\Component\DependencyInjection\ContainerInterface;
1716
use Symfony\Component\DependencyInjection\Reference;
@@ -31,9 +30,6 @@ protected function processValue($value, $isRoot = false)
3130
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $value->getInvalidBehavior() && !$this->container->has($id = (string) $value)) {
3231
throw new ServiceNotFoundException($id, $this->currentId);
3332
8000 }
34-
if (ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $value->getInvalidBehavior() && $this->container->has($id = (string) $value) && !$this->container->findDefinition($id)->isShared()) {
35-
throw new InvalidArgumentException(sprintf('Invalid ignore-on-uninitialized reference found in service "%s": target service "%s" is not shared.', $this->currentId, $id));
36-
}
3733

3834
return $value;
3935
}

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,6 +1660,9 @@ private function getServiceCall(string $id, Reference $reference = null): string
16601660
if ($this->container->hasDefinition($id) && ($definition = $this->container->getDefinition($id)) && !$definition->isSynthetic()) {
16611661
if (null !== $reference && ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE === $reference->getInvalidBehavior()) {
16621662
$code = 'null';
1663+
if (!$definition->isShared()) {
1664+
return $code;
1665+
}
16631666
} elseif ($this->isTrivialInstance($definition)) {
16641667
$code = substr($this->addNewInstance($definition, '', '', $id), 8, -2);
16651668
if ($definition->isShared()) {

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,6 @@ public function testProcessThrowsExceptionOnInvalidReferenceFromInlinedDefinitio
6868
$this->process($container);
6969
}
7070

71-
/**
72-
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
73-
* @expectedExceptionMessage Invalid ignore-on-uninitialized reference found in service
74-
*/
75-
public function testProcessThrowsExceptionOnNonSharedUninitializedReference()
76-
{
77-
$container = new ContainerBuilder();
78-
79-
$container
80-
->register('a', 'stdClass')
81-
->addArgument(new Reference('b', $container::IGNORE_ON_UNINITIALIZED_REFERENCE))
82-
;
83-
84-
$container
85-
->register('b', 'stdClass')
86-
->setShared(false)
87-
;
88-
89-
$this->process($container);
90-
}
91-
9271
public function testProcessDefinitionWithBindings()
9372
{
9473
$container = new ContainerBuilder();

src/Symfony/Component/HttpFoundation/File/MimeType/MimeTypeGuesser.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,8 @@ public static function reset()
8080
*/
8181
private function __construct()
8282
{
83-
if (FileBinaryMimeTypeGuesser::isSupported()) {
84-
$this->register(new FileBinaryMimeTypeGuesser());
85-
}
86-
87-
if (FileinfoMimeTypeGuesser::isSupported()) {
88-
$this->register(new FileinfoMimeTypeGuesser());
89-
}
83+
$this->register(new FileBinaryMimeTypeGuesser());
84+
$this->register(new FileinfoMimeTypeGuesser());
9085
}
9186

9287
/**
@@ -125,18 +120,14 @@ public function guess($path)
125120
throw new AccessDeniedException($path);
126121
}
127122

128-
if (!$this->guessers) {
129-
$msg = 'Unable to guess the mime type as no guessers are available';
130-
if (!FileinfoMimeTypeGuesser::isSupported()) {
131-
$msg .= ' (Did you enable the php_fileinfo extension?)';
132-
}
133-
throw new \LogicException($msg);
134-
}
135-
136123
foreach ($this->guessers as $guesser) {
137124
if (null !== $mimeType = $guesser->guess($path)) {
138125
return $mimeType;
139126
}
140127
}
128+
129+
if (2 === \count($this->guessers) && !FileBinaryMimeTypeGuesser::isSupported() && !FileinfoMimeTypeGuesser::isSupported()) {
130+
throw new \LogicException('Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)');
131+
}
141132
}
142133
}

0 commit comments

Comments
 (0)
0