Skip to content

Commit b8ac028

Browse files
committed
Merge branch '2.7' into 2.8
* 2.7: Fix locale and written standard inconsistencies for Norwegian translations [Form] [Validator] Fix locale inconsistencies in Norwegian translations fixed CS [DependencyInjection] fixed exceptions thrown by get method of ContainerBuilder [Form] remove useless code in ResizeFormListener
2 parents 57cdbcc + 2edd0cd commit b8ac028

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

ContainerBuilder.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
2020
use Symfony\Component\DependencyInjection\Exception\LogicException;
2121
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
22+
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
23+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2224
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
2325
use Symfony\Component\Config\Resource\FileResource;
2426
use Symfony\Component\Config\Resource\ResourceInterface;
@@ -438,9 +440,9 @@ public function has($id)
438440
*
439441
* @return object The associated service
440442
*
441-
* @throws InvalidArgumentException when no definitions are available
442-
* @throws InactiveScopeException when the current scope is not active
443-
* @throws LogicException when a circular dependency is detected
443+
* @throws InvalidArgumentException when no definitions are available
444+
* @throws ServiceCircularReferenceException When a circular reference is detected
445+
* @throws ServiceNotFoundException When the service is not defined
444446
* @throws \Exception
445447
*
446448
* @see Reference
@@ -459,7 +461,7 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
459461

460462
try {
461463
$definition = $this->getDefinition($id);
462-
} catch (InvalidArgumentException $e) {
464+
} catch (ServiceNotFoundException $e) {
463465
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
464466
return;
465467
}
@@ -807,14 +809,14 @@ public function hasDefinition($id)
807809
*
808810
* @return Definition A Definition instance
809811
*
810-
* @throws InvalidArgumentException if the service definition does not exist
812+
* @throws ServiceNotFoundException if the service definition does not exist
811813
*/
812814
public function getDefinition($id)
813815
{
814816
$id = strtolower($id);
815817

816818
if (!array_key_exists($id, $this->definitions)) {
817-
throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
819+
throw new ServiceNotFoundException($id);
818820
}
819821

820822
return $this->definitions[$id];
@@ -829,7 +831,7 @@ public function getDefinition($id)
829831
*
830832
* @return Definition A Definition instance
831833
*
832-
* @throws InvalidArgumentException if the service definition does not exist
834+
* @throws ServiceNotFoundException if the service definition does not exist
833835
*/
834836
public function findDefinition($id)
835837
{

Tests/ContainerBuilderTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Symfony\Component\DependencyInjection\Definition;
2222
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
2323
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
24+
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
25+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2426
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
2527
use Symfony\Component\DependencyInjection\Reference;
2628
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@@ -51,9 +53,9 @@ public function testDefinitions()
5153

5254
try {
5355
$builder->getDefinition('baz');
54-
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
55-
} catch (\InvalidArgumentException $e) {
56-
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
56+
$this->fail('->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
57+
} catch (ServiceNotFoundException $e) {
58+
$this->assertEquals('You have requested a non-existent service "baz".', $e->getMessage(), '->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
5759
}
5860
}
5961

@@ -102,9 +104,9 @@ public function testGet()
102104
$builder = new ContainerBuilder();
103105
try {
104106
$builder->get('foo');
105-
$this->fail('->get() throws an InvalidArgumentException if the service does not exist');
106-
} catch (\InvalidArgumentException $e) {
107-
$this->assertEquals('The service definition "foo" does not exist.', $e->getMessage(), '->get() throws an InvalidArgumentException if the service does not exist');
107+
$this->fail('->get() throws a ServiceNotFoundException if the service does not exist');
108+
} catch (ServiceNotFoundException $e) {
109+
$this->assertEquals('You have requested a non-existent service "foo".', $e->getMessage(), '->get() throws a ServiceNotFoundException if the service does not exist');
108110
}
109111

110112
$this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE), '->get() returns null if the service does not exist and NULL_ON_INVALID_REFERENCE is passed as a second argument');

0 commit comments

Comments
 (0)