[Validator] catch deprecated methods
This commit is contained in:
parent
92ecff816b
commit
07316c9aa0
@ -70,16 +70,20 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface, MetadataFac
|
||||
|
||||
// Include constraints from the parent class
|
||||
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
|
||||
set_error_handler(array($this, 'handleBC'));
|
||||
$metadata->mergeConstraints($this->getClassMetadata($parent->name));
|
||||
restore_error_handler();
|
||||
}
|
||||
|
||||
// Include constraints from all implemented interfaces
|
||||
set_error_handler(array($this, 'handleBC'));
|
||||
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
|
||||
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
|
||||
continue;
|
||||
}
|
||||
$metadata->mergeConstraints($this->getClassMetadata($interface->name));
|
||||
}
|
||||
restore_error_handler();
|
||||
|
||||
if (null !== $this->loader) {
|
||||
$this->loader->loadClassMetadata($metadata);
|
||||
@ -122,4 +126,16 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface, MetadataFac
|
||||
|
||||
return $this->getMetadataFor($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This is used to keep BC until deprecated methods are removed
|
||||
*/
|
||||
public function handleBC($errorNumber, $message, $file, $line, $context)
|
||||
{
|
||||
if ($errorNumber & E_USER_DEPRECATED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,9 @@ class ClassMetadataFactoryAdapter implements MetadataFactoryInterface
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
$class = is_object($value) ? get_class($value) : $value;
|
||||
set_error_handler(array($this, 'handleBC'));
|
||||
$metadata = $this->innerFactory->getClassMetadata($class);
|
||||
restore_error_handler();
|
||||
|
||||
if (null === $metadata) {
|
||||
throw new NoSuchMetadataException('No metadata exists for class '. $class);
|
||||
@ -54,6 +56,22 @@ class ClassMetadataFactoryAdapter implements MetadataFactoryInterface
|
||||
{
|
||||
$class = is_object($value) ? get_class($value) : $value;
|
||||
|
||||
return null !== $this->innerFactory->getClassMetadata($class);
|
||||
set_error_handler(array($this, 'handleBC'));
|
||||
$return = null !== $this->innerFactory->getClassMetadata($class);
|
||||
restore_error_handler();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated This is used to keep BC until deprecated methods are removed
|
||||
*/
|
||||
public function handleBC($errorNumber, $message, $file, $line, $context)
|
||||
{
|
||||
if ($errorNumber & E_USER_DEPRECATED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -22,10 +22,21 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
const CLASSNAME = 'Symfony\Component\Validator\Tests\Fixtures\Entity';
|
||||
const PARENTCLASS = 'Symfony\Component\Validator\Tests\Fixtures\EntityParent';
|
||||
|
||||
public function handle($errorNumber, $message, $file, $line, $context)
|
||||
{
|
||||
if ($errorNumber & E_USER_DEPRECATED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
|
||||
}
|
||||
|
||||
public function testLoadClassMetadata()
|
||||
{
|
||||
$factory = new ClassMetadataFactory(new TestLoader());
|
||||
set_error_handler(array($this, 'handle'));
|
||||
$metadata = $factory->getClassMetadata(self::PARENTCLASS);
|
||||
restore_error_handler();
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array('Default', 'EntityParent'))),
|
||||
@ -37,7 +48,9 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
public function testMergeParentConstraints()
|
||||
{
|
||||
$factory = new ClassMetadataFactory(new TestLoader());
|
||||
set_error_handler(array($this, 'handle'));
|
||||
$metadata = $factory->getClassMetadata(self::CLASSNAME);
|
||||
restore_error_handler();
|
||||
|
||||
$constraints = array(
|
||||
new ConstraintA(array('groups' => array(
|
||||
@ -81,7 +94,9 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$tester->assertEquals($constraints, $metadata->getConstraints());
|
||||
}));
|
||||
|
||||
set_error_handler(array($this, 'handle'));
|
||||
$metadata = $factory->getClassMetadata(self::PARENTCLASS);
|
||||
restore_error_handler();
|
||||
|
||||
$this->assertEquals(self::PARENTCLASS, $metadata->getClassName());
|
||||
$this->assertEquals($constraints, $metadata->getConstraints());
|
||||
@ -106,7 +121,9 @@ class ClassMetadataFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
->method('read')
|
||||
->will($this->returnValue($metadata));
|
||||
|
||||
set_error_handler(array($this, 'handle'));
|
||||
$this->assertEquals($metadata,$factory->getClassMetadata(self::PARENTCLASS));
|
||||
restore_error_handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user