[Validator] removed deprecated methods

This commit is contained in:
Fabien Potencier 2015-09-30 15:39:58 +02:00
parent 925ecafba8
commit 2a6b629e39
52 changed files with 230 additions and 2896 deletions

View File

@ -1,30 +0,0 @@
<?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;
/**
* An object backed by a PHP class.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\ClassMetadataInterface} instead.
*/
interface ClassBasedInterface
{
/**
* Returns the name of the backing PHP class.
*
* @return string The name of the backing class.
*/
public function getClassName();
}

View File

@ -11,9 +11,7 @@
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Context\ExecutionContextInterface as ExecutionContextInterface2Dot5;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
use Symfony\Component\Validator\Violation\LegacyConstraintViolationBuilder;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Base class for constraint validators.
@ -50,51 +48,6 @@ abstract class ConstraintValidator implements ConstraintValidatorInterface
$this->context = $context;
}
/**
* Wrapper for {@link ExecutionContextInterface::buildViolation} that
* supports the 2.4 context API.
*
* @param string $message The violation message
* @param array $parameters The message parameters
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolation($message, array $parameters = array())
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
if ($this->context instanceof ExecutionContextInterface2Dot5) {
return $this->context->buildViolation($message, $parameters);
}
return new LegacyConstraintViolationBuilder($this->context, $message, $parameters);
}
/**
* Wrapper for {@link ExecutionContextInterface::buildViolation} that
* supports the 2.4 context API.
*
* @param ExecutionContextInterface $context The context to use
* @param string $message The violation message
* @param array $parameters The message parameters
*
* @return ConstraintViolationBuilderInterface The violation builder
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
protected function buildViolationInContext(ExecutionContextInterface $context, $message, array $parameters = array())
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
if ($context instanceof ExecutionContextInterface2Dot5) {
return $context->buildViolation($message, $parameters);
}
return new LegacyConstraintViolationBuilder($context, $message, $parameters);
}
/**
* Returns a string representation of the type of the value.
*

View File

@ -11,6 +11,8 @@
namespace Symfony\Component\Validator;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/

View File

@ -141,19 +141,6 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use getParameters() instead
*/
public function getMessageParameters()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getParameters() method instead.', E_USER_DEPRECATED);
return $this->parameters;
}
/**
* Alias of {@link getMessageParameters()}.
*/
public function getParameters()
{
@ -162,19 +149,6 @@ class ConstraintViolation implements ConstraintViolationInterface
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
* Use getPlural() instead
*/
public function getMessagePluralization()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.7, to be removed in 3.0. Use the ConstraintViolation::getPlural() method instead.', E_USER_DEPRECATED);
return $this->plural;
}
/**
* Alias of {@link getMessagePluralization()}.
*/
public function getPlural()
{

View File

@ -46,7 +46,7 @@ interface ConstraintViolationInterface
* Returns the raw violation message.
*
* The raw violation message contains placeholders for the parameters
* returned by {@link getMessageParameters}. Typically you'll pass the
* returned by {@link getParameters}. Typically you'll pass the
* message template and parameters to a translation engine.
*
* @return string The raw violation message.
@ -60,10 +60,8 @@ interface ConstraintViolationInterface
* that appear in the message template.
*
* @see getMessageTemplate()
*
* @deprecated since version 2.7, to be replaced by getParameters() in 3.0.
*/
public function getMessageParameters();
public function getParameters();
/**
* Returns a number for pluralizing the violation message.
@ -80,10 +78,8 @@ interface ConstraintViolationInterface
* pluralization form (in this case "choices").
*
* @return int|null The number to use to pluralize of the message.
*
* @deprecated since version 2.7, to be replaced by getPlural() in 3.0.
*/
public function getMessagePluralization();
public function getPlural();
/**
* Returns the root element of the validation.

View File

@ -11,8 +11,6 @@
namespace Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\Exception\OutOfBoundsException;
/**
* A sequence of validation groups.
*

View File

@ -24,11 +24,6 @@ class Valid extends Constraint
{
public $traverse = true;
/**
* @deprecated since version 2.5, to be removed in Symfony 3.0.
*/
public $deep = true;
public function __construct($options = null)
{
if (is_array($options) && array_key_exists('groups', $options)) {
@ -38,10 +33,6 @@ class Valid extends Constraint
));
}
if (is_array($options) && array_key_exists('deep', $options)) {
@trigger_error('The "deep" option for the Valid constraint is deprecated since version 2.5 and will be removed in 3.0. When traversing arrays, nested arrays are always traversed. When traversing nested objects, their traversal strategy is used.', E_USER_DEPRECATED);
}
parent::__construct($options);
}
}

View File

@ -12,16 +12,15 @@
namespace Symfony\Component\Validator\Context;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\ClassBasedInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\MemberMetadata;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Util\PropertyPath;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilder;
/**
@ -183,25 +182,8 @@ class ExecutionContext implements ExecutionContextInterface
/**
* {@inheritdoc}
*/
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
public function addViolation($message, array $parameters = array())
{
// The parameters $invalidValue and following are ignored by the new
// API, as they are not present in the new interface anymore.
// You should use buildViolation() instead.
if (func_num_args() > 2) {
@trigger_error('The parameters $invalidValue, $plural and $code in method '.__METHOD__.' are deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);
$this
->buildViolation($message, $parameters)
->setInvalidValue($invalidValue)
->setPlural($plural)
->setCode($code)
->addViolation()
;
return;
}
$this->violations->add(new ConstraintViolation(
$this->translator->trans($message, $parameters, $this->translationDomain),
$message,
@ -294,7 +276,7 @@ class ExecutionContext implements ExecutionContextInterface
*/
public function getClassName()
{
return $this->metadata instanceof ClassBasedInterface ? $this->metadata->getClassName() : null;
return $this->metadata instanceof MemberMetadata || $this->metadata instanceof ClassMetadataInterface ? $this->metadata->getClassName() : null;
}
/**
@ -313,103 +295,6 @@ class ExecutionContext implements ExecutionContextInterface
return PropertyPath::append($this->propertyPath, $subPath);
}
/**
* {@inheritdoc}
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::buildViolation method instead.', E_USER_DEPRECATED);
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)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator() method instead.', E_USER_DEPRECATED);
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)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the '.__CLASS__.'::getValidator() method instead.', E_USER_DEPRECATED);
return $this
->getValidator()
->inContext($this)
->atPath($subPath)
->validate($value, $constraints, $groups)
;
}
/**
* {@inheritdoc}
*/
public function getMetadataFactory()
{
@trigger_error('The '.__METHOD__.' is deprecated since version 2.5 and will be removed in 3.0. Use the new Symfony\Component\Validator\Context\ExecutionContext::getValidator method in combination with Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFor or Symfony\Component\Validator\Validator\ValidatorInterface::hasMetadataFor method instead.', E_USER_DEPRECATED);
$validator = $this->getValidator();
if ($validator instanceof LegacyValidatorInterface) {
return $validator->getMetadataFactory();
}
// The ValidatorInterface extends from the deprecated MetadataFactoryInterface, so return it when we don't have the factory instance itself
return $validator;
}
/**
* {@inheritdoc}
*/

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Validator\Context;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
@ -60,8 +60,16 @@ use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface ExecutionContextInterface extends LegacyExecutionContextInterface
interface ExecutionContextInterface
{
/**
* Adds a violation at the current node of the validation graph.
*
* @param string $message The error message
* @param array $params The parameters substituted in the error message
*/
public function addViolation($message, array $params = array());
/**
* Returns a builder for adding a violation with extended information.
*
@ -224,4 +232,114 @@ interface ExecutionContextInterface extends LegacyExecutionContextInterface
* @see ObjectInitializerInterface
*/
public function isObjectInitialized($cacheKey);
/**
* Returns the violations generated by the validator so far.
*
* @return ConstraintViolationListInterface The constraint violation list.
*/
public function getViolations();
/**
* Returns the value at which validation was started in the object graph.
*
* The validator, when given an object, traverses the properties and
* related objects and their properties. The root of the validation is the
* object from which the traversal started.
*
* The current value is returned by {@link getValue}.
*
* @return mixed The root value of the validation.
*/
public function getRoot();
/**
* Returns the value that the validator is currently validating.
*
* If you want to retrieve the object that was originally passed to the
* validator, use {@link getRoot}.
*
* @return mixed The currently validated value.
*/
public function getValue();
/**
* Returns the metadata for the currently validated value.
*
* With the core implementation, this method returns a
* {@link Mapping\ClassMetadata} instance if the current value is an object,
* a {@link Mapping\PropertyMetadata} instance if the current value is
* the value of a property and a {@link Mapping\GetterMetadata} instance if
* the validated value is the result of a getter method.
*
* If the validated value is neither of these, for example if the validator
* has been called with a plain value and constraint, this method returns
* null.
*
* @return MetadataInterface|null The metadata of the currently validated
* value.
*/
public function getMetadata();
/**
* Returns the validation group that is currently being validated.
*
* @return string The current validation group.
*/
public function getGroup();
/**
* Returns the class name of the current node.
*
* If the metadata of the current node does not implement
* {@link ClassMetadataInterface} or if no metadata is available for the
* current node, this method returns null.
*
* @return string|null The class name or null, if no class name could be found.
*/
public function getClassName();
/**
* Returns the property name of the current node.
*
* If the metadata of the current node does not implement
* {@link PropertyMetadataInterface} or if no metadata is available for the
* current node, this method returns null.
*
* @return string|null The property name or null, if no property name could be found.
*/
public function getPropertyName();
/**
* Returns the property path to the value that the validator is currently
* validating.
*
* For example, take the following object graph:
*
* <pre>
* (Person)---($address: Address)---($street: string)
* </pre>
*
* When the <tt>Person</tt> instance is passed to the validator, the
* property path is initially empty. When the <tt>$address</tt> property
* of that person is validated, the property path is "address". When
* the <tt>$street</tt> property of the related <tt>Address</tt> instance
* is validated, the property path is "address.street".
*
* Properties of objects are prefixed with a dot in the property path.
* Indices of arrays or objects implementing the {@link \ArrayAccess}
* interface are enclosed in brackets. For example, if the property in
* the previous example is <tt>$addresses</tt> and contains an array
* of <tt>Address</tt> instance, the property path generated for the
* <tt>$street</tt> property of one of these addresses is for example
* "addresses[0].street".
*
* @param string $subPath Optional. The suffix appended to the current
* property path.
*
* @return string The current property path. The result may be an empty
* string if the validator is currently validating the
* root value of the validation graph.
*/
public function getPropertyPath($subPath = '');
}

View File

@ -1,55 +0,0 @@
<?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\Context;
@trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContext class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* An execution context that is compatible with the legacy API (< 2.5).
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
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;
}
}

View File

@ -1,77 +0,0 @@
<?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\Context;
@trigger_error('The '.__NAMESPACE__.'\LegacyExecutionContextFactory class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
/**
* Creates new {@link LegacyExecutionContext} instances.
*
* Implemented for backward compatibility with Symfony < 2.5.
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
class LegacyExecutionContextFactory implements ExecutionContextFactoryInterface
{
/**
* @var MetadataFactoryInterface
*/
private $metadataFactory;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var string|null
*/
private $translationDomain;
/**
* Creates a new context factory.
*
* @param MetadataFactoryInterface $metadataFactory The metadata factory
* @param TranslatorInterface $translator The translator
* @param string|null $translationDomain The translation domain
* to use for translating
* violation messages
*/
public function __construct(MetadataFactoryInterface $metadataFactory, TranslatorInterface $translator, $translationDomain = null)
{
$this->metadataFactory = $metadataFactory;
$this->translator = $translator;
$this->translationDomain = $translationDomain;
}
/**
* {@inheritdoc}
*/
public function createContext(ValidatorInterface $validator, $root)
{
return new LegacyExecutionContext(
$validator,
$root,
$this->metadataFactory,
$this->translator,
$this->translationDomain
);
}
}

View File

@ -1,171 +0,0 @@
<?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;
@trigger_error('The class '.__NAMESPACE__.'\DefaultTranslator is deprecated since version 2.7 and will be removed in 3.0. Use Symfony\Component\Translation\IdentityTranslator instead.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Exception\BadMethodCallException;
use Symfony\Component\Validator\Exception\InvalidArgumentException;
/**
* Simple translator implementation that simply replaces the parameters in
* the message IDs.
*
* Example usage:
*
* $translator = new DefaultTranslator();
*
* echo $translator->trans(
* 'This is a {{ var }}.',
* array('{{ var }}' => 'donkey')
* );
*
* // -> This is a donkey.
*
* echo $translator->transChoice(
* 'This is {{ count }} donkey.|These are {{ count }} donkeys.',
* 3,
* array('{{ count }}' => 'three')
* );
*
* // -> These are three donkeys.
*
* This translator does not support message catalogs, translation domains or
* locales. Instead, it implements a subset of the capabilities of
* {@link \Symfony\Component\Translation\Translator} and can be used in places
* where translation is not required by default but should be optional.
*
* @deprecated since version 2.7, to be removed in 3.0. Use Symfony\Component\Translation\IdentityTranslator instead.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class DefaultTranslator implements TranslatorInterface
{
/**
* Interpolates the given message.
*
* Parameters are replaced in the message in the same manner that
* {@link strtr()} uses.
*
* Example usage:
*
* $translator = new DefaultTranslator();
*
* echo $translator->trans(
* 'This is a {{ var }}.',
* array('{{ var }}' => 'donkey')
* );
*
* // -> This is a donkey.
*
* @param string $id The message id
* @param array $parameters An array of parameters for the message
* @param string $domain Ignored
* @param string $locale Ignored
*
* @return string The interpolated string
*/
public function trans($id, array $parameters = array(), $domain = null, $locale = null)
{
return strtr($id, $parameters);
}
/**
* Interpolates the given choice message by choosing a variant according to a number.
*
* The variants are passed in the message ID using the format
* "<singular>|<plural>". "<singular>" is chosen if the passed $number is
* exactly 1. "<plural>" is chosen otherwise.
*
* This format is consistent with the format supported by
* {@link \Symfony\Component\Translation\Translator}, but it does not
* have the same expressiveness. While Translator supports intervals in
* message translations, which are needed for languages other than English,
* this translator does not. You should use Translator or a custom
* implementation of {@link \Symfony\Component\Translation\TranslatorInterface} if you need this or similar
* functionality.
*
* Example usage:
*
* echo $translator->transChoice(
* 'This is {{ count }} donkey.|These are {{ count }} donkeys.',
* 0,
* array('{{ count }}' => 0)
* );
*
* // -> These are 0 donkeys.
*
* echo $translator->transChoice(
* 'This is {{ count }} donkey.|These are {{ count }} donkeys.',
* 1,
* array('{{ count }}' => 1)
* );
*
* // -> This is 1 donkey.
*
* echo $translator->transChoice(
* 'This is {{ count }} donkey.|These are {{ count }} donkeys.',
* 3,
* array('{{ count }}' => 3)
* );
*
* // -> These are 3 donkeys.
*
* @param string $id The message id
* @param int $number The number to use to find the index of the message
* @param array $parameters An array of parameters for the message
* @param string $domain Ignored
* @param string $locale Ignored
*
* @return string The translated string
*
* @throws InvalidArgumentException If the message id does not have the format
* "singular|plural".
*/
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null)
{
$ids = explode('|', $id);
if (1 == $number) {
return strtr($ids[0], $parameters);
}
if (!isset($ids[1])) {
throw new InvalidArgumentException(sprintf('The message "%s" cannot be pluralized, because it is missing a plural (e.g. "There is one apple|There are %%count%% apples").', $id));
}
return strtr($ids[1], $parameters);
}
/**
* Not supported.
*
* @param string $locale The locale
*
* @throws BadMethodCallException
*/
public function setLocale($locale)
{
throw new BadMethodCallException('Unsupported method.');
}
/**
* Returns the locale of the translator.
*
* @return string Always returns 'en'
*/
public function getLocale()
{
return 'en';
}
}

View File

@ -1,295 +0,0 @@
<?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;
@trigger_error('The '.__NAMESPACE__.'\ExecutionContext class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Context\ExecutionContext class instead.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
/**
* Default implementation of {@link ExecutionContextInterface}.
*
* This class is immutable by design.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContext} instead.
*/
class ExecutionContext implements ExecutionContextInterface
{
/**
* @var GlobalExecutionContextInterface
*/
private $globalContext;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* @var MetadataInterface
*/
private $metadata;
/**
* @var mixed
*/
private $value;
/**
* @var string
*/
private $group;
/**
* @var string
*/
private $propertyPath;
/**
* Creates a new execution context.
*
* @param GlobalExecutionContextInterface $globalContext The global context storing node-independent state.
* @param TranslatorInterface $translator The translator for translating violation messages.
* @param null|string $translationDomain The domain of the validation messages.
* @param MetadataInterface $metadata The metadata of the validated node.
* @param mixed $value The value of the validated node.
* @param string $group The current validation group.
* @param string $propertyPath The property path to the current node.
*/
public function __construct(GlobalExecutionContextInterface $globalContext, TranslatorInterface $translator, $translationDomain = null, MetadataInterface $metadata = null, $value = null, $group = null, $propertyPath = '')
{
if (null === $group) {
$group = Constraint::DEFAULT_GROUP;
}
$this->globalContext = $globalContext;
$this->translator = $translator;
$this->translationDomain = $translationDomain;
$this->metadata = $metadata;
$this->value = $value;
$this->propertyPath = $propertyPath;
$this->group = $group;
}
/**
* {@inheritdoc}
*/
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
{
if (null === $plural) {
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
} else {
try {
$translatedMessage = $this->translator->transChoice($message, $plural, $params, $this->translationDomain);
} catch (\InvalidArgumentException $e) {
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
}
}
$this->globalContext->getViolations()->add(new ConstraintViolation(
$translatedMessage,
$message,
$params,
$this->globalContext->getRoot(),
$this->propertyPath,
// check using func_num_args() to allow passing null values
func_num_args() >= 3 ? $invalidValue : $this->value,
$plural,
$code
));
}
/**
* {@inheritdoc}
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
{
$this->globalContext->getViolations()->add(new ConstraintViolation(
null === $plural
? $this->translator->trans($message, $parameters, $this->translationDomain)
: $this->translator->transChoice($message, $plural, $parameters, $this->translationDomain),
$message,
$parameters,
$this->globalContext->getRoot(),
$this->getPropertyPath($subPath),
// check using func_num_args() to allow passing null values
func_num_args() >= 4 ? $invalidValue : $this->value,
$plural,
$code
));
}
/**
* {@inheritdoc}
*/
public function getViolations()
{
return $this->globalContext->getViolations();
}
/**
* {@inheritdoc}
*/
public function getRoot()
{
return $this->globalContext->getRoot();
}
/**
* {@inheritdoc}
*/
public function getPropertyPath($subPath = '')
{
if ('' != $subPath && '' !== $this->propertyPath && '[' !== $subPath[0]) {
return $this->propertyPath.'.'.$subPath;
}
return $this->propertyPath.$subPath;
}
/**
* {@inheritdoc}
*/
public function getClassName()
{
if ($this->metadata instanceof ClassBasedInterface) {
return $this->metadata->getClassName();
}
}
/**
* {@inheritdoc}
*/
public function getPropertyName()
{
if ($this->metadata instanceof PropertyMetadataInterface) {
return $this->metadata->getPropertyName();
}
}
/**
* {@inheritdoc}
*/
public function getValue()
{
return $this->value;
}
/**
* {@inheritdoc}
*/
public function getGroup()
{
return $this->group;
}
/**
* {@inheritdoc}
*/
public function getMetadata()
{
return $this->metadata;
}
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
return $this->globalContext->getMetadataFactory()->getMetadataFor($value);
}
/**
* {@inheritdoc}
*/
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false)
{
$propertyPath = $this->getPropertyPath($subPath);
foreach ($this->resolveGroups($groups) as $group) {
$this->globalContext->getVisitor()->validate($value, $group, $propertyPath, $traverse, $deep);
}
}
/**
* {@inheritdoc}
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null)
{
$constraints = is_array($constraints) ? $constraints : array($constraints);
if (null === $groups && '' === $subPath) {
$context = clone $this;
$context->value = $value;
$context->executeConstraintValidators($value, $constraints);
return;
}
$propertyPath = $this->getPropertyPath($subPath);
foreach ($this->resolveGroups($groups) as $group) {
$context = clone $this;
$context->value = $value;
$context->group = $group;
$context->propertyPath = $propertyPath;
$context->executeConstraintValidators($value, $constraints);
}
}
/**
* {@inheritdoc}
*/
public function getMetadataFactory()
{
return $this->globalContext->getMetadataFactory();
}
/**
* Executes the validators of the given constraints for the given value.
*
* @param mixed $value The value to validate.
* @param Constraint[] $constraints The constraints to match against.
*/
private function executeConstraintValidators($value, array $constraints)
{
foreach ($constraints as $constraint) {
$validator = $this->globalContext->getValidatorFactory()->getInstance($constraint);
$validator->initialize($this);
$validator->validate($value, $constraint);
}
}
/**
* Returns an array of group names.
*
* @param null|string|string[] $groups The groups to resolve. If a single string is
* passed, it is converted to an array. If null
* is passed, an array containing the current
* group of the context is returned.
*
* @return array An array of validation groups.
*/
private function resolveGroups($groups)
{
return $groups ? (array) $groups : (array) $this->group;
}
}

View File

@ -1,319 +0,0 @@
<?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;
/**
* Stores the validator's state during validation.
*
* For example, let's validate the following object graph:
*
* <pre>
* (Person)---($firstName: string)
* \
* ($address: Address)---($street: string)
* </pre>
*
* We validate the <tt>Person</tt> instance, which becomes the "root" of the
* validation run (see {@link getRoot}). The state of the context after the
* first step will be like this:
*
* <pre>
* (Person)---($firstName: string)
* ^ \
* ($address: Address)---($street: string)
* </pre>
*
* The validator is stopped at the <tt>Person</tt> node, both the root and the
* value (see {@link getValue}) of the context point to the <tt>Person</tt>
* instance. The property path is empty at this point (see {@link getPropertyPath}).
* The metadata of the context is the metadata of the <tt>Person</tt> node
* (see {@link getMetadata}).
*
* After advancing to the property <tt>$firstName</tt> of the <tt>Person</tt>
* instance, the state of the context looks like this:
*
* <pre>
* (Person)---($firstName: string)
* \ ^
* ($address: Address)---($street: string)
* </pre>
*
* The validator is stopped at the property <tt>$firstName</tt>. The root still
* points to the <tt>Person</tt> instance, because this is where the validation
* started. The property path is now "firstName" and the current value is the
* value of that property.
*
* After advancing to the <tt>$address</tt> property and then to the
* <tt>$street</tt> property of the <tt>Address</tt> instance, the context state
* looks like this:
*
* <pre>
* (Person)---($firstName: string)
* \
* ($address: Address)---($street: string)
* ^
* </pre>
*
* The validator is stopped at the property <tt>$street</tt>. The root still
* points to the <tt>Person</tt> instance, but the property path is now
* "address.street" and the validated value is the value of that property.
*
* Apart from the root, the property path and the currently validated value,
* the execution context also knows the metadata of the current node (see
* {@link getMetadata}) which for example returns a {@link Mapping\PropertyMetadata}
* or a {@link Mapping\ClassMetadata} object. he context also contains the
* validation group that is currently being validated (see {@link getGroup}) and
* the violations that happened up until now (see {@link getViolations}).
*
* Apart from reading the execution context, you can also use
* {@link addViolation} or {@link addViolationAt} to add new violations and
* {@link validate} or {@link validateValue} to validate values that the
* validator otherwise would not reach.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface} instead.
*/
interface ExecutionContextInterface
{
/**
* Adds a violation at the current node of the validation graph.
*
* Note: the parameters $invalidValue, $plural and $code are deprecated since version 2.5 and will be removed in 3.0.
*
* @param string $message The error message
* @param array $params The parameters substituted in the error message
* @param mixed $invalidValue The invalid, validated value
* @param int|null $plural The number to use to pluralize of the message
* @param int|null $code The violation code
*/
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null);
/**
* Adds a violation at the validation graph node with the given property
* path relative to the current property path.
*
* @param string $subPath The relative property path for the violation
* @param string $message The error message
* @param array $parameters The parameters substituted in the error message
* @param mixed $invalidValue The invalid, validated value
* @param int|null $plural The number to use to pluralize of the message
* @param int|null $code The violation code
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface::buildViolation()}
* instead.
*/
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null);
/**
* Validates the given value within the scope of the current validation.
*
* The value may be any value recognized by the used metadata factory
* (see {@link MetadataFactoryInterface::getMetadata}), or an array or a
* traversable object of such values.
*
* Usually you validate a value that is not the current node of the
* execution context. For this case, you can pass the {@link $subPath}
* argument which is appended to the current property path when a violation
* is created. For example, take the following object graph:
*
* <pre>
* (Person)---($address: Address)---($phoneNumber: PhoneNumber)
* ^
* </pre>
*
* When the execution context stops at the <tt>Person</tt> instance, the
* property path is "address". When you validate the <tt>PhoneNumber</tt>
* instance now, pass "phoneNumber" as sub path to correct the property path
* to "address.phoneNumber":
*
* <pre>
* $context->validate($address->phoneNumber, 'phoneNumber');
* </pre>
*
* Any violations generated during the validation will be added to the
* violation list that you can access with {@link getViolations}.
*
* @param mixed $value The value to validate.
* @param string $subPath The path to append to the context's property path.
* @param null|string|string[] $groups The groups to validate in. If you don't pass any
* groups here, the current group of the context
* will be used.
* @param bool $traverse Whether to traverse the value if it is an array
* or an instance of <tt>\Traversable</tt>.
* @param bool $deep Whether to traverse the value recursively if
* it is a collection of collections.
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface::getValidator()}
* instead.
*/
public function validate($value, $subPath = '', $groups = null, $traverse = false, $deep = false);
/**
* Validates a value against a constraint.
*
* Use the parameter <tt>$subPath</tt> to adapt the property path for the
* validated value. For example, take the following object graph:
*
* <pre>
* (Person)---($address: Address)---($street: string)
* ^
* </pre>
*
* When the validator validates the <tt>Address</tt> instance, the
* property path stored in the execution context is "address". When you
* manually validate the property <tt>$street</tt> now, pass the sub path
* "street" to adapt the full property path to "address.street":
*
* <pre>
* $context->validate($address->street, new NotNull(), 'street');
* </pre>
*
* @param mixed $value The value to validate.
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against.
* @param string $subPath The path to append to the context's property path.
* @param null|string|string[] $groups The groups to validate in. If you don't pass any
* groups here, the current group of the context
* will be used.
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface::getValidator()}
* instead.
*/
public function validateValue($value, $constraints, $subPath = '', $groups = null);
/**
* Returns the violations generated by the validator so far.
*
* @return ConstraintViolationListInterface The constraint violation list.
*/
public function getViolations();
/**
* Returns the value at which validation was started in the object graph.
*
* The validator, when given an object, traverses the properties and
* related objects and their properties. The root of the validation is the
* object from which the traversal started.
*
* The current value is returned by {@link getValue}.
*
* @return mixed The root value of the validation.
*/
public function getRoot();
/**
* Returns the value that the validator is currently validating.
*
* If you want to retrieve the object that was originally passed to the
* validator, use {@link getRoot}.
*
* @return mixed The currently validated value.
*/
public function getValue();
/**
* Returns the metadata for the currently validated value.
*
* With the core implementation, this method returns a
* {@link Mapping\ClassMetadata} instance if the current value is an object,
* a {@link Mapping\PropertyMetadata} instance if the current value is
* the value of a property and a {@link Mapping\GetterMetadata} instance if
* the validated value is the result of a getter method.
*
* If the validated value is neither of these, for example if the validator
* has been called with a plain value and constraint, this method returns
* null.
*
* @return MetadataInterface|null The metadata of the currently validated
* value.
*/
public function getMetadata();
/**
* Returns the used metadata factory.
*
* @return MetadataFactoryInterface The metadata factory.
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface::getValidator()}
* instead and call
* {@link Validator\ValidatorInterface::getMetadataFor()} or
* {@link Validator\ValidatorInterface::hasMetadataFor()} there.
*/
public function getMetadataFactory();
/**
* Returns the validation group that is currently being validated.
*
* @return string The current validation group.
*/
public function getGroup();
/**
* Returns the class name of the current node.
*
* If the metadata of the current node does not implement
* {@link ClassBasedInterface} or if no metadata is available for the
* current node, this method returns null.
*
* @return string|null The class name or null, if no class name could be found.
*/
public function getClassName();
/**
* Returns the property name of the current node.
*
* If the metadata of the current node does not implement
* {@link PropertyMetadataInterface} or if no metadata is available for the
* current node, this method returns null.
*
* @return string|null The property name or null, if no property name could be found.
*/
public function getPropertyName();
/**
* Returns the property path to the value that the validator is currently
* validating.
*
* For example, take the following object graph:
*
* <pre>
* (Person)---($address: Address)---($street: string)
* </pre>
*
* When the <tt>Person</tt> instance is passed to the validator, the
* property path is initially empty. When the <tt>$address</tt> property
* of that person is validated, the property path is "address". When
* the <tt>$street</tt> property of the related <tt>Address</tt> instance
* is validated, the property path is "address.street".
*
* Properties of objects are prefixed with a dot in the property path.
* Indices of arrays or objects implementing the {@link \ArrayAccess}
* interface are enclosed in brackets. For example, if the property in
* the previous example is <tt>$addresses</tt> and contains an array
* of <tt>Address</tt> instance, the property path generated for the
* <tt>$street</tt> property of one of these addresses is for example
* "addresses[0].street".
*
* @param string $subPath Optional. The suffix appended to the current
* property path.
*
* @return string The current property path. The result may be an empty
* string if the validator is currently validating the
* root value of the validation graph.
*/
public function getPropertyPath($subPath = '');
}

View File

@ -1,71 +0,0 @@
<?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;
/**
* Stores the node-independent state of a validation run.
*
* When the validator validates a graph of objects, it uses two classes to
* store the state during the validation:
*
* <ul>
* <li>For each node in the validation graph (objects, properties, getters) the
* validator creates an instance of {@link ExecutionContextInterface} that
* stores the information about that node.</li>
* <li>One single <tt>GlobalExecutionContextInterface</tt> stores the state
* that is independent of the current node.</li>
* </ul>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Context\ExecutionContextInterface} instead.
*/
interface GlobalExecutionContextInterface
{
/**
* Returns the violations generated by the validator so far.
*
* @return ConstraintViolationListInterface A list of constraint violations.
*/
public function getViolations();
/**
* Returns the value at which validation was started in the object graph.
*
* @return mixed The root value.
*
* @see ExecutionContextInterface::getRoot()
*/
public function getRoot();
/**
* Returns the visitor instance used to validate the object graph nodes.
*
* @return ValidationVisitorInterface The validation visitor.
*/
public function getVisitor();
/**
* Returns the factory for constraint validators.
*
* @return ConstraintValidatorFactoryInterface The constraint validator factory.
*/
public function getValidatorFactory();
/**
* Returns the factory for validation metadata objects.
*
* @return MetadataFactoryInterface The metadata factory.
*/
public function getMetadataFactory();
}

View File

@ -1,28 +0,0 @@
<?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\Mapping;
@trigger_error('The '.__NAMESPACE__.'\BlackholeMetadataFactory class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory class instead.', E_USER_DEPRECATED);
use Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory as MappingBlackHoleMetadataFactory;
/**
* Alias of {@link Factory\BlackHoleMetadataFactory}.
*
* @author Fabien Potencier <fabien@symfony.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Factory\BlackHoleMetadataFactory} instead.
*/
class BlackholeMetadataFactory extends MappingBlackHoleMetadataFactory
{
}

View File

@ -1,57 +0,0 @@
<?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\Mapping\Cache;
@trigger_error('The '.__NAMESPACE__.'\ApcCache class is deprecated since version 2.5 and will be removed in 3.0. Use DoctrineCache with the Doctrine\Common\Cache\ApcCache class instead.', E_USER_DEPRECATED);
use Symfony\Component\Validator\Mapping\ClassMetadata;
/**
* @deprecated since version 2.5, to be removed in 3.0.
* Use DoctrineCache with \Doctrine\Common\Cache\ApcCache instead.
*/
class ApcCache implements CacheInterface
{
private $prefix;
public function __construct($prefix)
{
if (!extension_loaded('apc')) {
throw new \RuntimeException('Unable to use ApcCache to cache validator mappings as APC is not enabled.');
}
$this->prefix = $prefix;
}
public function has($class)
{
if (!function_exists('apc_exists')) {
$exists = false;
apc_fetch($this->prefix.$class, $exists);
return $exists;
}
return apc_exists($this->prefix.$class);
}
public function read($class)
{
return apc_fetch($this->prefix.$class);
}
public function write(ClassMetadata $metadata)
{
apc_store($this->prefix.$metadata->getClassName(), $metadata);
}
}

View File

@ -17,7 +17,6 @@ use Symfony\Component\Validator\Constraints\Traverse;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
use Symfony\Component\Validator\Exception\GroupDefinitionException;
use Symfony\Component\Validator\ValidationVisitorInterface;
/**
* Default implementation of {@link ClassMetadataInterface}.
@ -27,7 +26,7 @@ use Symfony\Component\Validator\ValidationVisitorInterface;
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Fabien Potencier <fabien@symfony.com>
*/
class ClassMetadata extends ElementMetadata implements ClassMetadataInterface
class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
{
/**
* @var string
@ -126,47 +125,6 @@ class ClassMetadata extends ElementMetadata implements ClassMetadataInterface
}
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath, $propagatedGroup = null)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
if (null === $propagatedGroup && Constraint::DEFAULT_GROUP === $group
&& ($this->hasGroupSequence() || $this->isGroupSequenceProvider())) {
if ($this->hasGroupSequence()) {
$groups = $this->getGroupSequence()->groups;
} else {
$groups = $value->getGroupSequence();
}
foreach ($groups as $group) {
$this->accept($visitor, $value, $group, $propertyPath, Constraint::DEFAULT_GROUP);
if (count($visitor->getViolations()) > 0) {
break;
}
}
return;
}
$visitor->visit($this, $value, $group, $propertyPath);
if (null !== $value) {
$pathPrefix = empty($propertyPath) ? '' : $propertyPath.'.';
foreach ($this->getConstrainedProperties() as $property) {
foreach ($this->getPropertyMetadata($property) as $member) {
$member->accept($visitor, $member->getPropertyValue($value), $group, $pathPrefix.$property, $propagatedGroup);
}
}
}
}
/**
* {@inheritdoc}
*/
@ -368,52 +326,6 @@ class ClassMetadata extends ElementMetadata implements ClassMetadataInterface
}
}
/**
* Adds a member metadata.
*
* @param MemberMetadata $metadata
*
* @deprecated since version 2.6, to be removed in 3.0.
*/
protected function addMemberMetadata(MemberMetadata $metadata)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the addPropertyMetadata() method instead.', E_USER_DEPRECATED);
$this->addPropertyMetadata($metadata);
}
/**
* Returns true if metadatas of members is present for the given property.
*
* @param string $property The name of the property
*
* @return bool
*
* @deprecated since version 2.6, to be removed in 3.0. Use {@link hasPropertyMetadata} instead.
*/
public function hasMemberMetadatas($property)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the hasPropertyMetadata() method instead.', E_USER_DEPRECATED);
return $this->hasPropertyMetadata($property);
}
/**
* Returns all metadatas of members describing the given property.
*
* @param string $property The name of the property
*
* @return MemberMetadata[] An array of MemberMetadata
*
* @deprecated since version 2.6, to be removed in 3.0. Use {@link getPropertyMetadata} instead.
*/
public function getMemberMetadatas($property)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.6 and will be removed in 3.0. Use the getPropertyMetadata() method instead.', E_USER_DEPRECATED);
return $this->getPropertyMetadata($property);
}
/**
* {@inheritdoc}
*/

View File

@ -1,28 +0,0 @@
<?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\Mapping;
@trigger_error('The '.__NAMESPACE__.'\ClassMetadataFactory class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory class instead.', E_USER_DEPRECATED);
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
/**
* Alias of {@link LazyLoadingMetadataFactory}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link LazyLoadingMetadataFactory} instead.
*/
class ClassMetadataFactory extends LazyLoadingMetadataFactory
{
}

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\Validator\Mapping;
use Symfony\Component\Validator\ClassBasedInterface;
use Symfony\Component\Validator\PropertyMetadataContainerInterface as LegacyPropertyMetadataContainerInterface;
/**
* Stores all metadata needed for validating objects of specific class.
*
@ -33,7 +30,7 @@ use Symfony\Component\Validator\PropertyMetadataContainerInterface as LegacyProp
* @see \Symfony\Component\Validator\GroupSequenceProviderInterface
* @see TraversalStrategy
*/
interface ClassMetadataInterface extends MetadataInterface, LegacyPropertyMetadataContainerInterface, ClassBasedInterface
interface ClassMetadataInterface extends MetadataInterface
{
/**
* Returns the names of all constrained properties.
@ -78,4 +75,33 @@ interface ClassMetadataInterface extends MetadataInterface, LegacyPropertyMetada
* @see \Symfony\Component\Validator\GroupSequenceProviderInterface
*/
public function isGroupSequenceProvider();
/**
* Check if there's any metadata attached to the given named property.
*
* @param string $property The property name.
*
* @return bool
*/
public function hasPropertyMetadata($property);
/**
* Returns all metadata instances for the given named property.
*
* If your implementation does not support properties, simply throw an
* exception in this method (for example a <tt>BadMethodCallException</tt>).
*
* @param string $property The property name.
*
* @return PropertyMetadataInterface[] A list of metadata instances. Empty if
* no metadata exists for the property.
*/
public function getPropertyMetadata($property);
/**
* Returns the name of the backing PHP class.
*
* @return string The name of the backing class.
*/
public function getClassName();
}

View File

@ -1,30 +0,0 @@
<?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\Mapping;
/**
* Contains the metadata of a structural element.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Extend {@link GenericMetadata} instead.
*/
abstract class ElementMetadata extends GenericMetadata
{
public function __construct()
{
if (!$this instanceof MemberMetadata && !$this instanceof ClassMetadata) {
@trigger_error('The '.__CLASS__.' class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Mapping\GenericMetadata class instead.', E_USER_DEPRECATED);
}
}
}

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Validator\Mapping\Factory;
use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface;
use Symfony\Component\Validator\Exception;
/**
* Returns {@link \Symfony\Component\Validator\Mapping\MetadataInterface} instances for values.
@ -20,6 +20,25 @@ use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactor
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
interface MetadataFactoryInterface extends LegacyMetadataFactoryInterface
interface MetadataFactoryInterface
{
/**
* Returns the metadata for the given value.
*
* @param mixed $value Some value
*
* @return MetadataInterface The metadata for the value
*
* @throws Exception\NoSuchMetadataException If no metadata exists for the given value
*/
public function getMetadataFor($value);
/**
* Returns whether the class is able to return metadata for the given value.
*
* @param mixed $value Some value
*
* @return bool Whether metadata can be returned for that value
*/
public function hasMetadataFor($value);
}

View File

@ -112,13 +112,10 @@ class GenericMetadata implements MetadataInterface
*
* If the constraint {@link Valid} is added, the cascading strategy will be
* changed to {@link CascadingStrategy::CASCADE}. Depending on the
* properties $traverse and $deep of that constraint, the traversal strategy
* $traverse property of that constraint, the traversal strategy
* will be set to one of the following:
*
* - {@link TraversalStrategy::IMPLICIT} if $traverse is enabled and $deep
* is enabled
* - {@link TraversalStrategy::IMPLICIT} | {@link TraversalStrategy::STOP_RECURSION}
* if $traverse is enabled, but $deep is disabled
* - {@link TraversalStrategy::IMPLICIT} if $traverse is enabled
* - {@link TraversalStrategy::NONE} if $traverse is disabled
*
* @param Constraint $constraint The constraint to add
@ -144,10 +141,6 @@ class GenericMetadata implements MetadataInterface
if ($constraint->traverse) {
// Traverse unless the value is not traversable
$this->traversalStrategy = TraversalStrategy::IMPLICIT;
if (!$constraint->deep) {
$this->traversalStrategy |= TraversalStrategy::STOP_RECURSION;
}
} else {
$this->traversalStrategy = TraversalStrategy::NONE;
}
@ -225,21 +218,4 @@ class GenericMetadata implements MetadataInterface
{
return $this->traversalStrategy;
}
/**
* Exists for compatibility with the deprecated
* {@link Symfony\Component\Validator\MetadataInterface}.
*
* Should not be used.
*
* Implemented for backward compatibility with Symfony < 2.5.
*
* @throws BadMethodCallException
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath)
{
throw new BadMethodCallException('Not supported.');
}
}

View File

@ -27,7 +27,7 @@ use Symfony\Component\Validator\ValidationVisitorInterface;
*
* @see PropertyMetadataInterface
*/
abstract class MemberMetadata extends ElementMetadata implements PropertyMetadataInterface
abstract class MemberMetadata extends GenericMetadata implements PropertyMetadataInterface
{
/**
* @var string
@ -75,22 +75,6 @@ abstract class MemberMetadata extends ElementMetadata implements PropertyMetadat
$this->property = $property;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath, $propagatedGroup = null)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
$visitor->visit($this, $value, $group, $propertyPath);
if ($this->isCascaded()) {
$visitor->validate($value, $propagatedGroup ?: $group, $propertyPath, $this->isCollectionCascaded(), $this->isCollectionCascadedDeeply());
}
}
/**
* {@inheritdoc}
*/
@ -182,53 +166,6 @@ abstract class MemberMetadata extends ElementMetadata implements PropertyMetadat
return $this->getReflectionMember($objectOrClassName)->isPrivate();
}
/**
* Returns whether objects stored in this member should be validated.
*
* @return bool
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link getCascadingStrategy()} instead.
*/
public function isCascaded()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getCascadingStrategy() method instead.', E_USER_DEPRECATED);
return (bool) ($this->cascadingStrategy & CascadingStrategy::CASCADE);
}
/**
* Returns whether arrays or traversable objects stored in this member
* should be traversed and validated in each entry.
*
* @return bool
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link getTraversalStrategy()} instead.
*/
public function isCollectionCascaded()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getTraversalStrategy() method instead.', E_USER_DEPRECATED);
return (bool) ($this->traversalStrategy & (TraversalStrategy::IMPLICIT | TraversalStrategy::TRAVERSE));
}
/**
* Returns whether arrays or traversable objects stored in this member
* should be traversed recursively for inner arrays/traversable objects.
*
* @return bool
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link getTraversalStrategy()} instead.
*/
public function isCollectionCascadedDeeply()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. Use the getTraversalStrategy() method instead.', E_USER_DEPRECATED);
return !($this->traversalStrategy & TraversalStrategy::STOP_RECURSION);
}
/**
* Returns the reflection instance for accessing the member's value.
*

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Validator\Mapping;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\MetadataInterface as LegacyMetadataInterface;
use Symfony\Component\Validator\ValidationVisitorInterface;
/**
* A container for validation metadata.
@ -31,7 +31,7 @@ use Symfony\Component\Validator\MetadataInterface as LegacyMetadataInterface;
* @see CascadingStrategy
* @see TraversalStrategy
*/
interface MetadataInterface extends LegacyMetadataInterface
interface MetadataInterface
{
/**
* Returns the strategy for cascading objects.
@ -57,4 +57,13 @@ interface MetadataInterface extends LegacyMetadataInterface
* @return Constraint[] A list of Constraint instances
*/
public function getConstraints();
/**
* Returns all constraints for a given validation group.
*
* @param string $group The validation group
*
* @return Constraint[] A list of constraint instances
*/
public function findConstraints($group);
}

View File

@ -11,9 +11,6 @@
namespace Symfony\Component\Validator\Mapping;
use Symfony\Component\Validator\ClassBasedInterface;
use Symfony\Component\Validator\PropertyMetadataInterface as LegacyPropertyMetadataInterface;
/**
* Stores all metadata needed for validating the value of a class property.
*
@ -32,6 +29,21 @@ use Symfony\Component\Validator\PropertyMetadataInterface as LegacyPropertyMetad
* @see CascadingStrategy
* @see TraversalStrategy
*/
interface PropertyMetadataInterface extends MetadataInterface, LegacyPropertyMetadataInterface, ClassBasedInterface
interface PropertyMetadataInterface extends MetadataInterface
{
/**
* Returns the name of the property.
*
* @return string The property name.
*/
public function getPropertyName();
/**
* Extracts the value of the property from the given container.
*
* @param mixed $containingValue The container to extract the property value from.
*
* @return mixed The value of the property.
*/
public function getPropertyValue($containingValue);
}

View File

@ -1,43 +0,0 @@
<?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;
/**
* Returns {@link MetadataInterface} instances for values.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\Factory\MetadataFactoryInterface} instead.
*/
interface MetadataFactoryInterface
{
/**
* Returns the metadata for the given value.
*
* @param mixed $value Some value
*
* @return MetadataInterface The metadata for the value
*
* @throws Exception\NoSuchMetadataException If no metadata exists for the given value
*/
public function getMetadataFor($value);
/**
* Returns whether the class is able to return metadata for the given value.
*
* @param mixed $value Some value
*
* @return bool Whether metadata can be returned for that value
*/
public function hasMetadataFor($value);
}

View File

@ -1,73 +0,0 @@
<?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;
/**
* A container for validation metadata.
*
* The container contains constraints that may belong to different validation
* groups. Constraints for a specific group can be fetched by calling
* {@link findConstraints}.
*
* Implement this interface to add validation metadata to your own metadata
* layer. Each metadata may have named properties. Each property can be
* represented by one or more {@link PropertyMetadataInterface} instances that
* are returned by {@link getPropertyMetadata}. Since
* <tt>PropertyMetadataInterface</tt> inherits from <tt>MetadataInterface</tt>,
* each property may be divided into further properties.
*
* The {@link accept} method of each metadata implements the Visitor pattern.
* The method should forward the call to the visitor's
* {@link ValidationVisitorInterface::visit} method and additionally call
* <tt>accept()</tt> on all structurally related metadata instances.
*
* For example, to store constraints for PHP classes and their properties,
* create a class <tt>ClassMetadata</tt> (implementing <tt>MetadataInterface</tt>)
* and a class <tt>PropertyMetadata</tt> (implementing <tt>PropertyMetadataInterface</tt>).
* <tt>ClassMetadata::getPropertyMetadata($property)</tt> returns all
* <tt>PropertyMetadata</tt> instances for a property of that class. Its
* <tt>accept()</tt>-method simply forwards to <tt>ValidationVisitorInterface::visit()</tt>
* and calls <tt>accept()</tt> on all contained <tt>PropertyMetadata</tt>
* instances, which themselves call <tt>ValidationVisitorInterface::visit()</tt>
* again.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\MetadataInterface} instead.
*/
interface MetadataInterface
{
/**
* Implementation of the Visitor design pattern.
*
* Calls {@link ValidationVisitorInterface::visit} and then forwards the
* <tt>accept()</tt>-call to all property metadata instances.
*
* @param ValidationVisitorInterface $visitor The visitor implementing the validation logic
* @param mixed $value The value to validate
* @param string|string[] $group The validation group to validate in
* @param string $propertyPath The current property path in the validation graph
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath);
/**
* Returns all constraints for a given validation group.
*
* @param string $group The validation group
*
* @return Constraint[] A list of constraint instances
*/
public function findConstraints($group);
}

View File

@ -1,45 +0,0 @@
<?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;
/**
* A container for {@link PropertyMetadataInterface} instances.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\ClassMetadataInterface} instead.
*/
interface PropertyMetadataContainerInterface
{
/**
* Check if there's any metadata attached to the given named property.
*
* @param string $property The property name.
*
* @return bool
*/
public function hasPropertyMetadata($property);
/**
* Returns all metadata instances for the given named property.
*
* If your implementation does not support properties, simply throw an
* exception in this method (for example a <tt>BadMethodCallException</tt>).
*
* @param string $property The property name.
*
* @return PropertyMetadataInterface[] A list of metadata instances. Empty if
* no metadata exists for the property.
*/
public function getPropertyMetadata($property);
}

View File

@ -1,46 +0,0 @@
<?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;
/**
* A container for validation metadata of a property.
*
* What exactly you define as "property" is up to you. The validator expects
* implementations of {@link MetadataInterface} that contain constraints and
* optionally a list of named properties that also have constraints (and may
* have further sub properties). Such properties are mapped by implementations
* of this interface.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see MetadataInterface
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Mapping\PropertyMetadataInterface} instead.
*/
interface PropertyMetadataInterface extends MetadataInterface
{
/**
* Returns the name of the property.
*
* @return string The property name.
*/
public function getPropertyName();
/**
* Extracts the value of the property from the given container.
*
* @param mixed $containingValue The container to extract the property value from.
*
* @return mixed The value of the property.
*/
public function getPropertyValue($containingValue);
}

View File

@ -17,8 +17,6 @@ use Symfony\Component\Validator\ConstraintValidatorInterface;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Context\ExecutionContext;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Context\LegacyExecutionContext;
use Symfony\Component\Validator\ExecutionContextInterface as LegacyExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\PropertyMetadata;
use Symfony\Component\Validator\Validation;
@ -100,27 +98,7 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
$validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
$contextualValidator = $this->getMock('Symfony\Component\Validator\Validator\ContextualValidatorInterface');
switch ($this->getApiVersion()) {
case Validation::API_VERSION_2_5:
$context = new ExecutionContext(
$validator,
$this->root,
$translator
);
break;
case Validation::API_VERSION_2_4:
case Validation::API_VERSION_2_5_BC:
$context = new LegacyExecutionContext(
$validator,
$this->root,
$this->getMock('Symfony\Component\Validator\MetadataFactoryInterface'),
$translator
);
break;
default:
throw new \RuntimeException('Invalid API version');
}
$context = new ExecutionContext($validator, $this->root, $translator);
$context->setGroup($this->group);
$context->setNode($this->value, $this->object, $this->metadata, $this->propertyPath);
$context->setConstraint($this->constraint);
@ -133,33 +111,6 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
return $context;
}
/**
* @param mixed $message
* @param array $parameters
* @param string $propertyPath
* @param string $invalidValue
* @param null $plural
* @param null $code
*
* @return ConstraintViolation
*
* @deprecated to be removed in Symfony 3.0. Use {@link buildViolation()} instead.
*/
protected function createViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
{
return new ConstraintViolation(
null,
$message,
$parameters,
$this->root,
$propertyPath,
$invalidValue,
$plural,
$code,
$this->constraint
);
}
protected function setGroup($group)
{
$this->group = $group;
@ -243,51 +194,6 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
$this->assertSame(0, $violationsCount = count($this->context->getViolations()), sprintf('0 violation expected. Got %u.', $violationsCount));
}
/**
* @param mixed $message
* @param array $parameters
* @param string $propertyPath
* @param string $invalidValue
* @param null $plural
* @param null $code
*
* @deprecated To be removed in Symfony 3.0. Use
* {@link buildViolation()} instead.
*/
protected function assertViolation($message, array $parameters = array(), $propertyPath = 'property.path', $invalidValue = 'InvalidValue', $plural = null, $code = null)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the buildViolation() method instead.', E_USER_DEPRECATED);
$this->buildViolation($message)
->setParameters($parameters)
->atPath($propertyPath)
->setInvalidValue($invalidValue)
->setCode($code)
->setPlural($plural)
->assertRaised();
}
/**
* @param array $expected
*
* @deprecated To be removed in Symfony 3.0. Use
* {@link buildViolation()} instead.
*/
protected function assertViolations(array $expected)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.3 and will be removed in 3.0. Use the buildViolation() method instead.', E_USER_DEPRECATED);
$violations = $this->context->getViolations();
$this->assertCount(count($expected), $violations);
$i = 0;
foreach ($expected as $violation) {
$this->assertEquals($violation, $violations[$i++]);
}
}
/**
* @param $message
*
@ -312,7 +218,7 @@ abstract class AbstractConstraintValidatorTest extends \PHPUnit_Framework_TestCa
class ConstraintViolationAssertion
{
/**
* @var LegacyExecutionContextInterface
* @var ExecutionContextInterface
*/
private $context;
@ -331,7 +237,7 @@ class ConstraintViolationAssertion
private $constraint;
private $cause;
public function __construct(LegacyExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array())
public function __construct(ExecutionContextInterface $context, $message, Constraint $constraint = null, array $assertions = array())
{
$this->context = $context;
$this->message = $message;

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Validator\Tests\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\CallbackValidator;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Validation;
class CallbackValidatorTest_Class

View File

@ -11,7 +11,7 @@
namespace Symfony\Component\Validator\Tests\Fixtures;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @author Bernhard Schussek <bschussek@gmail.com>

View File

@ -13,7 +13,7 @@ namespace Symfony\Component\Validator\Tests\Fixtures;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class ConstraintAValidator extends ConstraintValidator
{

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Validator\Tests\Fixtures;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* @Symfony\Component\Validator\Tests\Fixtures\ConstraintA

View File

@ -12,7 +12,7 @@
namespace Symfony\Component\Validator\Tests\Fixtures;
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\MetadataInterface;
class FakeMetadataFactory implements MetadataFactoryInterface

View File

@ -1,20 +0,0 @@
<?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\Tests\Fixtures;
use Symfony\Component\Validator\ClassBasedInterface;
use Symfony\Component\Validator\MetadataInterface;
use Symfony\Component\Validator\PropertyMetadataContainerInterface;
interface LegacyClassMetadata extends MetadataInterface, PropertyMetadataContainerInterface, ClassBasedInterface
{
}

View File

@ -1,70 +0,0 @@
<?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\Tests\Fixtures;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Component\Validator\GlobalExecutionContextInterface;
use Symfony\Component\Validator\ValidationVisitorInterface;
/**
* @since 2.5.3
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0
*/
class StubGlobalExecutionContext implements GlobalExecutionContextInterface
{
private $violations;
private $root;
private $visitor;
public function __construct($root = null, ValidationVisitorInterface $visitor = null)
{
$this->violations = new ConstraintViolationList();
$this->root = $root;
$this->visitor = $visitor;
}
public function getViolations()
{
return $this->violations;
}
public function setRoot($root)
{
$this->root = $root;
}
public function getRoot()
{
return $this->root;
}
public function setVisitor(ValidationVisitorInterface $visitor)
{
$this->visitor = $visitor;
}
public function getVisitor()
{
return $this->visitor;
}
public function getValidatorFactory()
{
}
public function getMetadataFactory()
{
}
}

View File

@ -19,7 +19,7 @@ use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\FailingConstraint;
use Symfony\Component\Validator\Tests\Fixtures\FakeClassMetadata;

View File

@ -15,7 +15,7 @@ use Symfony\Component\Validator\Constraints\Callback;
use Symfony\Component\Validator\Constraints\GroupSequence;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintViolationInterface;
use Symfony\Component\Validator\ExecutionContextInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\FakeMetadataFactory;

View File

@ -14,7 +14,7 @@ namespace Symfony\Component\Validator\Tests\Validator;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Validator\RecursiveValidator;

View File

@ -1,212 +0,0 @@
<?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;
@trigger_error('The '.__NAMESPACE__.'\ValidationVisitor class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
/**
* Default implementation of {@link ValidationVisitorInterface} and
* {@link GlobalExecutionContextInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
class ValidationVisitor implements ValidationVisitorInterface, GlobalExecutionContextInterface
{
/**
* @var mixed
*/
private $root;
/**
* @var MetadataFactoryInterface
*/
private $metadataFactory;
/**
* @var ConstraintValidatorFactoryInterface
*/
private $validatorFactory;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* @var array
*/
private $objectInitializers;
/**
* @var ConstraintViolationList
*/
private $violations;
/**
* @var array
*/
private $validatedObjects = array();
/**
* Creates a new validation visitor.
*
* @param mixed $root The value passed to the validator.
* @param MetadataFactoryInterface $metadataFactory The factory for obtaining metadata instances.
* @param ConstraintValidatorFactoryInterface $validatorFactory The factory for creating constraint validators.
* @param TranslatorInterface $translator The translator for translating violation messages.
* @param string|null $translationDomain The domain of the translation messages.
* @param ObjectInitializerInterface[] $objectInitializers The initializers for preparing objects before validation.
*
* @throws UnexpectedTypeException If any of the object initializers is not an instance of ObjectInitializerInterface
*/
public function __construct($root, MetadataFactoryInterface $metadataFactory, ConstraintValidatorFactoryInterface $validatorFactory, TranslatorInterface $translator, $translationDomain = null, array $objectInitializers = array())
{
foreach ($objectInitializers as $initializer) {
if (!$initializer instanceof ObjectInitializerInterface) {
throw new UnexpectedTypeException($initializer, 'Symfony\Component\Validator\ObjectInitializerInterface');
}
}
$this->root = $root;
$this->metadataFactory = $metadataFactory;
$this->validatorFactory = $validatorFactory;
$this->translator = $translator;
$this->translationDomain = $translationDomain;
$this->objectInitializers = $objectInitializers;
$this->violations = new ConstraintViolationList();
}
/**
* {@inheritdoc}
*/
public function visit(MetadataInterface $metadata, $value, $group, $propertyPath)
{
$context = new ExecutionContext(
$this,
$this->translator,
$this->translationDomain,
$metadata,
$value,
$group,
$propertyPath
);
$context->validateValue($value, $metadata->findConstraints($group));
}
/**
* {@inheritdoc}
*/
public function validate($value, $group, $propertyPath, $traverse = false, $deep = false)
{
if (null === $value) {
return;
}
if (is_object($value)) {
$hash = spl_object_hash($value);
// Exit, if the object is already validated for the current group
if (isset($this->validatedObjects[$hash][$group])) {
return;
}
// Initialize if the object wasn't initialized before
if (!isset($this->validatedObjects[$hash])) {
foreach ($this->objectInitializers as $initializer) {
if (!$initializer instanceof ObjectInitializerInterface) {
throw new \LogicException('Validator initializers must implement ObjectInitializerInterface.');
}
$initializer->initialize($value);
}
}
// Remember validating this object before starting and possibly
// traversing the object graph
$this->validatedObjects[$hash][$group] = true;
}
// Validate arrays recursively by default, otherwise every driver needs
// to implement special handling for arrays.
// https://github.com/symfony/symfony/issues/6246
if (is_array($value) || ($traverse && $value instanceof \Traversable)) {
foreach ($value as $key => $element) {
// Ignore any scalar values in the collection
if (is_object($element) || is_array($element)) {
// Only repeat the traversal if $deep is set
$this->validate($element, $group, $propertyPath.'['.$key.']', $deep, $deep);
}
}
try {
$this->metadataFactory->getMetadataFor($value)->accept($this, $value, $group, $propertyPath);
} catch (NoSuchMetadataException $e) {
// Metadata doesn't necessarily have to exist for
// traversable objects, because we know how to validate
// them anyway. Optionally, additional metadata is supported.
}
} else {
$this->metadataFactory->getMetadataFor($value)->accept($this, $value, $group, $propertyPath);
}
}
/**
* {@inheritdoc}
*/
public function getViolations()
{
return $this->violations;
}
/**
* {@inheritdoc}
*/
public function getRoot()
{
return $this->root;
}
/**
* {@inheritdoc}
*/
public function getVisitor()
{
return $this;
}
/**
* {@inheritdoc}
*/
public function getValidatorFactory()
{
return $this->validatorFactory;
}
/**
* {@inheritdoc}
*/
public function getMetadataFactory()
{
return $this->metadataFactory;
}
}

View File

@ -1,82 +0,0 @@
<?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;
/**
* Validates values against constraints defined in {@link MetadataInterface}
* instances.
*
* This interface is an implementation of the Visitor design pattern. A value
* is validated by first passing it to the {@link validate} method. That method
* will determine the matching {@link MetadataInterface} for validating the
* value. It then calls the {@link MetadataInterface::accept} method of that
* metadata. <tt>accept()</tt> does two things:
*
* <ol>
* <li>It calls {@link visit} to validate the value against the constraints of
* the metadata.</li>
* <li>It calls <tt>accept()</tt> on all nested metadata instances with the
* corresponding values extracted from the current value. For example, if the
* current metadata represents a class and the current value is an object of
* that class, the metadata contains nested instances for each property of that
* class. It forwards the call to these nested metadata with the values of the
* corresponding properties in the original object.</li>
* </ol>
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
interface ValidationVisitorInterface
{
/**
* Validates a value.
*
* If the value is an array or a traversable object, you can set the
* parameter <tt>$traverse</tt> to <tt>true</tt> in order to run through
* the collection and validate each element. If these elements can be
* collections again and you want to traverse them recursively, set the
* parameter <tt>$deep</tt> to <tt>true</tt> as well.
*
* If you set <tt>$traversable</tt> to <tt>true</tt>, the visitor will
* nevertheless try to find metadata for the collection and validate its
* constraints. If no such metadata is found, the visitor ignores that and
* only iterates the collection.
*
* If you don't set <tt>$traversable</tt> to <tt>true</tt> and the visitor
* does not find metadata for the given value, it will fail with an
* exception.
*
* @param mixed $value The value to validate.
* @param string $group The validation group to validate.
* @param string $propertyPath The current property path in the validation graph.
* @param bool $traverse Whether to traverse the value if it is traversable.
* @param bool $deep Whether to traverse nested traversable values recursively.
*
* @throws Exception\NoSuchMetadataException If no metadata can be found for
* the given value.
*/
public function validate($value, $group, $propertyPath, $traverse = false, $deep = false);
/**
* Validates a value against the constraints defined in some metadata.
*
* This method implements the Visitor design pattern. See also
* {@link ValidationVisitorInterface}.
*
* @param MetadataInterface $metadata The metadata holding the constraints.
* @param mixed $value The value to validate.
* @param string $group The validation group to validate.
* @param string $propertyPath The current property path in the validation graph.
*/
public function visit(MetadataInterface $metadata, $value, $group, $propertyPath);
}

View File

@ -1,237 +0,0 @@
<?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;
@trigger_error('The '.__NAMESPACE__.'\Validator class is deprecated since version 2.5 and will be removed in 3.0. Use the Symfony\Component\Validator\Validator\RecursiveValidator class instead.', E_USER_DEPRECATED);
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\ValidatorException;
/**
* Default implementation of {@link ValidatorInterface}.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Validator\RecursiveValidator} instead.
*/
class Validator implements ValidatorInterface, Mapping\Factory\MetadataFactoryInterface
{
/**
* @var MetadataFactoryInterface
*/
private $metadataFactory;
/**
* @var ConstraintValidatorFactoryInterface
*/
private $validatorFactory;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var null|string
*/
private $translationDomain;
/**
* @var array
*/
private $objectInitializers;
public function __construct(
MetadataFactoryInterface $metadataFactory,
ConstraintValidatorFactoryInterface $validatorFactory,
TranslatorInterface $translator,
$translationDomain = 'validators',
array $objectInitializers = array()
) {
$this->metadataFactory = $metadataFactory;
$this->validatorFactory = $validatorFactory;
$this->translator = $translator;
$this->translationDomain = $translationDomain;
$this->objectInitializers = $objectInitializers;
}
/**
* {@inheritdoc}
*/
public function getMetadataFactory()
{
return $this->metadataFactory;
}
/**
* {@inheritdoc}
*/
public function getMetadataFor($value)
{
return $this->metadataFactory->getMetadataFor($value);
}
/**
* {@inheritdoc}
*/
public function hasMetadataFor($value)
{
return $this->metadataFactory->hasMetadataFor($value);
}
/**
* {@inheritdoc}
*/
public function validate($value, $groups = null, $traverse = false, $deep = false)
{
$visitor = $this->createVisitor($value);
foreach ($this->resolveGroups($groups) as $group) {
$visitor->validate($value, $group, '', $traverse, $deep);
}
return $visitor->getViolations();
}
/**
* {@inheritdoc}
*
* @throws ValidatorException If the metadata for the value does not support properties.
*/
public function validateProperty($containingValue, $property, $groups = null)
{
$visitor = $this->createVisitor($containingValue);
$metadata = $this->metadataFactory->getMetadataFor($containingValue);
if (!$metadata instanceof PropertyMetadataContainerInterface) {
$valueAsString = is_scalar($containingValue)
? '"'.$containingValue.'"'
: 'the value of type '.gettype($containingValue);
throw new ValidatorException(sprintf('The metadata for %s does not support properties.', $valueAsString));
}
foreach ($this->resolveGroups($groups) as $group) {
if (!$metadata->hasPropertyMetadata($property)) {
continue;
}
foreach ($metadata->getPropertyMetadata($property) as $propMeta) {
$propMeta->accept($visitor, $propMeta->getPropertyValue($containingValue), $group, $property);
}
}
return $visitor->getViolations();
}
/**
* {@inheritdoc}
*
* @throws ValidatorException If the metadata for the value does not support properties.
*/
public function validatePropertyValue($containingValue, $property, $value, $groups = null)
{
$visitor = $this->createVisitor(is_object($containingValue) ? $containingValue : $value);
$metadata = $this->metadataFactory->getMetadataFor($containingValue);
if (!$metadata instanceof PropertyMetadataContainerInterface) {
$valueAsString = is_scalar($containingValue)
? '"'.$containingValue.'"'
: 'the value of type '.gettype($containingValue);
throw new ValidatorException(sprintf('The metadata for '.$valueAsString.' does not support properties.'));
}
// If $containingValue is passed as class name, take $value as root
// and start the traversal with an empty property path
$propertyPath = is_object($containingValue) ? $property : '';
foreach ($this->resolveGroups($groups) as $group) {
if (!$metadata->hasPropertyMetadata($property)) {
continue;
}
foreach ($metadata->getPropertyMetadata($property) as $propMeta) {
$propMeta->accept($visitor, $value, $group, $propertyPath);
}
}
return $visitor->getViolations();
}
/**
* {@inheritdoc}
*/
public function validateValue($value, $constraints, $groups = null)
{
$context = new ExecutionContext($this->createVisitor($value), $this->translator, $this->translationDomain);
$constraints = is_array($constraints) ? $constraints : array($constraints);
foreach ($constraints as $constraint) {
if ($constraint instanceof Valid) {
// Why can't the Valid constraint be executed directly?
//
// It cannot be executed like regular other constraints, because regular
// constraints are only executed *if they belong to the validated group*.
// The Valid constraint, on the other hand, is always executed and propagates
// the group to the cascaded object. The propagated group depends on
//
// * Whether a group sequence is currently being executed. Then the default
// group is propagated.
//
// * Otherwise the validated group is propagated.
throw new ValidatorException(
sprintf(
'The constraint %s cannot be validated. Use the method validate() instead.',
get_class($constraint)
)
);
}
$context->validateValue($value, $constraint, '', $groups);
}
return $context->getViolations();
}
/**
* @param mixed $root
*
* @return ValidationVisitor
*/
private function createVisitor($root)
{
return new ValidationVisitor(
$root,
$this->metadataFactory,
$this->validatorFactory,
$this->translator,
$this->translationDomain,
$this->objectInitializers
);
}
/**
* @param null|string|string[] $groups
*
* @return string[]
*/
private function resolveGroups($groups)
{
return $groups ? (array) $groups : array(Constraint::DEFAULT_GROUP);
}
}

View File

@ -1,29 +0,0 @@
<?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\Validator;
@trigger_error('The '.__NAMESPACE__.'\LegacyValidator class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
/**
* A validator that supports both the API of Symfony < 2.5 and Symfony 2.5+.
*
* @since 2.5
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @see \Symfony\Component\Validator\ValidatorInterface
* @see \Symfony\Component\Validator\Validator\ValidatorInterface
* @deprecated since version 2.5, to be removed in 3.0.
*/
class LegacyValidator extends RecursiveValidator
{
}

View File

@ -26,7 +26,7 @@ use Symfony\Component\Validator\Mapping\GenericMetadata;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Mapping\TraversalStrategy;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\Validator\Util\PropertyPath;

View File

@ -17,9 +17,8 @@ use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
use Symfony\Component\Validator\Context\ExecutionContextFactoryInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Component\Validator\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
/**
* Recursive implementation of {@link ValidatorInterface}.
@ -28,7 +27,7 @@ use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
*
* @author Bernhard Schussek <bschussek@gmail.com>
*/
class RecursiveValidator implements ValidatorInterface, LegacyValidatorInterface
class RecursiveValidator implements ValidatorInterface
{
/**
* @var ExecutionContextFactoryInterface
@ -115,21 +114,8 @@ class RecursiveValidator implements ValidatorInterface, LegacyValidatorInterface
/**
* {@inheritdoc}
*/
public function validate($value, $groups = null, $traverse = false, $deep = false)
public function validate($value, $constraints = null, $groups = null)
{
$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;
} else {
@trigger_error('The Symfony\Component\Validator\ValidatorInterface::validate method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
$constraints = new Valid(array('traverse' => $traverse, 'deep' => $deep));
}
return $this->startContext($value)
->validate($value, $constraints, $groups)
->getViolations();
@ -156,26 +142,6 @@ class RecursiveValidator implements ValidatorInterface, LegacyValidatorInterface
->getViolations();
}
/**
* {@inheritdoc}
*/
public function validateValue($value, $constraints, $groups = null)
{
@trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::validate method instead.', E_USER_DEPRECATED);
return $this->validate($value, $constraints, $groups);
}
/**
* {@inheritdoc}
*/
public function getMetadataFactory()
{
@trigger_error('The '.__METHOD__.' method is deprecated in version 2.5 and will be removed in version 3.0. Use the Symfony\Component\Validator\Validator\ValidatorInterface::getMetadataFor or Symfony\Component\Validator\Validator\ValidatorInterface::hasMetadataFor method instead.', E_USER_DEPRECATED);
return $this->metadataFactory;
}
private static function testConstraints($constraints)
{
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && (0 === count($constraints) || current($constraints) instanceof Constraint));

View File

@ -23,6 +23,7 @@ use Symfony\Component\Validator\Exception\InvalidArgumentException;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
use Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Validator\Mapping\Loader\LoaderChain;
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
@ -292,41 +293,6 @@ class ValidatorBuilder implements ValidatorBuilderInterface
return $this;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.5, to be removed in 3.0.
* The validator will function without a property accessor.
*/
public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0. The validator will function without a property accessor.', E_USER_DEPRECATED);
if (null !== $this->validatorFactory) {
throw new ValidatorException('You cannot set a property accessor after setting a custom validator factory. Configure your validator factory instead.');
}
$this->propertyAccessor = $propertyAccessor;
return $this;
}
/**
* {@inheritdoc}
*
* @deprecated since version 2.7, to be removed in 3.0.
*/
public function setApiVersion($apiVersion)
{
@trigger_error('The '.__METHOD__.' method is deprecated in version 2.7 and will be removed in version 3.0.', E_USER_DEPRECATED);
if (!in_array($apiVersion, array(Validation::API_VERSION_2_4, Validation::API_VERSION_2_5, Validation::API_VERSION_2_5_BC))) {
throw new InvalidArgumentException(sprintf('The requested API version is invalid: "%s"', $apiVersion));
}
return $this;
}
/**
* {@inheritdoc}
*/

View File

@ -15,6 +15,7 @@ use Doctrine\Common\Annotations\Reader;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
/**
* A configurable builder for ValidatorInterface objects.
@ -160,30 +161,6 @@ interface ValidatorBuilderInterface
*/
public function setTranslationDomain($translationDomain);
/**
* Sets the property accessor for resolving property paths.
*
* @param PropertyAccessorInterface $propertyAccessor The property accessor
*
* @return ValidatorBuilderInterface The builder object
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function setPropertyAccessor(PropertyAccessorInterface $propertyAccessor);
/**
* Sets the API version that the returned validator should support.
*
* @param int $apiVersion The required API version
*
* @return ValidatorBuilderInterface The builder object
*
* @see Validation::API_VERSION_2_5
* @see Validation::API_VERSION_2_5_BC
* @deprecated since version 2.7, to be removed in 3.0.
*/
public function setApiVersion($apiVersion);
/**
* Builds and returns a new validator object.
*

View File

@ -1,103 +0,0 @@
<?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;
/**
* Validates values and graphs of objects and arrays.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link \Symfony\Component\Validator\Validator\ValidatorInterface} instead.
*/
interface ValidatorInterface
{
/**
* Validates a value.
*
* The accepted values depend on the {@link MetadataFactoryInterface}
* implementation.
*
* The signature changed with Symfony 2.5 (see
* {@link Validator\ValidatorInterface::validate()}. This signature will be
* disabled in Symfony 3.0.
*
* @param mixed $value The value to validate
* @param array|null $groups The validation groups to validate.
* @param bool $traverse Whether to traverse the value if it is traversable.
* @param bool $deep Whether to traverse nested traversable values recursively.
*
* @return ConstraintViolationListInterface A list of constraint violations. If the
* list is empty, validation succeeded.
*/
public function validate($value, $groups = null, $traverse = false, $deep = false);
/**
* Validates a property of a value against its current value.
*
* The accepted values depend on the {@link MetadataFactoryInterface}
* implementation.
*
* @param mixed $containingValue The value containing the property.
* @param string $property The name of the property to validate.
* @param array|null $groups The validation groups to validate.
*
* @return ConstraintViolationListInterface A list of constraint violations. If the
* list is empty, validation succeeded.
*/
public function validateProperty($containingValue, $property, $groups = null);
/**
* Validate a property of a value against a potential value.
*
* The accepted values depend on the {@link MetadataFactoryInterface}
* implementation.
*
* @param mixed $containingValue The value containing the property.
* @param string $property The name of the property to validate
* @param string $value The value to validate against the
* constraints of the property.
* @param array|null $groups The validation groups to validate.
*
* @return ConstraintViolationListInterface A list of constraint violations. If the
* list is empty, validation succeeded.
*/
public function validatePropertyValue($containingValue, $property, $value, $groups = null);
/**
* Validates a value against a constraint or a list of constraints.
*
* @param mixed $value The value to validate.
* @param Constraint|Constraint[] $constraints The constraint(s) to validate against.
* @param array|null $groups The validation groups to validate.
*
* @return ConstraintViolationListInterface A list of constraint violations. If the
* list is empty, validation succeeded.
*
* @deprecated since version 2.5, to be removed in 3.0.
* Renamed to {@link Validator\ValidatorInterface::validate()}
* in Symfony 2.5.
*/
public function validateValue($value, $constraints, $groups = null);
/**
* Returns the factory for metadata instances.
*
* @return MetadataFactoryInterface The metadata factory.
*
* @deprecated since version 2.5, to be removed in 3.0.
* Use {@link Validator\ValidatorInterface::getMetadataFor()} or
* {@link Validator\ValidatorInterface::hasMetadataFor()}
* instead.
*/
public function getMetadataFactory();
}

View File

@ -1,166 +0,0 @@
<?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\Violation;
@trigger_error('The '.__NAMESPACE__.'\LegacyConstraintViolationBuilder class is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
use Symfony\Component\Validator\ExecutionContextInterface;
/**
* Backwards-compatible implementation of {@link ConstraintViolationBuilderInterface}.
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* @internal You should not instantiate or use this class. Code against
* {@link ConstraintViolationBuilderInterface} instead.
*
* @deprecated since version 2.5.5, to be removed in 3.0.
*/
class LegacyConstraintViolationBuilder implements ConstraintViolationBuilderInterface
{
/**
* @var ExecutionContextInterface
*/
private $context;
/**
* @var string
*/
private $message;
/**
* @var array
*/
private $parameters;
/**
* @var mixed
*/
private $invalidValue;
/**
* @var string
*/
private $propertyPath;
/**
* @var int|null
*/
private $plural;
/**
* @var mixed
*/
private $code;
public function __construct(ExecutionContextInterface $context, $message, array $parameters)
{
$this->context = $context;
$this->message = $message;
$this->parameters = $parameters;
$this->invalidValue = $context->getValue();
}
/**
* {@inheritdoc}
*/
public function atPath($path)
{
$this->propertyPath = $path;
return $this;
}
/**
* {@inheritdoc}
*/
public function setParameter($key, $value)
{
$this->parameters[$key] = $value;
return $this;
}
/**
* {@inheritdoc}
*/
public function setParameters(array $parameters)
{
$this->parameters = $parameters;
return $this;
}
/**
* {@inheritdoc}
*/
public function setTranslationDomain($translationDomain)
{
// can't be set in the old API
return $this;
}
/**
* {@inheritdoc}
*/
public function setInvalidValue($invalidValue)
{
$this->invalidValue = $invalidValue;
return $this;
}
/**
* {@inheritdoc}
*/
public function setPlural($number)
{
$this->plural = $number;
return $this;
}
/**
* {@inheritdoc}
*/
public function setCode($code)
{
$this->code = $code;
return $this;
}
/**
* {@inheritdoc}
*/
public function setCause($cause)
{
// do nothing - we can't save the cause through the old API
return $this;
}
/**
* {@inheritdoc}
*/
public function addViolation()
{
if ($this->propertyPath) {
$this->context->addViolationAt($this->propertyPath, $this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
return;
}
$this->context->addViolation($this->message, $this->parameters, $this->invalidValue, $this->plural, $this->code);
}
}

View File

@ -25,7 +25,6 @@
"symfony/intl": "~2.8|~3.0",
"symfony/yaml": "~2.8|~3.0",
"symfony/config": "~2.8|~3.0",
"symfony/property-access": "~2.8|~3.0",
"symfony/expression-language": "~2.8|~3.0",
"doctrine/annotations": "~1.0",
"doctrine/cache": "~1.0",
@ -39,8 +38,7 @@
"symfony/yaml": "",
"symfony/config": "",
"egulias/email-validator": "Strict (RFC compliant) email validation",
"symfony/property-access": "For using the 2.4 Validator API",
"symfony/expression-language": "For using the 2.4 Expression validator"
"symfony/expression-language": "For using the Expression validator"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Validator\\": "" }