Skip to content

Commit 0946dbe

Browse files
committed
[Validator] Adapted CHANGELOG
1 parent 1b111d0 commit 0946dbe

11 files changed

+316
-195
lines changed

src/Symfony/Component/Validator/CHANGELOG.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,57 @@ CHANGELOG
77
* deprecated `ApcCache` in favor of `DoctrineCache`
88
* added `DoctrineCache` to adapt any Doctrine cache
99
* `GroupSequence` now implements `ArrayAccess`, `Countable` and `Traversable`
10-
* changed `ClassMetadata::getGroupSequence()` to return a `GroupSequence` instance instead of an array
10+
* [BC BREAK] changed `ClassMetadata::getGroupSequence()` to return a `GroupSequence` instance instead of an array
1111
* `Callback` can now be put onto properties (useful when you pass a closure to the constraint)
12+
* deprecated `ClassBasedInterface`
13+
* deprecated `MetadataInterface`
14+
* deprecated `PropertyMetadataInterface`
15+
* deprecated `PropertyMetadataContainerInterface`
16+
* deprecated `Mapping\ElementMetadata`
17+
* added `Mapping\MetadataInterface`
18+
* added `Mapping\ClassMetadataInterface`
19+
* added `Mapping\PropertyMetadataInterface`
20+
* added `Mapping\GenericMetadata`
21+
* added `Mapping\CascadingStrategy`
22+
* added `Mapping\TraversalStrategy`
23+
* deprecated `Mapping\ClassMetadata::accept()`
24+
* deprecated `Mapping\MemberMetadata::accept()`
25+
* removed array type hint of `Mapping\ClassMetadata::setGroupSequence()`
26+
* deprecated `MetadataFactoryInterface`
27+
* deprecated `Mapping\BlackholeMetadataFactory`
28+
* deprecated `Mapping\ClassMetadataFactory`
29+
* added `Mapping\Factory\MetadataFactoryInterface`
30+
* added `Mapping\Factory\BlackHoleMetadataFactory`
31+
* added `Mapping\Factory\LazyMetadataFactory`
32+
* deprecated `ExecutionContextInterface`
33+
* deprecated `ExecutionContext`
34+
* deprecated `GlobalExecutionContextInterface`
35+
* added `Context\ExecutionContextInterface`
36+
* added `Context\ExecutionContext`
37+
* added `Context\ExecutionContextFactoryInterface`
38+
* added `Context\ExecutionContextFactory`
39+
* deprecated `ValidatorInterface`
40+
* deprecated `Validator`
41+
* deprecated `ValidationVisitorInterface`
42+
* deprecated `ValidationVisitor`
43+
* added `Validator\ValidatorInterface`
44+
* added `Validator\RecursiveValidator`
45+
* added `Validator\ContextualValidatorInterface`
46+
* added `Validator\RecursiveContextualValidator`
47+
* added `Violation\ConstraintViolationBuilderInterface`
48+
* added `Violation\ConstraintViolationBuilder`
49+
* added `ConstraintViolation::getParameters()`
50+
* added `ConstraintViolation::getPlural()`
51+
* added `Constraints\Traverse`
52+
* deprecated `$deep` property in `Constraints\Valid`
53+
* added `ValidatorBuilderInterface::setApiVersion()`
54+
* added `Validation::API_VERSION_2_4`
55+
* added `Validation::API_VERSION_2_5`
56+
* added `Exception\OutOfBoundsException`
57+
* added `Exception\UnsupportedMetadataException`
58+
* made `Exception\ValidatorException` extend `Exception\RuntimeException`
59+
* added `Util\PropertyPath`
60+
1261

1362
2.4.0
1463
-----

src/Symfony/Component/Validator/Context/ExecutionContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function setGroup($group)
158158
/**
159159
* {@inheritdoc}
160160
*/
161-
public function addViolation($message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
161+
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
162162
{
163163
// The parameters $invalidValue and following are ignored by the new
164164
// API, as they are not present in the new interface anymore.
@@ -275,7 +275,7 @@ public function getPropertyPath($subPath = '')
275275
/**
276276
* {@inheritdoc}
277277
*/
278-
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
278+
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
279279
{
280280
throw new BadMethodCallException(
281281
'addViolationAt() is not supported anymore as of Symfony 2.5. '.

src/Symfony/Component/Validator/ExecutionContext.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,13 @@ public function __construct(GlobalExecutionContextInterface $globalContext, Tran
9090
/**
9191
* {@inheritdoc}
9292
*/
93-
public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
93+
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
9494
{
95-
if (null === $pluralization) {
95+
if (null === $plural) {
9696
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
9797
} else {
9898
try {
99-
$translatedMessage = $this->translator->transChoice($message, $pluralization, $params, $this->translationDomain);
99+
$translatedMessage = $this->translator->transChoice($message, $plural, $params, $this->translationDomain);
100100
} catch (\InvalidArgumentException $e) {
101101
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
102102
}
@@ -110,27 +110,27 @@ public function addViolation($message, array $params = array(), $invalidValue =
110110
$this->propertyPath,
111111
// check using func_num_args() to allow passing null values
112112
func_num_args() >= 3 ? $invalidValue : $this->value,
113-
$pluralization,
113+
$plural,
114114
$code
115115
));
116116
}
117117

118118
/**
119119
* {@inheritdoc}
120120
*/
121-
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
121+
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
122122
{
123123
$this->globalContext->getViolations()->add(new ConstraintViolation(
124-
null === $pluralization
124+
null === $plural
125125
? $this->translator->trans($message, $parameters, $this->translationDomain)
126-
: $this->translator->transChoice($message, $pluralization, $parameters, $this->translationDomain),
126+
: $this->translator->transChoice($message, $plural, $parameters, $this->translationDomain),
127127
$message,
128128
$parameters,
129129
$this->globalContext->getRoot(),
130130
$this->getPropertyPath($subPath),
131131
// check using func_num_args() to allow passing null values
132132
func_num_args() >= 4 ? $invalidValue : $this->value,
133-
$pluralization,
133+
$plural,
134134
$code
135135
));
136136
}

src/Symfony/Component/Validator/ExecutionContextInterface.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,38 +91,38 @@ interface ExecutionContextInterface
9191
/**
9292
* Adds a violation at the current node of the validation graph.
9393
*
94-
* @param string $message The error message.
95-
* @param array $params The parameters substituted in the error message.
96-
* @param mixed $invalidValue The invalid, validated value.
97-
* @param integer|null $pluralization The number to use to pluralize of the message.
98-
* @param integer|null $code The violation code.
94+
* @param string $message The error message
95+
* @param array $params The parameters substituted in the error message
96+
* @param mixed $invalidValue The invalid, validated value
97+
* @param integer|null $plural The number to use to pluralize of the message
98+
* @param integer|null $code The violation code
9999
*
100100
* @api
101101
*
102102
* @deprecated The parameters $invalidValue, $pluralization and $code are
103103
* deprecated since version 2.5 and will be removed in
104104
* Symfony 3.0.
105105
*/
106-
public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null);
106+
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null);
107107

108108
/**
109109
* Adds a violation at the validation graph node with the given property
110110
* path relative to the current property path.
111111
*
112-
* @param string $subPath The relative property path for the violation.
113-
* @param string $message The error message.
114-
* @param array $parameters The parameters substituted in the error message.
115-
* @param mixed $invalidValue The invalid, validated value.
116-
* @param integer|null $pluralization The number to use to pluralize of the message.
117-
* @param integer|null $code The violation code.
112+
* @param string $subPath The relative property path for the violation
113+
* @param string $message The error message
114+
* @param array $parameters The parameters substituted in the error message
115+
* @param mixed $invalidValue The invalid, validated value
116+
* @param integer|null $plural The number to use to pluralize of the message
117+
* @param integer|null $code The violation code
118118
*
119119
* @api
120120
*
121121
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
122122
* Use {@link Context\ExecutionContextInterface::buildViolation()}
123123
* instead.
124124
*/
125-
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null);
125+
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null);
126126

127127
/**
128128
* Validates the given value within the scope of the current validation.

src/Symfony/Component/Validator/Mapping/BlackholeMetadataFactory.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,14 @@
1111

1212
namespace Symfony\Component\Validator\Mapping;
1313

14-
use Symfony\Component\Validator\MetadataFactoryInterface;
15-
1614
/**
17-
* Metadata factory that does not store metadata.
18-
*
19-
* This implementation is useful if you want to validate values against
20-
* constraints only and you don't need to add constraints to classes and
21-
* properties.
15+
* Alias of {@link Factory\BlackHoleMetadataFactory}.
2216
*
2317
* @author Fabien Potencier <[email protected]>
18+
*
19+
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
20+
* Use {@link Factory\BlackHoleMetadataFactory} instead.
2421
*/
25-
class BlackholeMetadataFactory implements MetadataFactoryInterface
22+
class BlackholeMetadataFactory extends \Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory
2623
{
27-
/**
28-
* {@inheritdoc}
29-
*/
30-
public function getMetadataFor($value)
31-
{
32-
throw new \LogicException('This class does not support metadata.');
33-
}
34-
35-
/**
36-
* {@inheritdoc}
37-
*/
38-
public function hasMetadataFor($value)
39-
{
40-
return false;
41-
}
4224
}

src/Symfony/Component/Validator/Mapping/ClassMetadataFactory.php

Lines changed: 6 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -11,154 +11,16 @@
1111

1212
namespace Symfony\Component\Validator\Mapping;
1313

14-
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
15-
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
16-
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
17-
use Symfony\Component\Validator\MetadataFactoryInterface;
14+
use Symfony\Component\Validator\Mapping\Factory\LazyMetadataFactory;
1815

1916
/**
20-
* Creates new {@link ClassMetadataInterface} instances.
21-
*
22-
* Whenever {@link getMetadataFor()} is called for the first time with a given
23-
* class name or object of that class, a new metadata instance is created and
24-
* returned. On subsequent requests for the same class, the same metadata
25-
* instance will be returned.
26-
*
27-
* You can optionally pass a {@link LoaderInterface} instance to the constructor.
28-
* Whenever a new metadata instance is created, it is passed to the loader,
29-
* which can configure the metadata based on configuration loaded from the
30-
* filesystem or a database. If you want to use multiple loaders, wrap them in a
31-
* {@link Loader\LoaderChain}.
32-
*
33-
* You can also optionally pass a {@link CacheInterface} instance to the
34-
* constructor. This cache will be used for persisting the generated metadata
35-
* between multiple PHP requests.
17+
* Alias of {@link LazyMetadataFactory}.
3618
*
3719
* @author Bernhard Schussek <[email protected]>
20+
*
21+
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
22+
* Use {@link LazyMetadataFactory} instead.
3823
*/
39-
class ClassMetadataFactory implements MetadataFactoryInterface
24+
class ClassMetadataFactory extends LazyMetadataFactory
4025
{
41-
/**
42-
* The loader for loading the class metadata
43-
*
44-
* @var LoaderInterface
45-
*/
46-
protected $loader;
47-
48-
/**
49-
* The cache for caching class metadata
50-
*
51-
* @var CacheInterface
52-
*/
53-
protected $cache;
54-
55-
/**
56-
* The loaded metadata, indexed by class name
57-
*
58-
* @var ClassMetadata[]
59-
*/
60-
protected $loadedClasses = array();
61-
62-
/**
63-
* Creates a new metadata factory.
64-
*
65-
* @param LoaderInterface|null $loader The loader for configuring new metadata
66-
* @param CacheInterface|null $cache The cache for persisting metadata
67-
* between multiple PHP requests
68-
*/
69-
public function __construct(LoaderInterface $loader = null, CacheInterface $cache = null)
70-
{
71-
$this->loader = $loader;
72-
$this->cache = $cache;
73-
}
74-
75-
/**
76-
* Returns the metadata for the given class name or object.
77-
*
78-
* If the method was called with the same class name (or an object of that
79-
* class) before, the same metadata instance is returned.
80-
*
81-
* If the factory was configured with a cache, this method will first look
82-
* for an existing metadata instance in the cache. If an existing instance
83-
* is found, it will be returned without further ado.
84-
*
85-
* Otherwise, a new metadata instance is created. If the factory was
86-
* configured with a loader, the metadata is passed to the
87-
* {@link LoaderInterface::loadClassMetadata()} method for further
88-
* configuration. At last, the new object is returned.
89-
*
90-
* @param string|object $value A class name or an object
91-
*
92-
* @return MetadataInterface The metadata for the value
93-
*
94-
* @throws NoSuchMetadataException If no metadata exists for the given value
95-
*/
96-
public function getMetadataFor($value)
97-
{
98-
if (!is_object($value) && !is_string($value)) {
99-
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
100-
}
101-
102-
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
103-
104-
if (isset($this->loadedClasses[$class])) {
105-
return $this->loadedClasses[$class];
106-
}
107-
108-
if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
109-
return $this->loadedClasses[$class];
110-
}
111-
112-
if (!class_exists($class) && !interface_exists($class)) {
113-
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
114-
}
115-
116-
$metadata = new ClassMetadata($class);
117-
118-
// Include constraints from the parent class
119-
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
120-
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
121-
}
122-
123-
// Include constraints from all implemented interfaces
124-
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
125-
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
126-
continue;
127-
}
128-
$metadata->mergeConstraints($this->getMetadataFor($interface->name));
129-
}
130-
131-
if (null !== $this->loader) {
132-
$this->loader->loadClassMetadata($metadata);
133-
}
134-
135-
if (null !== $this->cache) {
136-
$this->cache->write($metadata);
137-
}
138-
139-
return $this->loadedClasses[$class] = $metadata;
140-
}
141-
142-
/**
143-
* Returns whether the factory is able to return metadata for the given
144-
* class name or object.
145-
*
146-
* @param string|object $value A class name or an object
147-
*
148-
* @return Boolean Whether metadata can be returned for that class
149-
*/
150-
public function hasMetadataFor($value)
151-
{
152-
if (!is_object($value) && !is_string($value)) {
153-
return false;
154-
}
155-
156-
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
157-
158-
if (class_exists($class) || interface_exists($class)) {
159-
return true;
160-
}
161-
162-
return false;
163-
}
16426
}

0 commit comments

Comments
 (0)