bug #17152 [DoctrineBridge] [PropertyInfo] Catch Doctrine\ORM\Mapping\MappingException (dunglas)
This PR was squashed before being merged into the 2.8 branch (closes #17152).
Discussion
----------
[DoctrineBridge] [PropertyInfo] Catch Doctrine\ORM\Mapping\MappingException
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | n/a
| License | MIT
| Doc PR | n/a
Sometimes the Doctrine ORM `ClassMetadataFactory` throws a `Doctrine\Common\Persistence\Mapping\MappingException` exception, sometime a `Doctrine\ORM\Mapping\MappingException`.
This PR catch both.
Port of dunglas/php-property-info#10.
Commits
-------
ceded10
[DoctrineBridge] [PropertyInfo] Catch Doctrine\ORM\Mapping\MappingException
This commit is contained in:
commit
ddc508bbd4
@ -14,6 +14,7 @@ namespace Symfony\Bridge\Doctrine\PropertyInfo;
|
|||||||
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
|
use Doctrine\Common\Persistence\Mapping\ClassMetadataFactory;
|
||||||
use Doctrine\Common\Persistence\Mapping\MappingException;
|
use Doctrine\Common\Persistence\Mapping\MappingException;
|
||||||
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
use Doctrine\ORM\Mapping\ClassMetadataInfo;
|
||||||
|
use Doctrine\ORM\Mapping\MappingException as OrmMappingException;
|
||||||
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
|
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
|
||||||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
||||||
use Symfony\Component\PropertyInfo\Type;
|
use Symfony\Component\PropertyInfo\Type;
|
||||||
@ -44,6 +45,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
|
|||||||
$metadata = $this->classMetadataFactory->getMetadataFor($class);
|
$metadata = $this->classMetadataFactory->getMetadataFor($class);
|
||||||
} catch (MappingException $exception) {
|
} catch (MappingException $exception) {
|
||||||
return;
|
return;
|
||||||
|
} catch (OrmMappingException $exception) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
|
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
|
||||||
@ -58,6 +61,8 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
|
|||||||
$metadata = $this->classMetadataFactory->getMetadataFor($class);
|
$metadata = $this->classMetadataFactory->getMetadataFor($class);
|
||||||
} catch (MappingException $exception) {
|
} catch (MappingException $exception) {
|
||||||
return;
|
return;
|
||||||
|
} catch (OrmMappingException $exception) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($metadata->hasAssociation($property)) {
|
if ($metadata->hasAssociation($property)) {
|
||||||
|
@ -81,4 +81,14 @@ class DoctrineExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
array('notMapped', null),
|
array('notMapped', null),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetPropertiesCatchException()
|
||||||
|
{
|
||||||
|
$this->assertNull($this->extractor->getProperties('Not\Exist'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetTypesCatchException()
|
||||||
|
{
|
||||||
|
$this->assertNull($this->extractor->getTypes('Not\Exist', 'baz'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user