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

View File

@ -21,6 +21,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException; 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\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
@ -51,9 +53,9 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
try { try {
$builder->getDefinition('baz'); $builder->getDefinition('baz');
$this->fail('->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 (\InvalidArgumentException $e) { } catch (ServiceNotFoundException $e) {
$this->assertEquals('The service definition "baz" does not exist.', $e->getMessage(), '->getDefinition() throws an InvalidArgumentException if the service definition does not exist'); $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(); $builder = new ContainerBuilder();
try { try {
$builder->get('foo'); $builder->get('foo');
$this->fail('->get() throws an InvalidArgumentException if the service does not exist'); $this->fail('->get() throws a ServiceNotFoundException if the service does not exist');
} catch (\InvalidArgumentException $e) { } catch (ServiceNotFoundException $e) {
$this->assertEquals('The service definition "foo" does not exist.', $e->getMessage(), '->get() throws an InvalidArgumentException if the service does not exist'); $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'); $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(); $form = $event->getForm();
$data = $event->getData(); $data = $event->getData();
if (null === $data || '' === $data) {
$data = array();
}
if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
$data = array(); $data = array();
} }