Merge branch '3.4' into 4.4
* 3.4: [ErrorHandler] fix throwing from __toString() Removed comments and requirements relative to php <5.5 (not supported anymore) fix validating lazy properties that evaluate to null
This commit is contained in:
commit
450034c986
@ -433,8 +433,6 @@ class Command
|
|||||||
* This feature should be used only when creating a long process command,
|
* This feature should be used only when creating a long process command,
|
||||||
* like a daemon.
|
* like a daemon.
|
||||||
*
|
*
|
||||||
* PHP 5.5+ or the proctitle PECL library is required
|
|
||||||
*
|
|
||||||
* @param string $title The process title
|
* @param string $title The process title
|
||||||
*
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
|
@ -403,18 +403,6 @@ class ErrorHandler
|
|||||||
}
|
}
|
||||||
$scope = $this->scopedErrors & $type;
|
$scope = $this->scopedErrors & $type;
|
||||||
|
|
||||||
if (4 < $numArgs = \func_num_args()) {
|
|
||||||
$context = $scope ? (func_get_arg(4) ?: []) : [];
|
|
||||||
} else {
|
|
||||||
$context = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($context['GLOBALS']) && $scope) {
|
|
||||||
$e = $context; // Whatever the signature of the method,
|
|
||||||
unset($e['GLOBALS'], $context); // $context is always a reference in 5.3
|
|
||||||
$context = $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false !== strpos($message, "@anonymous\0")) {
|
if (false !== strpos($message, "@anonymous\0")) {
|
||||||
$logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage();
|
$logMessage = $this->levels[$type].': '.(new FlattenException())->setMessage($message)->getMessage();
|
||||||
} else {
|
} else {
|
||||||
@ -476,6 +464,8 @@ class ErrorHandler
|
|||||||
// `return trigger_error($e, E_USER_ERROR);` allows this error handler
|
// `return trigger_error($e, E_USER_ERROR);` allows this error handler
|
||||||
// to make $e get through the __toString() barrier.
|
// to make $e get through the __toString() barrier.
|
||||||
|
|
||||||
|
$context = 4 < \func_num_args() ? (func_get_arg(4) ?: []) : [];
|
||||||
|
|
||||||
foreach ($context as $e) {
|
foreach ($context as $e) {
|
||||||
if ($e instanceof \Throwable && $e->__toString() === $message) {
|
if ($e instanceof \Throwable && $e->__toString() === $message) {
|
||||||
self::$toStringException = $e;
|
self::$toStringException = $e;
|
||||||
|
@ -423,18 +423,6 @@ class ErrorHandler
|
|||||||
}
|
}
|
||||||
$scope = $this->scopedErrors & $type;
|
$scope = $this->scopedErrors & $type;
|
||||||
|
|
||||||
if (4 < $numArgs = \func_num_args()) {
|
|
||||||
$context = $scope ? (func_get_arg(4) ?: []) : [];
|
|
||||||
} else {
|
|
||||||
$context = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($context['GLOBALS']) && $scope) {
|
|
||||||
$e = $context; // Whatever the signature of the method,
|
|
||||||
unset($e['GLOBALS'], $context); // $context is always a reference in 5.3
|
|
||||||
$context = $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (false !== strpos($message, "@anonymous\0")) {
|
if (false !== strpos($message, "@anonymous\0")) {
|
||||||
$logMessage = $this->parseAnonymousClass($message);
|
$logMessage = $this->parseAnonymousClass($message);
|
||||||
} else {
|
} else {
|
||||||
@ -496,6 +484,8 @@ class ErrorHandler
|
|||||||
// `return trigger_error($e, E_USER_ERROR);` allows this error handler
|
// `return trigger_error($e, E_USER_ERROR);` allows this error handler
|
||||||
// to make $e get through the __toString() barrier.
|
// to make $e get through the __toString() barrier.
|
||||||
|
|
||||||
|
$context = 4 < \func_num_args() ? (func_get_arg(4) ?: []) : [];
|
||||||
|
|
||||||
foreach ($context as $e) {
|
foreach ($context as $e) {
|
||||||
if ($e instanceof \Throwable && $e->__toString() === $message) {
|
if ($e instanceof \Throwable && $e->__toString() === $message) {
|
||||||
self::$toStringException = $e;
|
self::$toStringException = $e;
|
||||||
|
@ -18,6 +18,7 @@ class EntityParent implements EntityInterfaceA
|
|||||||
protected $firstName;
|
protected $firstName;
|
||||||
private $internal;
|
private $internal;
|
||||||
private $data = 'Data';
|
private $data = 'Data';
|
||||||
|
private $child;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NotNull
|
* @NotNull
|
||||||
@ -28,4 +29,9 @@ class EntityParent implements EntityInterfaceA
|
|||||||
{
|
{
|
||||||
return 'Data';
|
return 'Data';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getChild()
|
||||||
|
{
|
||||||
|
return $this->child;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ use Symfony\Component\Validator\Constraints\NotBlank;
|
|||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Optional;
|
use Symfony\Component\Validator\Constraints\Optional;
|
||||||
use Symfony\Component\Validator\Constraints\Required;
|
use Symfony\Component\Validator\Constraints\Required;
|
||||||
|
use Symfony\Component\Validator\Constraints\Valid;
|
||||||
use Symfony\Component\Validator\ConstraintValidatorFactory;
|
use Symfony\Component\Validator\ConstraintValidatorFactory;
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
@ -28,6 +29,7 @@ use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
|
|||||||
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
|
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
|
||||||
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
|
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
||||||
|
use Symfony\Component\Validator\Tests\Fixtures\EntityParent;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods;
|
use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods;
|
||||||
use Symfony\Component\Validator\Validator\RecursiveValidator;
|
use Symfony\Component\Validator\Validator\RecursiveValidator;
|
||||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||||
@ -144,6 +146,31 @@ class RecursiveValidatorTest extends AbstractTest
|
|||||||
$this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint());
|
$this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidConstraintOnGetterReturningNull()
|
||||||
|
{
|
||||||
|
$metadata = new ClassMetadata(EntityParent::class);
|
||||||
|
$metadata->addGetterConstraint('child', new Valid());
|
||||||
|
|
||||||
|
$this->metadataFactory->addMetadata($metadata);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate(new EntityParent());
|
||||||
|
|
||||||
|
$this->assertCount(0, $violations);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNotNullConstraintOnGetterReturningNull()
|
||||||
|
{
|
||||||
|
$metadata = new ClassMetadata(EntityParent::class);
|
||||||
|
$metadata->addGetterConstraint('child', new NotNull());
|
||||||
|
|
||||||
|
$this->metadataFactory->addMetadata($metadata);
|
||||||
|
|
||||||
|
$violations = $this->validator->validate(new EntityParent());
|
||||||
|
|
||||||
|
$this->assertCount(1, $violations);
|
||||||
|
$this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint());
|
||||||
|
}
|
||||||
|
|
||||||
public function testAllConstraintValidateAllGroupsForNestedConstraints()
|
public function testAllConstraintValidateAllGroupsForNestedConstraints()
|
||||||
{
|
{
|
||||||
$this->metadata->addPropertyConstraint('data', new All(['constraints' => [
|
$this->metadata->addPropertyConstraint('data', new All(['constraints' => [
|
||||||
|
@ -637,6 +637,10 @@ class RecursiveContextualValidator implements ContextualValidatorInterface
|
|||||||
|
|
||||||
if ($value instanceof LazyProperty) {
|
if ($value instanceof LazyProperty) {
|
||||||
$value = $value->getPropertyValue();
|
$value = $value->getPropertyValue();
|
||||||
|
|
||||||
|
if (null === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (\is_array($value)) {
|
if (\is_array($value)) {
|
||||||
|
Reference in New Issue
Block a user