From adef14f6873ac4d69ff4895d201069684e503227 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 10 May 2011 12:30:27 +0200 Subject: [PATCH] [Form] Make the PropertyPathMapper class use the UnexpectedTypeException --- .../Core/DataMapper/PropertyPathMapper.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php b/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php index 312dcafaf2..37b5a66209 100644 --- a/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php +++ b/src/Symfony/Component/Form/Extension/Core/DataMapper/PropertyPathMapper.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\DataMapperInterface; use Symfony\Component\Form\Util\VirtualFormAwareIterator; use Symfony\Component\Form\Exception\FormException; +use Symfony\Component\Form\Exception\UnexpectedTypeException; class PropertyPathMapper implements DataMapperInterface { @@ -29,15 +30,22 @@ class PropertyPathMapper implements DataMapperInterface $this->dataClass = $dataClass; } + /** + * + * @param dataClass $data + * @param array $forms + * + * @throws UnexpectedTypeException if the type of the data parameter is not supported + */ public function mapDataToForms($data, array $forms) { if (!empty($data) && !is_array($data) && !is_object($data)) { - throw new \InvalidArgumentException(sprintf('Expected argument of type object or array, %s given', gettype($data))); + throw new UnexpectedTypeException($data, 'Object, array or empty'); } if (!empty($data)) { - if ($this->dataClass && !$data instanceof $this->dataClass) { - throw new FormException(sprintf('Form data should be instance of %s', $this->dataClass)); + if (null !== $this->dataClass && !$data instanceof $this->dataClass) { + throw new UnexpectedTypeException($data, $this->dataClass); } $iterator = new VirtualFormAwareIterator($forms);