Skip to content

Commit f76156d

Browse files
Merge branch '4.0' into 4.1
* 4.0: (21 commits) [PropertyInfo] fix resolving parent|self type hints fixed CS fix merge [Security] Fix logout Cleanup 2 tests for the HttpException classes #27250 limiting GET_LOCK key up to 64 char due to changes in MySQL 5.7.5 and later [Config] Fix tests when path contains UTF chars [DI] Shared services should not be inlined in non-shared ones [Profiler] Remove propel & event_listener_loading category identifiers [Filesystem] Fix usages of error_get_last() [Cache][Lock] Fix usages of error_get_last() [Debug] Fix populating error_get_last() for handled silent errors fixed CS fixed CS fixed CS [FrameworkBundle] Fix cache:clear on vagrant [HttpKernel] Handle NoConfigurationException "onKernelException()" Fix misses calculation when calling getItems [DI] Display previous error messages when throwing unused bindings Fixed return type ...
2 parents a8c0836 + 3ff81e7 commit f76156d

File tree

6 files changed

+37
-7
lines changed

6 files changed

+37
-7
lines changed

Compiler/AbstractRecursivePass.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ protected function getConstructor(Definition $definition, $required)
118118

119119
$class = $definition->getClass();
120120

121-
if (!$r = $this->container->getReflectionClass($class)) {
122-
throw new RuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
121+
try {
122+
if (!$r = $this->container->getReflectionClass($class)) {
123+
throw new RuntimeException(sprintf('Invalid service "%s": class "%s" does not exist.', $this->currentId, $class));
124+
}
125+
} catch (\ReflectionException $e) {
126+
throw new RuntimeException(sprintf('Invalid service "%s": %s.', $this->currentId, lcfirst(rtrim($e->getMessage(), '.'))));
123127
}
124128
if (!$r = $r->getConstructor()) {
125129
if ($required) {

Compiler/InlineServiceDefinitionsPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@ private function isInlineableDefinition($id, Definition $definition, ServiceRefe
120120
return false;
121121
}
122122

123-
return true;
123+
return $this->container->getDefinition($ids[0])->isShared();
124124
}
125125
}

Compiler/ResolveBindingsPass.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class ResolveBindingsPass extends AbstractRecursivePass
2727
{
2828
private $usedBindings = array();
2929
private $unusedBindings = array();
30+
private $errorMessages = array();
3031

3132
/**
3233
* {@inheritdoc}
@@ -37,11 +38,19 @@ public function process(ContainerBuilder $container)
3738
parent::process($container);
3839

3940
foreach ($this->unusedBindings as list($key, $serviceId)) {
40-
throw new InvalidArgumentException(sprintf('Unused binding "%s" in service "%s".', $key, $serviceId));
41+
$message = sprintf('Unused binding "%s" in service "%s".', $key, $serviceId);
42+
if ($this->errorMessages) {
43+
$message .= sprintf("\nCould be related to%s:", 1 < \count($this->errorMessages) ? ' one of' : '');
44+
}
45+
foreach ($this->errorMessages as $m) {
46+
$message .= "\n - ".$m;
47+
}
48+
throw new InvalidArgumentException($message);
4149
}
4250
} finally {
4351
$this->usedBindings = array();
4452
$this->unusedBindings = array();
53+
$this->errorMessages = array();
4554
}
4655
}
4756

@@ -94,6 +103,7 @@ protected function processValue($value, $isRoot = false)
94103
$calls[] = array($constructor, $value->getArguments());
95104
}
96105
} catch (RuntimeException $e) {
106+
$this->errorMessages[] = $e->getMessage();
97107
$this->container->getDefinition($this->currentId)->addError($e->getMessage());
98108

99109
return parent::processValue($value, $isRoot);

Loader/Configurator/InstanceofConfigurator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InstanceofConfigurator extends AbstractServiceConfigurator
3030
/**
3131
* Defines an instanceof-conditional to be applied to following service definitions.
3232
*/
33-
final public function instanceof(string $fqcn): InstanceofConfigurator
33+
final public function instanceof(string $fqcn): self
3434
{
3535
return $this->parent->instanceof($fqcn);
3636
}

Tests/Compiler/InlineServiceDefinitionsPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testProcessDoesInlineNonSharedService()
9292
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
9393
}
9494

95-
public function testProcessInlinesMixedServicesLoop()
95+
public function testProcessDoesNotInlineMixedServicesLoop()
9696
{
9797
$container = new ContainerBuilder();
9898
$container
@@ -108,7 +108,7 @@ public function testProcessInlinesMixedServicesLoop()
108108

109109
$this->process($container);
110110

111-
$this->assertEquals($container->getDefinition('foo')->getArgument(0), $container->getDefinition('bar'));
111+
$this->assertEquals(new Reference('bar'), $container->getDefinition('foo')->getArgument(0));
112112
}
113113

114114
/**

Tests/Compiler/ResolveBindingsPassTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\DependencyInjection\Reference;
2020
use Symfony\Component\DependencyInjection\Tests\Fixtures\NamedArgumentsDummy;
21+
use Symfony\Component\DependencyInjection\Tests\Fixtures\ParentNotExists;
2122
use Symfony\Component\DependencyInjection\Tests\Fixtures\CaseSensitiveClass;
2223
use Symfony\Component\DependencyInjection\TypedReference;
2324

@@ -61,6 +62,21 @@ public function testUnusedBinding()
6162
$pass->process($container);
6263
}
6364

65+
/**
66+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
67+
* @expectedExceptionMessageRegexp Unused binding "$quz" in service [\s\S]+ Invalid service ".*\\ParentNotExists": class NotExists not found\.
68+
*/
69+
public function testMissingParent()
70+
{
71+
$container = new ContainerBuilder();
72+
73+
$definition = $container->register(ParentNotExists::class, ParentNotExists::class);
74+
$definition->setBindings(array('$quz' => '123'));
75+
76+
$pass = new ResolveBindingsPass();
77+
$pass->process($container);
78+
}
79+
6480
public function testTypedReferenceSupport()
6581
{
6682
$container = new ContainerBuilder();

0 commit comments

Comments
 (0)