Merge branch '2.3' into 2.7

* 2.3:
  [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
This commit is contained in:
Fabien Potencier 2016-02-14 14:08:36 +01:00
commit dc59e42257
3 changed files with 17 additions and 17 deletions

View File

@ -19,6 +19,8 @@ use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Config\Resource\ResourceInterface;
@ -419,9 +421,9 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return object The associated service
*
* @throws InvalidArgumentException when no definitions are available
* @throws InactiveScopeException when the current scope is not active
* @throws LogicException when a circular dependency is detected
* @throws InvalidArgumentException when no definitions are available
* @throws ServiceCircularReferenceException When a circular reference is detected
* @throws ServiceNotFoundException When the service is not defined
* @throws \Exception
*
* @see Reference
@ -440,7 +442,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
try {
$definition = $this->getDefinition($id);
} catch (InvalidArgumentException $e) {
} catch (ServiceNotFoundException $e) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return;
}
@ -788,14 +790,14 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return Definition A Definition instance
*
* @throws InvalidArgumentException if the service definition does not exist
* @throws ServiceNotFoundException if the service definition does not exist
*/
public function getDefinition($id)
{
$id = strtolower($id);
if (!array_key_exists($id, $this->definitions)) {
throw new InvalidArgumentException(sprintf('The service definition "%s" does not exist.', $id));
throw new ServiceNotFoundException($id);
}
return $this->definitions[$id];
@ -810,7 +812,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @return Definition A Definition instance
*
* @throws InvalidArgumentException if the service definition does not exist
* @throws ServiceNotFoundException if the service definition does not exist
*/
public function findDefinition($id)
{

View File

@ -21,6 +21,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@ -51,9 +53,9 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
try {
$builder->getDefinition('baz');
$this->fail('->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist');
$this->fail('->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
} catch (ServiceNotFoundException $e) {
$this->assertEquals('You have requested a non-existent service "baz".', $e->getMessage(), '->getDefinition() throws a ServiceNotFoundException if the service definition does not exist');
}
}
@ -80,9 +82,9 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
$builder = new ContainerBuilder();
try {
$builder->get('foo');
$this->fail('->get() throws an InvalidArgumentException if the service does not exist');
} catch (\InvalidArgumentException $e) {
$this->assertEquals('The service definition "foo" does not exist.', $e->getMessage(), '->get() throws an InvalidArgumentException if the service does not exist');
$this->fail('->get() throws a ServiceNotFoundException if the service does not exist');
} catch (ServiceNotFoundException $e) {
$this->assertEquals('You have requested a non-existent service "foo".', $e->getMessage(), '->get() throws a ServiceNotFoundException if the service does not exist');
}
$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');

View File

@ -102,10 +102,6 @@ class ResizeFormListener implements EventSubscriberInterface
$form = $event->getForm();
$data = $event->getData();
if (null === $data || '' === $data) {
$data = array();
}
if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
$data = array();
}