You are here

class LegacyExecutionContext in Plug 7

An execution context that is compatible with the legacy API (< 2.5).

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

Hierarchy

Expanded class hierarchy of LegacyExecutionContext

Deprecated

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

1 file declares its use of LegacyExecutionContext
AbstractConstraintValidatorTest.php in lib/Symfony/validator/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php

File

lib/Symfony/validator/Symfony/Component/Validator/Context/LegacyExecutionContext.php, line 28

Namespace

Symfony\Component\Validator\Context
View source
class LegacyExecutionContext extends ExecutionContext {

  /**
   * @var MetadataFactoryInterface
   */
  private $metadataFactory;

  /**
   * Creates a new context.
   *
   * @see ExecutionContext::__construct()
   *
   * @internal Called by {@link LegacyExecutionContextFactory}. Should not be used
   *           in user code.
   */
  public function __construct(ValidatorInterface $validator, $root, MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null) {
    parent::__construct($validator, $root, $translator, $translationDomain);
    $this->metadataFactory = $metadataFactory;
  }

  /**
   * {@inheritdoc}
   */
  public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) {
    if (func_num_args() > 2) {
      $this
        ->buildViolation($message, $parameters)
        ->setInvalidValue($invalidValue)
        ->setPlural($plural)
        ->setCode($code)
        ->addViolation();
      return;
    }
    parent::addViolation($message, $parameters);
  }

  /**
   * {@inheritdoc}
   */
  public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null) {
    if (func_num_args() > 2) {
      $this
        ->buildViolation($message, $parameters)
        ->atPath($subPath)
        ->setInvalidValue($invalidValue)
        ->setPlural($plural)
        ->setCode($code)
        ->addViolation();
      return;
    }
    $this
      ->buildViolation($message, $parameters)
      ->atPath($subPath)
      ->addViolation();
  }

  /**
   * {@inheritdoc}
   */
  public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false) {
    if (is_array($value)) {

      // The $traverse flag is ignored for arrays
      $constraint = new Valid(array(
        'traverse' => true,
        'deep' => $deep,
      ));
      return $this
        ->getValidator()
        ->inContext($this)
        ->atPath($subPath)
        ->validate($value, $constraint, $groups);
    }
    if ($traverse && $value instanceof \Traversable) {
      $constraint = new Valid(array(
        'traverse' => true,
        'deep' => $deep,
      ));
      return $this
        ->getValidator()
        ->inContext($this)
        ->atPath($subPath)
        ->validate($value, $constraint, $groups);
    }
    return $this
      ->getValidator()
      ->inContext($this)
      ->atPath($subPath)
      ->validate($value, null, $groups);
  }

  /**
   * {@inheritdoc}
   */
  public function validateValue($value, $constraints, $subPath = '', $groups = null) {
    return $this
      ->getValidator()
      ->inContext($this)
      ->atPath($subPath)
      ->validate($value, $constraints, $groups);
  }

  /**
   * {@inheritdoc}
   */
  public function getMetadataFactory() {
    return $this->metadataFactory;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExecutionContext::$constraint private property The currently validated constraint.
ExecutionContext::$group private property The currently validated group.
ExecutionContext::$initializedObjects private property Stores which objects have been initialized.
ExecutionContext::$metadata private property The current validation metadata.
ExecutionContext::$object private property The currently validated object.
ExecutionContext::$propertyPath private property The property path leading to the current value.
ExecutionContext::$root private property The root value of the validated object graph.
ExecutionContext::$translationDomain private property
ExecutionContext::$translator private property
ExecutionContext::$validatedConstraints private property Stores which class constraint has been validated for which object.
ExecutionContext::$validatedObjects private property Stores which objects have been validated in which group.
ExecutionContext::$validator private property
ExecutionContext::$value private property The currently validated value.
ExecutionContext::$violations private property The violations generated in the current context.
ExecutionContext::buildViolation public function Returns a builder for adding a violation with extended information. Overrides ExecutionContextInterface::buildViolation
ExecutionContext::getClassName public function Returns the class name of the current node. Overrides ExecutionContextInterface::getClassName
ExecutionContext::getGroup public function Returns the validation group that is currently being validated. Overrides ExecutionContextInterface::getGroup
ExecutionContext::getMetadata public function Returns the metadata for the currently validated value. Overrides ExecutionContextInterface::getMetadata
ExecutionContext::getObject public function Returns the currently validated object. Overrides ExecutionContextInterface::getObject
ExecutionContext::getPropertyName public function Returns the property name of the current node. Overrides ExecutionContextInterface::getPropertyName
ExecutionContext::getPropertyPath public function Returns the property path to the value that the validator is currently validating. Overrides ExecutionContextInterface::getPropertyPath
ExecutionContext::getRoot public function Returns the value at which validation was started in the object graph. Overrides ExecutionContextInterface::getRoot
ExecutionContext::getValidator public function Returns the validator. Overrides ExecutionContextInterface::getValidator
ExecutionContext::getValue public function Returns the value that the validator is currently validating. Overrides ExecutionContextInterface::getValue
ExecutionContext::getViolations public function Returns the violations generated by the validator so far. Overrides ExecutionContextInterface::getViolations
ExecutionContext::isConstraintValidated public function Returns whether a constraint was validated for an object. Overrides ExecutionContextInterface::isConstraintValidated
ExecutionContext::isGroupValidated public function Returns whether an object was validated in a specific validation group. Overrides ExecutionContextInterface::isGroupValidated
ExecutionContext::isObjectInitialized public function Returns whether an object was initialized. Overrides ExecutionContextInterface::isObjectInitialized
ExecutionContext::markConstraintAsValidated public function Marks a constraint as validated for an object. Overrides ExecutionContextInterface::markConstraintAsValidated
ExecutionContext::markGroupAsValidated public function Marks an object as validated in a specific validation group. Overrides ExecutionContextInterface::markGroupAsValidated
ExecutionContext::markObjectAsInitialized public function Marks that an object was initialized. Overrides ExecutionContextInterface::markObjectAsInitialized
ExecutionContext::setConstraint public function Sets the currently validated constraint. Overrides ExecutionContextInterface::setConstraint
ExecutionContext::setGroup public function Sets the currently validated group. Overrides ExecutionContextInterface::setGroup
ExecutionContext::setNode public function Sets the currently validated value. Overrides ExecutionContextInterface::setNode
LegacyExecutionContext::$metadataFactory private property
LegacyExecutionContext::addViolation public function Adds a violation at the current node of the validation graph. Overrides ExecutionContext::addViolation
LegacyExecutionContext::addViolationAt public function Adds a violation at the validation graph node with the given property path relative to the current property path. Overrides ExecutionContext::addViolationAt
LegacyExecutionContext::getMetadataFactory public function Returns the used metadata factory. Overrides ExecutionContext::getMetadataFactory
LegacyExecutionContext::validate public function Validates the given value within the scope of the current validation. Overrides ExecutionContext::validate
LegacyExecutionContext::validateValue public function Validates a value against a constraint. Overrides ExecutionContext::validateValue
LegacyExecutionContext::__construct public function Creates a new context. Overrides ExecutionContext::__construct