You are here

class LegacyValidator in Plug 7

A validator that supports both the API of Symfony < 2.5 and Symfony 2.5+.

This class is incompatible with PHP versions < 5.3.9, because it implements two different interfaces specifying the same method validate():

  • {@link \Symfony\Component\Validator\ValidatorInterface}
  • {@link \Symfony\Component\Validator\Validator\ValidatorInterface}

In PHP versions prior to 5.3.9, either use {@link RecursiveValidator} or the deprecated class {@link \Symfony\Component\Validator\Validator} instead.

@since 2.5 @author Bernhard Schussek <bschussek@gmail.com>

Hierarchy

Expanded class hierarchy of LegacyValidator

Deprecated

Implemented for backwards compatibility with Symfony < 2.5. To be removed in Symfony 3.0.

See also

\Symfony\Component\Validator\ValidatorInterface

\Symfony\Component\Validator\Validator\ValidatorInterface

3 files declare their use of LegacyValidator
LegacyValidator2Dot5ApiTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/LegacyValidator2Dot5ApiTest.php
LegacyValidatorLegacyApiTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Validator/LegacyValidatorLegacyApiTest.php
ValidatorBuilder.php in lib/Symfony/validator/Symfony/Component/Validator/ValidatorBuilder.php

File

lib/Symfony/validator/Symfony/Component/Validator/Validator/LegacyValidator.php, line 40

Namespace

Symfony\Component\Validator\Validator
View source
class LegacyValidator extends RecursiveValidator implements LegacyValidatorInterface {
  public function validate($value, $groups = null, $traverse = false, $deep = false) {
    $numArgs = func_num_args();

    // Use new signature if constraints are given in the second argument
    if (self::testConstraints($groups) && ($numArgs < 3 || 3 === $numArgs && self::testGroups($traverse))) {

      // Rename to avoid total confusion ;)
      $constraints = $groups;
      $groups = $traverse;
      return parent::validate($value, $constraints, $groups);
    }
    $constraint = new Valid(array(
      'traverse' => $traverse,
      'deep' => $deep,
    ));
    return parent::validate($value, $constraint, $groups);
  }
  public function validateValue($value, $constraints, $groups = null) {
    return parent::validate($value, $constraints, $groups);
  }
  public function getMetadataFactory() {
    return $this->metadataFactory;
  }
  private static function testConstraints($constraints) {
    return null === $constraints || $constraints instanceof Constraint || is_array($constraints) && current($constraints) instanceof Constraint;
  }
  private static function testGroups($groups) {
    return null === $groups || is_string($groups) || $groups instanceof GroupSequence || is_array($groups) && (is_string(current($groups)) || current($groups) instanceof GroupSequence);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LegacyValidator::getMetadataFactory public function Returns the factory for metadata instances. Overrides ValidatorInterface::getMetadataFactory
LegacyValidator::testConstraints private static function
LegacyValidator::testGroups private static function
LegacyValidator::validate public function Validates a value against a constraint or a list of constraints. Overrides RecursiveValidator::validate
LegacyValidator::validateValue public function Validates a value against a constraint or a list of constraints. Overrides ValidatorInterface::validateValue
RecursiveValidator::$contextFactory protected property
RecursiveValidator::$metadataFactory protected property
RecursiveValidator::$objectInitializers protected property
RecursiveValidator::$validatorFactory protected property
RecursiveValidator::getMetadataFor public function Returns the metadata for the given value. Overrides MetadataFactoryInterface::getMetadataFor
RecursiveValidator::hasMetadataFor public function Returns whether the class is able to return metadata for the given value. Overrides MetadataFactoryInterface::hasMetadataFor
RecursiveValidator::inContext public function Returns a validator in the given execution context. Overrides ValidatorInterface::inContext
RecursiveValidator::startContext public function Starts a new validation context and returns a validator for that context. Overrides ValidatorInterface::startContext
RecursiveValidator::validateProperty public function Validates a property of an object against the constraints specified for this property. Overrides ValidatorInterface::validateProperty
RecursiveValidator::validatePropertyValue public function Validates a value against the constraints specified for an object's property. Overrides ValidatorInterface::validatePropertyValue
RecursiveValidator::__construct public function Creates a new validator.