[DoctrineBridge] [PropertyInfo] Catch Doctrine\ORM\Mapping\MappingException

This commit is contained in:
Kévin Dunglas 2015-12-28 11:54:34 +01:00 committed by Fabien Potencier
parent b1a7949b36
commit ceded10f67
2 changed files with 15 additions and 0 deletions

View File

@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\PropertyInfo;
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
use Symfony\Component\PropertyInfo\Type;
@ -44,6 +45,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
$metadata = $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException $exception) {
return;
} catch (OrmMappingException $exception) {
return;
}
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
@ -58,6 +61,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
$metadata = $this->classMetadataFactory->getMetadataFor($class);
} catch (MappingException $exception) {
return;
} catch (OrmMappingException $exception) {
return;
}
if ($metadata->hasAssociation($property)) {

View File

@ -81,4 +81,14 @@ class DoctrineExtractorTest extends \PHPUnit_Framework_TestCase
array('notMapped', null),
);
}
public function testGetPropertiesCatchException()
{
$this->assertNull($this->extractor->getProperties('Not\Exist'));
}
public function testGetTypesCatchException()
{
$this->assertNull($this->extractor->getTypes('Not\Exist', 'baz'));
}
}