Skip to content

Commit

Permalink
[Validator] removed deprecated features in Constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Oct 1, 2015
1 parent 7bab317 commit 925ecaf
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 440 deletions.
16 changes: 1 addition & 15 deletions src/Symfony/Component/Validator/Constraints/Callback.php
Expand Up @@ -28,13 +28,6 @@ class Callback extends Constraint
*/
public $callback;

/**
* @var array
*
* @deprecated since version 2.4, to be removed in 3.0.
*/
public $methods;

/**
* {@inheritdoc}
*/
Expand All @@ -45,16 +38,9 @@ public function __construct($options = null)
$options = $options['value'];
}

if (is_array($options) && isset($options['methods'])) {
@trigger_error('The "methods" option of the '.__CLASS__.' class is deprecated since version 2.4 and will be removed in 3.0. Use the "callback" option instead.', E_USER_DEPRECATED);
}

if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) {
if (is_array($options) && !isset($options['callback']) && !isset($options['groups'])) {
if (is_callable($options) || !$options) {
$options = array('callback' => $options);
} else {
// @deprecated, to be removed in 3.0
$options = array('methods' => $options);
}
}

Expand Down
54 changes: 19 additions & 35 deletions src/Symfony/Component/Validator/Constraints/CallbackValidator.php
Expand Up @@ -32,45 +32,29 @@ public function validate($object, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback');
}

if (null !== $constraint->callback && null !== $constraint->methods) {
throw new ConstraintDefinitionException(
'The Callback constraint supports either the option "callback" '.
'or "methods", but not both at the same time.'
);
}

// has to be an array so that we can differentiate between callables
// and method names
if (null !== $constraint->methods && !is_array($constraint->methods)) {
throw new UnexpectedTypeException($constraint->methods, 'array');
}

$methods = $constraint->methods ?: array($constraint->callback);

foreach ($methods as $method) {
if ($method instanceof \Closure) {
$method($object, $this->context);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
$method = $constraint->callback;
if ($method instanceof \Closure) {
$method($object, $this->context);
} elseif (is_array($method)) {
if (!is_callable($method)) {
if (isset($method[0]) && is_object($method[0])) {
$method[0] = get_class($method[0]);
}
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
}

call_user_func($method, $object, $this->context);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
}
call_user_func($method, $object, $this->context);
} elseif (null !== $object) {
if (!method_exists($object, $method)) {
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
}

$reflMethod = new \ReflectionMethod($object, $method);
$reflMethod = new \ReflectionMethod($object, $method);

if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context);
} else {
$reflMethod->invoke($object, $this->context);
}
if ($reflMethod->isStatic()) {
$reflMethod->invoke(null, $object, $this->context);
} else {
$reflMethod->invoke($object, $this->context);
}
}
}
Expand Down

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions src/Symfony/Component/Validator/Constraints/False.php

This file was deleted.

23 changes: 0 additions & 23 deletions src/Symfony/Component/Validator/Constraints/FalseValidator.php

This file was deleted.

121 changes: 1 addition & 120 deletions src/Symfony/Component/Validator/Constraints/GroupSequence.php
Expand Up @@ -53,10 +53,8 @@
* @Target({"CLASS", "ANNOTATION"})
*
* @author Bernhard Schussek <bschussek@gmail.com>
*
* Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0.
*/
class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
class GroupSequence
{
/**
* The groups in the sequence.
Expand Down Expand Up @@ -91,121 +89,4 @@ public function __construct(array $groups)
// Support for Doctrine annotations
$this->groups = isset($groups['value']) ? $groups['value'] : $groups;
}

/**
* Returns an iterator for this group.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @return \Traversable The iterator
*
* @see \IteratorAggregate::getIterator()
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function getIterator()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

return new \ArrayIterator($this->groups);
}

/**
* Returns whether the given offset exists in the sequence.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @return bool Whether the offset exists
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function offsetExists($offset)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

return isset($this->groups[$offset]);
}

/**
* Returns the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @return string The group a the given offset
*
* @throws OutOfBoundsException If the object does not exist
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function offsetGet($offset)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

if (!isset($this->groups[$offset])) {
throw new OutOfBoundsException(sprintf(
'The offset "%s" does not exist.',
$offset
));
}

return $this->groups[$offset];
}

/**
* Sets the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
* @param string $value The group name
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function offsetSet($offset, $value)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

if (null !== $offset) {
$this->groups[$offset] = $value;

return;
}

$this->groups[] = $value;
}

/**
* Removes the group at the given offset.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @param int $offset The offset
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function offsetUnset($offset)
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

unset($this->groups[$offset]);
}

/**
* Returns the number of groups in the sequence.
*
* Implemented for backwards compatibility with Symfony < 2.5.
*
* @return int The number of groups
*
* @deprecated since version 2.5, to be removed in 3.0.
*/
public function count()
{
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);

return count($this->groups);
}
}
6 changes: 0 additions & 6 deletions src/Symfony/Component/Validator/Constraints/Iban.php
Expand Up @@ -23,21 +23,15 @@
*/
class Iban extends Constraint
{
/** @deprecated, to be removed in 3.0. */
const TOO_SHORT_ERROR = '88e5e319-0aeb-4979-a27e-3d9ce0c16166';
const INVALID_COUNTRY_CODE_ERROR = 'de78ee2c-bd50-44e2-aec8-3d8228aeadb9';
const INVALID_CHARACTERS_ERROR = '8d3d85e4-784f-4719-a5bc-d9e40d45a3a5';
/** @deprecated, to be removed in 3.0. */
const INVALID_CASE_ERROR = 'f4bf62fe-03ec-42af-a53b-68e21b1e7274';
const CHECKSUM_FAILED_ERROR = 'b9401321-f9bf-4dcb-83c1-f31094440795';
const INVALID_FORMAT_ERROR = 'c8d318f1-2ecc-41ba-b983-df70d225cf5a';
const NOT_SUPPORTED_COUNTRY_CODE_ERROR = 'e2c259f3-4b46-48e6-b72e-891658158ec8';

protected static $errorNames = array(
self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
self::INVALID_COUNTRY_CODE_ERROR => 'INVALID_COUNTRY_CODE_ERROR',
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
self::INVALID_CASE_ERROR => 'INVALID_CASE_ERROR',
self::CHECKSUM_FAILED_ERROR => 'CHECKSUM_FAILED_ERROR',
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
self::NOT_SUPPORTED_COUNTRY_CODE_ERROR => 'NOT_SUPPORTED_COUNTRY_CODE_ERROR',
Expand Down
14 changes: 0 additions & 14 deletions src/Symfony/Component/Validator/Constraints/Isbn.php
Expand Up @@ -43,20 +43,6 @@ class Isbn extends Constraint
public $type;
public $message;

/**
* @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead.
*
* @var bool
*/
public $isbn10 = false;

/**
* @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead.
*
* @var bool
*/
public $isbn13 = false;

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 925ecaf

Please sign in to comment.