Merge branch '2.6' into 2.7
* 2.6: [EventDispatcher] make listeners removable from an executed listener [HttpFoundation] Fix volatile MongoDbSessionHandlerTest::testRead() Fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator) Conflicts: src/Symfony/Component/Validator/Constraints/FalseValidator.php src/Symfony/Component/Validator/Constraints/NullValidator.php src/Symfony/Component/Validator/Constraints/TrueValidator.php src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidator2Dot4ApiTest.php src/Symfony/Component/Validator/Tests/Constraints/LegacyFalseValidatorLegacyApiTest.php src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidator2Dot4ApiTest.php src/Symfony/Component/Validator/Tests/Constraints/LegacyNullValidatorLegacyApiTest.php src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidator2Dot4ApiTest.php src/Symfony/Component/Validator/Tests/Constraints/LegacyTrueValidatorLegacyApiTest.php
This commit is contained in:
commit
8622a7b22a
@ -158,6 +158,8 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
|
|
||||||
case 'Symfony\Component\Validator\Constraints\True':
|
case 'Symfony\Component\Validator\Constraints\True':
|
||||||
case 'Symfony\Component\Validator\Constraints\False':
|
case 'Symfony\Component\Validator\Constraints\False':
|
||||||
|
case 'Symfony\Component\Validator\Constraints\IsTrue':
|
||||||
|
case 'Symfony\Component\Validator\Constraints\IsFalse':
|
||||||
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
|
return new TypeGuess('checkbox', array(), Guess::MEDIUM_CONFIDENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,6 +177,7 @@ class ValidatorTypeGuesser implements FormTypeGuesserInterface
|
|||||||
case 'Symfony\Component\Validator\Constraints\NotNull':
|
case 'Symfony\Component\Validator\Constraints\NotNull':
|
||||||
case 'Symfony\Component\Validator\Constraints\NotBlank':
|
case 'Symfony\Component\Validator\Constraints\NotBlank':
|
||||||
case 'Symfony\Component\Validator\Constraints\True':
|
case 'Symfony\Component\Validator\Constraints\True':
|
||||||
|
case 'Symfony\Component\Validator\Constraints\IsTrue':
|
||||||
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
|
return new ValueGuess(true, Guess::HIGH_CONFIDENCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ use Symfony\Component\Validator\Constraints\Length;
|
|||||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\True;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Constraints\Type;
|
use Symfony\Component\Validator\Constraints\Type;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
|||||||
return array(
|
return array(
|
||||||
array(new NotNull(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
array(new NotNull(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||||
array(new NotBlank(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
array(new NotBlank(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||||
array(new True(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
array(new IsTrue(), new ValueGuess(true, Guess::HIGH_CONFIDENCE)),
|
||||||
array(new Length(10), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
array(new Length(10), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
||||||
array(new Range(array('min' => 1, 'max' => 20)), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
array(new Range(array('min' => 1, 'max' => 20)), new ValueGuess(false, Guess::LOW_CONFIDENCE)),
|
||||||
);
|
);
|
||||||
@ -84,6 +84,18 @@ class ValidatorTypeGuesserTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
$this->assertEquals($guess, $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
|
public function testLegacyGuessRequired()
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID >= 70000) {
|
||||||
|
$this->markTestSkipped('Cannot use a class called True on PHP 7 or higher.');
|
||||||
|
}
|
||||||
|
$true = 'Symfony\Component\Validator\Constraints\True';
|
||||||
|
$this->testGuessRequired(new $true(), new ValueGuess(true, Guess::HIGH_CONFIDENCE));
|
||||||
|
}
|
||||||
|
|
||||||
public function testGuessRequiredReturnsFalseForUnmappedProperties()
|
public function testGuessRequiredReturnsFalseForUnmappedProperties()
|
||||||
{
|
{
|
||||||
$this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
$this->assertEquals(new ValueGuess(false, Guess::LOW_CONFIDENCE), $this->guesser->guessRequired(self::TEST_CLASS, self::TEST_PROPERTY));
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/phpunit-bridge": "~2.7",
|
"symfony/phpunit-bridge": "~2.7",
|
||||||
"doctrine/collections": "~1.0",
|
"doctrine/collections": "~1.0",
|
||||||
"symfony/validator": "~2.6",
|
"symfony/validator": "~2.6,>=2.6.8",
|
||||||
"symfony/http-foundation": "~2.2",
|
"symfony/http-foundation": "~2.2",
|
||||||
"symfony/http-kernel": "~2.4",
|
"symfony/http-kernel": "~2.4",
|
||||||
"symfony/security-csrf": "~2.4",
|
"symfony/security-csrf": "~2.4",
|
||||||
|
@ -87,7 +87,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// defining the timeout before the actual method call
|
// defining the timeout before the actual method call
|
||||||
// allows to test for "greater than" values in the $criteria
|
// allows to test for "greater than" values in the $criteria
|
||||||
$testTimeout = time();
|
$testTimeout = time() + 1;
|
||||||
|
|
||||||
$collection->expects($this->once())
|
$collection->expects($this->once())
|
||||||
->method('findOne')
|
->method('findOne')
|
||||||
|
@ -93,6 +93,19 @@ class TraceableEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($called2);
|
$this->assertTrue($called2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testListenerCanRemoveItselfWhenExecuted()
|
||||||
|
{
|
||||||
|
$eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch());
|
||||||
|
$listener1 = function () use ($eventDispatcher, &$listener1) {
|
||||||
|
$eventDispatcher->removeListener('foo', $listener1);
|
||||||
|
};
|
||||||
|
$eventDispatcher->addListener('foo', $listener1);
|
||||||
|
$eventDispatcher->addListener('foo', function () {});
|
||||||
|
$eventDispatcher->dispatch('foo');
|
||||||
|
|
||||||
|
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
|
||||||
|
}
|
||||||
|
|
||||||
protected function getHttpKernel($dispatcher, $controller)
|
protected function getHttpKernel($dispatcher, $controller)
|
||||||
{
|
{
|
||||||
$resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
|
$resolver = $this->getMock('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface');
|
||||||
|
@ -87,6 +87,11 @@ CHANGELOG
|
|||||||
* added a constraint the uses the expression language
|
* added a constraint the uses the expression language
|
||||||
* added `minRatio`, `maxRatio`, `allowSquare`, `allowLandscape`, and `allowPortrait` to Image validator
|
* added `minRatio`, `maxRatio`, `allowSquare`, `allowLandscape`, and `allowPortrait` to Image validator
|
||||||
|
|
||||||
|
2.3.29
|
||||||
|
------
|
||||||
|
|
||||||
|
* fixed compatibility with PHP7 and up by introducing new constraints (IsNull, IsTrue, IsFalse) and related validators (IsNullValidator, IsTrueValidator, IsFalseValidator)
|
||||||
|
|
||||||
2.3.0
|
2.3.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
@ -21,7 +19,4 @@ use Symfony\Component\Validator\Constraint;
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class False extends Constraint
|
class False extends IsFalse {}
|
||||||
{
|
|
||||||
public $message = 'This value should be false.';
|
|
||||||
}
|
|
||||||
|
@ -11,39 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
|
||||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class FalseValidator extends ConstraintValidator
|
class FalseValidator extends IsFalseValidator {}
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function validate($value, Constraint $constraint)
|
|
||||||
{
|
|
||||||
if (!$constraint instanceof False) {
|
|
||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\False');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $value || false === $value || 0 === $value || '0' === $value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
|
||||||
$this->context->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
} else {
|
|
||||||
$this->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
27
src/Symfony/Component/Validator/Constraints/IsFalse.php
Normal file
27
src/Symfony/Component/Validator/Constraints/IsFalse.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsFalse extends Constraint
|
||||||
|
{
|
||||||
|
public $message = 'This value should be false.';
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsFalseValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validate($value, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof IsFalse) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsFalse');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $value || false === $value || 0 === $value || '0' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
|
$this->context->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
} else {
|
||||||
|
$this->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/Symfony/Component/Validator/Constraints/IsNull.php
Normal file
27
src/Symfony/Component/Validator/Constraints/IsNull.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsNull extends Constraint
|
||||||
|
{
|
||||||
|
public $message = 'This value should be null.';
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsNullValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validate($value, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof IsNull) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsNull');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $value) {
|
||||||
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
|
$this->context->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
} else {
|
||||||
|
$this->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
27
src/Symfony/Component/Validator/Constraints/IsTrue.php
Normal file
27
src/Symfony/Component/Validator/Constraints/IsTrue.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Annotation
|
||||||
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
|
*
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsTrue extends Constraint
|
||||||
|
{
|
||||||
|
public $message = 'This value should be true.';
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
use Symfony\Component\Validator\Constraint;
|
||||||
|
use Symfony\Component\Validator\ConstraintValidator;
|
||||||
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
class IsTrueValidator extends ConstraintValidator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function validate($value, Constraint $constraint)
|
||||||
|
{
|
||||||
|
if (!$constraint instanceof IsTrue) {
|
||||||
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\IsTrue');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true !== $value && 1 !== $value && '1' !== $value) {
|
||||||
|
if ($this->context instanceof ExecutionContextInterface) {
|
||||||
|
$this->context->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
} else {
|
||||||
|
$this->buildViolation($constraint->message)
|
||||||
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
@ -21,7 +19,4 @@ use Symfony\Component\Validator\Constraint;
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class Null extends Constraint
|
class Null extends IsNull {}
|
||||||
{
|
|
||||||
public $message = 'This value should be null.';
|
|
||||||
}
|
|
||||||
|
@ -11,37 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
|
||||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class NullValidator extends ConstraintValidator
|
class NullValidator extends IsNullValidator {}
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function validate($value, Constraint $constraint)
|
|
||||||
{
|
|
||||||
if (!$constraint instanceof Null) {
|
|
||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Null');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $value) {
|
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
|
||||||
$this->context->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
} else {
|
|
||||||
$this->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Annotation
|
* @Annotation
|
||||||
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
|
||||||
@ -21,7 +19,4 @@ use Symfony\Component\Validator\Constraint;
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class True extends Constraint
|
class True extends IsTrue {}
|
||||||
{
|
|
||||||
public $message = 'This value should be true.';
|
|
||||||
}
|
|
||||||
|
@ -11,41 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Constraints;
|
namespace Symfony\Component\Validator\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
|
||||||
use Symfony\Component\Validator\Constraint;
|
|
||||||
use Symfony\Component\Validator\ConstraintValidator;
|
|
||||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
class TrueValidator extends ConstraintValidator
|
class TrueValidator extends IsTrueValidator {}
|
||||||
{
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
public function validate($value, Constraint $constraint)
|
|
||||||
{
|
|
||||||
if (!$constraint instanceof True) {
|
|
||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\True');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $value) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (true !== $value && 1 !== $value && '1' !== $value) {
|
|
||||||
if ($this->context instanceof ExecutionContextInterface) {
|
|
||||||
$this->context->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
} else {
|
|
||||||
$this->buildViolation($constraint->message)
|
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
|
||||||
->addViolation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -81,7 +81,7 @@ class User
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Assert\True(message = "The user should have a Google Mail account")
|
* @Assert\IsTrue(message = "The user should have a Google Mail account")
|
||||||
*/
|
*/
|
||||||
public function isGmailUser()
|
public function isGmailUser()
|
||||||
{
|
{
|
||||||
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints\False;
|
use Symfony\Component\Validator\Constraints\IsFalse;
|
||||||
use Symfony\Component\Validator\Constraints\FalseValidator;
|
use Symfony\Component\Validator\Constraints\IsFalseValidator;
|
||||||
use Symfony\Component\Validator\Validation;
|
use Symfony\Component\Validator\Validation;
|
||||||
|
|
||||||
class FalseValidatorTest extends AbstractConstraintValidatorTest
|
class IsFalseValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected function getApiVersion()
|
protected function getApiVersion()
|
||||||
{
|
{
|
||||||
@ -24,26 +24,26 @@ class FalseValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
protected function createValidator()
|
protected function createValidator()
|
||||||
{
|
{
|
||||||
return new FalseValidator();
|
return new IsFalseValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(null, new False());
|
$this->validator->validate(null, new IsFalse());
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFalseIsValid()
|
public function testFalseIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(false, new False());
|
$this->validator->validate(false, new IsFalse());
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTrueIsInvalid()
|
public function testTrueIsInvalid()
|
||||||
{
|
{
|
||||||
$constraint = new False(array(
|
$constraint = new IsFalse(array(
|
||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
));
|
||||||
|
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints\Null;
|
use Symfony\Component\Validator\Constraints\IsNull;
|
||||||
use Symfony\Component\Validator\Constraints\NullValidator;
|
use Symfony\Component\Validator\Constraints\IsNullValidator;
|
||||||
use Symfony\Component\Validator\Validation;
|
use Symfony\Component\Validator\Validation;
|
||||||
|
|
||||||
class NullValidatorTest extends AbstractConstraintValidatorTest
|
class IsNullValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected function getApiVersion()
|
protected function getApiVersion()
|
||||||
{
|
{
|
||||||
@ -24,12 +24,12 @@ class NullValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
protected function createValidator()
|
protected function createValidator()
|
||||||
{
|
{
|
||||||
return new NullValidator();
|
return new IsNullValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(null, new Null());
|
$this->validator->validate(null, new IsNull());
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
@ -39,7 +39,7 @@ class NullValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
*/
|
*/
|
||||||
public function testInvalidValues($value, $valueAsString)
|
public function testInvalidValues($value, $valueAsString)
|
||||||
{
|
{
|
||||||
$constraint = new Null(array(
|
$constraint = new IsNull(array(
|
||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
));
|
||||||
|
|
@ -11,11 +11,11 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Validator\Tests\Constraints;
|
namespace Symfony\Component\Validator\Tests\Constraints;
|
||||||
|
|
||||||
use Symfony\Component\Validator\Constraints\True;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Constraints\TrueValidator;
|
use Symfony\Component\Validator\Constraints\IsTrueValidator;
|
||||||
use Symfony\Component\Validator\Validation;
|
use Symfony\Component\Validator\Validation;
|
||||||
|
|
||||||
class TrueValidatorTest extends AbstractConstraintValidatorTest
|
class IsTrueValidatorTest extends AbstractConstraintValidatorTest
|
||||||
{
|
{
|
||||||
protected function getApiVersion()
|
protected function getApiVersion()
|
||||||
{
|
{
|
||||||
@ -24,26 +24,26 @@ class TrueValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
|
|
||||||
protected function createValidator()
|
protected function createValidator()
|
||||||
{
|
{
|
||||||
return new TrueValidator();
|
return new IsTrueValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNullIsValid()
|
public function testNullIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(null, new True());
|
$this->validator->validate(null, new IsTrue());
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTrueIsValid()
|
public function testTrueIsValid()
|
||||||
{
|
{
|
||||||
$this->validator->validate(true, new True());
|
$this->validator->validate(true, new IsTrue());
|
||||||
|
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFalseIsInvalid()
|
public function testFalseIsInvalid()
|
||||||
{
|
{
|
||||||
$constraint = new True(array(
|
$constraint = new IsTrue(array(
|
||||||
'message' => 'myMessage',
|
'message' => 'myMessage',
|
||||||
));
|
));
|
||||||
|
|
@ -64,7 +64,7 @@ class Entity extends EntityParent implements EntityInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Assert\True
|
* @Assert\IsTrue
|
||||||
*/
|
*/
|
||||||
public function isValid()
|
public function isValid()
|
||||||
{
|
{
|
||||||
@ -72,7 +72,7 @@ class Entity extends EntityParent implements EntityInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Assert\True
|
* @Assert\IsTrue
|
||||||
*/
|
*/
|
||||||
public function hasPermissions()
|
public function hasPermissions()
|
||||||
{
|
{
|
||||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Validator\Constraints\Choice;
|
|||||||
use Symfony\Component\Validator\Constraints\Collection;
|
use Symfony\Component\Validator\Constraints\Collection;
|
||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\True;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
|
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||||
@ -68,8 +68,8 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
'choices' => array('A', 'B'),
|
'choices' => array('A', 'B'),
|
||||||
)));
|
)));
|
||||||
$expected->addGetterConstraint('lastName', new NotNull());
|
$expected->addGetterConstraint('lastName', new NotNull());
|
||||||
$expected->addGetterConstraint('valid', new True());
|
$expected->addGetterConstraint('valid', new IsTrue());
|
||||||
$expected->addGetterConstraint('permissions', new True());
|
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||||
|
|
||||||
// load reflection class so that the comparison passes
|
// load reflection class so that the comparison passes
|
||||||
$expected->getReflectionClass();
|
$expected->getReflectionClass();
|
||||||
@ -137,8 +137,8 @@ class AnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
'choices' => array('A', 'B'),
|
'choices' => array('A', 'B'),
|
||||||
)));
|
)));
|
||||||
$expected->addGetterConstraint('lastName', new NotNull());
|
$expected->addGetterConstraint('lastName', new NotNull());
|
||||||
$expected->addGetterConstraint('valid', new True());
|
$expected->addGetterConstraint('valid', new IsTrue());
|
||||||
$expected->addGetterConstraint('permissions', new True());
|
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||||
|
|
||||||
// load reflection class so that the comparison passes
|
// load reflection class so that the comparison passes
|
||||||
$expected->getReflectionClass();
|
$expected->getReflectionClass();
|
||||||
|
@ -18,7 +18,7 @@ use Symfony\Component\Validator\Constraints\Collection;
|
|||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\Regex;
|
use Symfony\Component\Validator\Constraints\Regex;
|
||||||
use Symfony\Component\Validator\Constraints\True;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Exception\MappingException;
|
use Symfony\Component\Validator\Exception\MappingException;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
||||||
@ -71,8 +71,8 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
'choices' => array('A', 'B'),
|
'choices' => array('A', 'B'),
|
||||||
)));
|
)));
|
||||||
$expected->addGetterConstraint('lastName', new NotNull());
|
$expected->addGetterConstraint('lastName', new NotNull());
|
||||||
$expected->addGetterConstraint('valid', new True());
|
$expected->addGetterConstraint('valid', new IsTrue());
|
||||||
$expected->addGetterConstraint('permissions', new True());
|
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||||
|
|
||||||
$this->assertEquals($expected, $metadata);
|
$this->assertEquals($expected, $metadata);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ use Symfony\Component\Validator\Constraints\Choice;
|
|||||||
use Symfony\Component\Validator\Constraints\Collection;
|
use Symfony\Component\Validator\Constraints\Collection;
|
||||||
use Symfony\Component\Validator\Constraints\NotNull;
|
use Symfony\Component\Validator\Constraints\NotNull;
|
||||||
use Symfony\Component\Validator\Constraints\Range;
|
use Symfony\Component\Validator\Constraints\Range;
|
||||||
use Symfony\Component\Validator\Constraints\True;
|
use Symfony\Component\Validator\Constraints\IsTrue;
|
||||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||||
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
||||||
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
use Symfony\Component\Validator\Tests\Fixtures\ConstraintA;
|
||||||
@ -102,8 +102,8 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
'choices' => array('A', 'B'),
|
'choices' => array('A', 'B'),
|
||||||
)));
|
)));
|
||||||
$expected->addGetterConstraint('lastName', new NotNull());
|
$expected->addGetterConstraint('lastName', new NotNull());
|
||||||
$expected->addGetterConstraint('valid', new True());
|
$expected->addGetterConstraint('valid', new IsTrue());
|
||||||
$expected->addGetterConstraint('permissions', new True());
|
$expected->addGetterConstraint('permissions', new IsTrue());
|
||||||
|
|
||||||
$this->assertEquals($expected, $metadata);
|
$this->assertEquals($expected, $metadata);
|
||||||
}
|
}
|
||||||
|
@ -103,10 +103,10 @@
|
|||||||
<constraint name="NotNull" />
|
<constraint name="NotNull" />
|
||||||
</getter>
|
</getter>
|
||||||
<getter property="valid">
|
<getter property="valid">
|
||||||
<constraint name="True" />
|
<constraint name="IsTrue" />
|
||||||
</getter>
|
</getter>
|
||||||
<getter property="permissions">
|
<getter property="permissions">
|
||||||
<constraint name="True" />
|
<constraint name="IsTrue" />
|
||||||
</getter>
|
</getter>
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ Symfony\Component\Validator\Tests\Fixtures\Entity:
|
|||||||
lastName:
|
lastName:
|
||||||
- NotNull: ~
|
- NotNull: ~
|
||||||
valid:
|
valid:
|
||||||
- "True": ~
|
- "IsTrue": ~
|
||||||
permissions:
|
permissions:
|
||||||
- "True": ~
|
- "IsTrue": ~
|
||||||
|
|
||||||
Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity:
|
Symfony\Component\Validator\Tests\Fixtures\GroupSequenceProviderEntity:
|
||||||
group_sequence_provider: true
|
group_sequence_provider: true
|
||||||
|
Reference in New Issue
Block a user