Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 34a258e

Browse files
committed
[Validator] removed deprecated features in Constraints
1 parent ed610df commit 34a258e

17 files changed

+21
-440
lines changed

src/Symfony/Component/Validator/Constraints/Callback.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ class Callback extends Constraint
2828
*/
2929
public $callback;
3030

31-
/**
32-
* @var array
33-
*
34-
* @deprecated since version 2.4, to be removed in 3.0.
35-
*/
36-
public $methods;
37-
3831
/**
3932
* {@inheritdoc}
4033
*/
@@ -45,16 +38,9 @@ public function __construct($options = null)
4538
$options = $options['value'];
4639
}
4740

48-
if (is_array($options) && isset($options['methods'])) {
49-
@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);
50-
}
51-
52-
if (is_array($options) && !isset($options['callback']) && !isset($options['methods']) && !isset($options['groups'])) {
41+
if (is_array($options) && !isset($options['callback']) && !isset($options['groups'])) {
5342
if (is_callable($options) || !$options) {
5443
$options = array('callback' => $options);
55-
} else {
56-
// @deprecated, to be removed in 3.0
57-
$options = array('methods' => $options);
5844
}
5945
}
6046

src/Symfony/Component/Validator/Constraints/CallbackValidator.php

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,29 @@ public function validate($object, Constraint $constraint)
3232
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Callback');
3333
}
3434

35-
if (null !== $constraint->callback && null !== $constraint->methods) {
36-
throw new ConstraintDefinitionException(
37-
'The Callback constraint supports either the option "callback" '.
38-
'or "methods", but not both at the same time.'
39-
);
40-
}
41-
42-
// has to be an array so that we can differentiate between callables
43-
// and method names
44-
if (null !== $constraint->methods && !is_array($constraint->methods)) {
45-
throw new UnexpectedTypeException($constraint->methods, 'array');
46-
}
47-
48-
$methods = $constraint->methods ?: array($constraint->callback);
49-
50-
foreach ($methods as $method) {
51-
if ($method instanceof \Closure) {
52-
$method($object, $this->context);
53-
} elseif (is_array($method)) {
54-
if (!is_callable($method)) {
55-
if (isset($method[0]) && is_object($method[0])) {
56-
$method[0] = get_class($method[0]);
57-
}
58-
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
35+
$method = $constraint->callback;
36+
if ($method instanceof \Closure) {
37+
$method($object, $this->context);
38+
} elseif (is_array($method)) {
39+
if (!is_callable($method)) {
40+
if (isset($method[0]) && is_object($method[0])) {
41+
$method[0] = get_class($method[0]);
5942
}
43+
throw new ConstraintDefinitionException(sprintf('%s targeted by Callback constraint is not a valid callable', json_encode($method)));
44+
}
6045

61-
call_user_func($method, $object, $this->context);
62-
} elseif (null !== $object) {
63-
if (!method_exists($object, $method)) {
64-
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
65-
}
46+
call_user_func($method, $object, $this->context);
47+
} elseif (null !== $object) {
48+
if (!method_exists($object, $method)) {
49+
throw new ConstraintDefinitionException(sprintf('Method "%s" targeted by Callback constraint does not exist in class %s', $method, get_class($object)));
50+
}
6651

67-
$reflMethod = new \ReflectionMethod($object, $method);
52+
$reflMethod = new \ReflectionMethod($object, $method);
6853

69-
if ($reflMethod->isStatic()) {
70-
$reflMethod->invoke(null, $object, $this->context);
71-
} else {
72-
$reflMethod->invoke($object, $this->context);
73-
}
54+
if ($reflMethod->isStatic()) {
55+
$reflMethod->invoke(null, $object, $this->context);
56+
} else {
57+
$reflMethod->invoke($object, $this->context);
7458
}
7559
}
7660
}

src/Symfony/Component/Validator/Constraints/Collection/Optional.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/Collection/Required.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/False.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/FalseValidator.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/Symfony/Component/Validator/Constraints/GroupSequence.php

Lines changed: 1 addition & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@
5353
* @Target({"CLASS", "ANNOTATION"})
5454
*
5555
* @author Bernhard Schussek <[email protected]>
56-
*
57-
* Implementing \ArrayAccess, \IteratorAggregate and \Countable is @deprecated since 2.5 and will be removed in 3.0.
5856
*/
59-
class GroupSequence implements \ArrayAccess, \IteratorAggregate, \Countable
57+
class GroupSequence
6058
{
6159
/**
6260
* The groups in the sequence.
@@ -91,121 +89,4 @@ public function __construct(array $groups)
9189
// Support for Doctrine annotations
9290
$this->groups = isset($groups['value']) ? $groups['value'] : $groups;
9391
}
94-
95-
/**
96-
* Returns an iterator for this group.
97-
*
98-
* Implemented for backwards compatibility with Symfony < 2.5.
99-
*
100-
* @return \Traversable The iterator
101-
*
102-
* @see \IteratorAggregate::getIterator()
103-
* @deprecated since version 2.5, to be removed in 3.0.
104-
*/
105-
public function getIterator()
106-
{
107-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
108-
109-
return new \ArrayIterator($this->groups);
110-
}
111-
112-
/**
113-
* Returns whether the given offset exists in the sequence.
114-
*
115-
* Implemented for backwards compatibility with Symfony < 2.5.
116-
*
117-
* @param int $offset The offset
118-
*
119-
* @return bool Whether the offset exists
120-
*
121-
* @deprecated since version 2.5, to be removed in 3.0.
122-
*/
123-
public function offsetExists($offset)
124-
{
125-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
126-
127-
return isset($this->groups[$offset]);
128-
}
129-
130-
/**
131-
* Returns the group at the given offset.
132-
*
133-
* Implemented for backwards compatibility with Symfony < 2.5.
134-
*
135-
* @param int $offset The offset
136-
*
137-
* @return string The group a the given offset
138-
*
139-
* @throws OutOfBoundsException If the object does not exist
140-
*
141-
* @deprecated since version 2.5, to be removed in 3.0.
142-
*/
143-
public function offsetGet($offset)
144-
{
145-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
146-
147-
if (!isset($this->groups[$offset])) {
148-
throw new OutOfBoundsException(sprintf(
149-
'The offset "%s" does not exist.',
150-
$offset
151-
));
152-
}
153-
154-
return $this->groups[$offset];
155-
}
156-
157-
/**
158-
* Sets the group at the given offset.
159-
*
160-
* Implemented for backwards compatibility with Symfony < 2.5.
161-
*
162-
* @param int $offset The offset
163-
* @param string $value The group name
164-
*
165-
* @deprecated since version 2.5, to be removed in 3.0.
166-
*/
167-
public function offsetSet($offset, $value)
168-
{
169-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
170-
171-
if (null !== $offset) {
172-
$this->groups[$offset] = $value;
173-
174-
return;
175-
}
176-
177-
$this->groups[] = $value;
178-
}
179-
180-
/**
181-
* Removes the group at the given offset.
182-
*
183-
* Implemented for backwards compatibility with Symfony < 2.5.
184-
*
185-
* @param int $offset The offset
186-
*
187-
* @deprecated since version 2.5, to be removed in 3.0.
188-
*/
189-
public function offsetUnset($offset)
190-
{
191-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
192-
193-
unset($this->groups[$offset]);
194-
}
195-
196-
/**
197-
* Returns the number of groups in the sequence.
198-
*
199-
* Implemented for backwards compatibility with Symfony < 2.5.
200-
*
201-
* @return int The number of groups
202-
*
203-
* @deprecated since version 2.5, to be removed in 3.0.
204-
*/
205-
public function count()
206-
{
207-
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
208-
209-
return count($this->groups);
210-
}
21192
}

src/Symfony/Component/Validator/Constraints/Iban.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,15 @@
2323
*/
2424
class Iban extends Constraint
2525
{
26-
/** @deprecated, to be removed in 3.0. */
27-
const TOO_SHORT_ERROR = '88e5e319-0aeb-4979-a27e-3d9ce0c16166';
2826
const INVALID_COUNTRY_CODE_ERROR = 'de78ee2c-bd50-44e2-aec8-3d8228aeadb9';
2927
const INVALID_CHARACTERS_ERROR = '8d3d85e4-784f-4719-a5bc-d9e40d45a3a5';
30-
/** @deprecated, to be removed in 3.0. */
31-
const INVALID_CASE_ERROR = 'f4bf62fe-03ec-42af-a53b-68e21b1e7274';
3228
const CHECKSUM_FAILED_ERROR = 'b9401321-f9bf-4dcb-83c1-f31094440795';
3329
const INVALID_FORMAT_ERROR = 'c8d318f1-2ecc-41ba-b983-df70d225cf5a';
3430
const NOT_SUPPORTED_COUNTRY_CODE_ERROR = 'e2c259f3-4b46-48e6-b72e-891658158ec8';
3531

3632
protected static $errorNames = array(
37-
self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
3833
self::INVALID_COUNTRY_CODE_ERROR => 'INVALID_COUNTRY_CODE_ERROR',
3934
self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
40-
self::INVALID_CASE_ERROR => 'INVALID_CASE_ERROR',
4135
self::CHECKSUM_FAILED_ERROR => 'CHECKSUM_FAILED_ERROR',
4236
self::INVALID_FORMAT_ERROR => 'INVALID_FORMAT_ERROR',
4337
self::NOT_SUPPORTED_COUNTRY_CODE_ERROR => 'NOT_SUPPORTED_COUNTRY_CODE_ERROR',

src/Symfony/Component/Validator/Constraints/Isbn.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,6 @@ class Isbn extends Constraint
4343
public $type;
4444
public $message;
4545

46-
/**
47-
* @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead.
48-
*
49-
* @var bool
50-
*/
51-
public $isbn10 = false;
52-
53-
/**
54-
* @deprecated since version 2.5, to be removed in 3.0. Use option "type" instead.
55-
*
56-
* @var bool
57-
*/
58-
public $isbn13 = false;
59-
6046
/**
6147
* {@inheritdoc}
6248
*/

0 commit comments

Comments
 (0)