8000 [Validator] removed deprecated features in Validator and Form by fabpot · Pull Request #16024 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] removed deprecated features in Validator and Form #16024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 1, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validator] removed deprecated methods
  • Loading branch information
fabpot committed Oct 1, 2015
commit 2a6b629e39a3069f67af94e991c7a1b672c7b983
30 changes: 0 additions & 30 deletions src/Symfony/Component/Validator/ClassBasedInterface.php

This file was deleted.

49 changes: 1 addition & 48 deletions src/Symfony/Component/Validator/ConstraintValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -50,51 +48,6 @@ public function initialize(ExecutionContextInterface $context)
$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 remove 10000 d 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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Validator;

use Symfony\Component\Validator\Context\ExecutionContextInterface;

/**
* @author Bernhard Schussek <bschussek@gmail.com>
*/
Expand Down
26 changes: 0 additions & 26 deletions src/Symfony/Component/Validator/ConstraintViolation.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,6 @@ public function getMessageTemplate()

/**
* {@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()
{
Expand All @@ -162,19 +149,6 @@ public function getParameters()

/**
* {@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()
{
Expand Down
10 changes: 3 additions & 7 deletions src/Symfony/Component/Validator/ConstraintViolationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getMessage();
* 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.
Expand All @@ -60,10 +60,8 @@ public function getMessageTemplate();
* 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.
Expand All @@ -80,10 +78,8 @@ public function getMessageParameters();
* 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.
Expand Down
2 changes: 0 additions & 2 deletions src/Symfony/Component/Validator/Constraints/GroupSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

namespace Symfony\Component\Validator\Constraints;

use Symfony\Component\Validator\Exception\OutOfBoundsException;

/**
* A sequence of validation groups.
*
Expand Down
9 changes: 0 additions & 9 deletions src/Symfony/Component/Validator/Constraints/Valid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -38,10 +33,6 @@ public function __construct($options = null)
));
}

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);
}
}
123 changes: 4 additions & 119 deletions src/Symfony/Component/Validator/Context/ExecutionContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -183,25 +182,8 @@ public function setConstraint(Constraint $constraint)
/**
* {@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,
Expand Down Expand Up @@ -294,7 +276,7 @@ public function getGroup()
*/
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;
}

/**
Expand All @@ -313,103 +295,6 @@ public function getPropertyPath($subPath = '')
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}
*/
Expand Down
Loading
0