[Validator] Adapted CHANGELOG
This commit is contained in:
parent
1b111d0e83
commit
0946dbe7a0
|
@ -7,8 +7,57 @@ CHANGELOG
|
|||
* deprecated `ApcCache` in favor of `DoctrineCache`
|
||||
* added `DoctrineCache` to adapt any Doctrine cache
|
||||
* `GroupSequence` now implements `ArrayAccess`, `Countable` and `Traversable`
|
||||
* changed `ClassMetadata::getGroupSequence()` to return a `GroupSequence` instance instead of an array
|
||||
* [BC BREAK] changed `ClassMetadata::getGroupSequence()` to return a `GroupSequence` instance instead of an array
|
||||
* `Callback` can now be put onto properties (useful when you pass a closure to the constraint)
|
||||
* deprecated `ClassBasedInterface`
|
||||
* deprecated `MetadataInterface`
|
||||
* deprecated `PropertyMetadataInterface`
|
||||
* deprecated `PropertyMetadataContainerInterface`
|
||||
* deprecated `Mapping\ElementMetadata`
|
||||
* added `Mapping\MetadataInterface`
|
||||
* added `Mapping\ClassMetadataInterface`
|
||||
* added `Mapping\PropertyMetadataInterface`
|
||||
* added `Mapping\GenericMetadata`
|
||||
* added `Mapping\CascadingStrategy`
|
||||
* added `Mapping\TraversalStrategy`
|
||||
* deprecated `Mapping\ClassMetadata::accept()`
|
||||
* deprecated `Mapping\MemberMetadata::accept()`
|
||||
* removed array type hint of `Mapping\ClassMetadata::setGroupSequence()`
|
||||
* deprecated `MetadataFactoryInterface`
|
||||
* deprecated `Mapping\BlackholeMetadataFactory`
|
||||
* deprecated `Mapping\ClassMetadataFactory`
|
||||
* added `Mapping\Factory\MetadataFactoryInterface`
|
||||
* added `Mapping\Factory\BlackHoleMetadataFactory`
|
||||
* added `Mapping\Factory\LazyMetadataFactory`
|
||||
* deprecated `ExecutionContextInterface`
|
||||
* deprecated `ExecutionContext`
|
||||
* deprecated `GlobalExecutionContextInterface`
|
||||
* added `Context\ExecutionContextInterface`
|
||||
* added `Context\ExecutionContext`
|
||||
* added `Context\ExecutionContextFactoryInterface`
|
||||
* added `Context\ExecutionContextFactory`
|
||||
* deprecated `ValidatorInterface`
|
||||
* deprecated `Validator`
|
||||
* deprecated `ValidationVisitorInterface`
|
||||
* deprecated `ValidationVisitor`
|
||||
* added `Validator\ValidatorInterface`
|
||||
* added `Validator\RecursiveValidator`
|
||||
* added `Validator\ContextualValidatorInterface`
|
||||
* added `Validator\RecursiveContextualValidator`
|
||||
* added `Violation\ConstraintViolationBuilderInterface`
|
||||
* added `Violation\ConstraintViolationBuilder`
|
||||
* added `ConstraintViolation::getParameters()`
|
||||
* added `ConstraintViolation::getPlural()`
|
||||
* added `Constraints\Traverse`
|
||||
* deprecated `$deep` property in `Constraints\Valid`
|
||||
* added `ValidatorBuilderInterface::setApiVersion()`
|
||||
* added `Validation::API_VERSION_2_4`
|
||||
* added `Validation::API_VERSION_2_5`
|
||||
* added `Exception\OutOfBoundsException`
|
||||
* added `Exception\UnsupportedMetadataException`
|
||||
* made `Exception\ValidatorException` extend `Exception\RuntimeException`
|
||||
* added `Util\PropertyPath`
|
||||
|
||||
|
||||
2.4.0
|
||||
-----
|
||||
|
|
|
@ -158,7 +158,7 @@ class ExecutionContext implements ExecutionContextInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addViolation($message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
|
||||
public function addViolation($message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
|
||||
{
|
||||
// The parameters $invalidValue and following are ignored by the new
|
||||
// API, as they are not present in the new interface anymore.
|
||||
|
@ -275,7 +275,7 @@ class ExecutionContext implements ExecutionContextInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
|
||||
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
|
||||
{
|
||||
throw new BadMethodCallException(
|
||||
'addViolationAt() is not supported anymore as of Symfony 2.5. '.
|
||||
|
|
|
@ -90,13 +90,13 @@ class ExecutionContext implements ExecutionContextInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null)
|
||||
public function addViolation($message, array $params = array(), $invalidValue = null, $plural = null, $code = null)
|
||||
{
|
||||
if (null === $pluralization) {
|
||||
if (null === $plural) {
|
||||
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
|
||||
} else {
|
||||
try {
|
||||
$translatedMessage = $this->translator->transChoice($message, $pluralization, $params, $this->translationDomain);
|
||||
$translatedMessage = $this->translator->transChoice($message, $plural, $params, $this->translationDomain);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
$translatedMessage = $this->translator->trans($message, $params, $this->translationDomain);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ class ExecutionContext implements ExecutionContextInterface
|
|||
$this->propertyPath,
|
||||
// check using func_num_args() to allow passing null values
|
||||
func_num_args() >= 3 ? $invalidValue : $this->value,
|
||||
$pluralization,
|
||||
$plural,
|
||||
$code
|
||||
));
|
||||
}
|
||||
|
@ -118,19 +118,19 @@ class ExecutionContext implements ExecutionContextInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null)
|
||||
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $plural = null, $code = null)
|
||||
{
|
||||
$this->globalContext->getViolations()->add(new ConstraintViolation(
|
||||
null === $pluralization
|
||||
null === $plural
|
||||
? $this->translator->trans($message, $parameters, $this->translationDomain)
|
||||
: $this->translator->transChoice($message, $pluralization, $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,
|
||||
$pluralization,
|
||||
$plural,
|
||||
$code
|
||||
));
|
||||
}
|
||||
|
|
|
@ -91,11 +91,11 @@ 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.
|
||||
* @param mixed $invalidValue The invalid, validated value.
|
||||
* @param integer|null $pluralization The number to use to pluralize of the message.
|
||||
* @param integer|null $code The violation code.
|
||||
* @param string $message The error message
|
||||
* @param array $params The parameters substituted in the error message
|
||||
* @param mixed $invalidValue The invalid, validated value
|
||||
* @param integer|null $plural The number to use to pluralize of the message
|
||||
* @param integer|null $code The violation code
|
||||
*
|
||||
* @api
|
||||
*
|
||||
|
@ -103,18 +103,18 @@ interface ExecutionContextInterface
|
|||
* deprecated since version 2.5 and will be removed in
|
||||
* Symfony 3.0.
|
||||
*/
|
||||
public function addViolation($message, array $params = array(), $invalidValue = null, $pluralization = null, $code = null);
|
||||
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 integer|null $pluralization The number to use to pluralize of the message.
|
||||
* @param integer|null $code The violation code.
|
||||
* @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 integer|null $plural The number to use to pluralize of the message
|
||||
* @param integer|null $code The violation code
|
||||
*
|
||||
* @api
|
||||
*
|
||||
|
@ -122,7 +122,7 @@ interface ExecutionContextInterface
|
|||
* Use {@link Context\ExecutionContextInterface::buildViolation()}
|
||||
* instead.
|
||||
*/
|
||||
public function addViolationAt($subPath, $message, array $parameters = array(), $invalidValue = null, $pluralization = null, $code = null);
|
||||
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.
|
||||
|
|
|
@ -11,32 +11,14 @@
|
|||
|
||||
namespace Symfony\Component\Validator\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\MetadataFactoryInterface;
|
||||
|
||||
/**
|
||||
* Metadata factory that does not store metadata.
|
||||
*
|
||||
* This implementation is useful if you want to validate values against
|
||||
* constraints only and you don't need to add constraints to classes and
|
||||
* properties.
|
||||
* Alias of {@link Factory\BlackHoleMetadataFactory}.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Factory\BlackHoleMetadataFactory} instead.
|
||||
*/
|
||||
class BlackholeMetadataFactory implements MetadataFactoryInterface
|
||||
class BlackholeMetadataFactory extends \Symfony\Component\Validator\Mapping\Factory\BlackHoleMetadataFactory
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
throw new \LogicException('This class does not support metadata.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,154 +11,16 @@
|
|||
|
||||
namespace Symfony\Component\Validator\Mapping;
|
||||
|
||||
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
|
||||
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
use Symfony\Component\Validator\MetadataFactoryInterface;
|
||||
use Symfony\Component\Validator\Mapping\Factory\LazyMetadataFactory;
|
||||
|
||||
/**
|
||||
* Creates new {@link ClassMetadataInterface} instances.
|
||||
*
|
||||
* Whenever {@link getMetadataFor()} is called for the first time with a given
|
||||
* class name or object of that class, a new metadata instance is created and
|
||||
* returned. On subsequent requests for the same class, the same metadata
|
||||
* instance will be returned.
|
||||
*
|
||||
* You can optionally pass a {@link LoaderInterface} instance to the constructor.
|
||||
* Whenever a new metadata instance is created, it is passed to the loader,
|
||||
* which can configure the metadata based on configuration loaded from the
|
||||
* filesystem or a database. If you want to use multiple loaders, wrap them in a
|
||||
* {@link Loader\LoaderChain}.
|
||||
*
|
||||
* You can also optionally pass a {@link CacheInterface} instance to the
|
||||
* constructor. This cache will be used for persisting the generated metadata
|
||||
* between multiple PHP requests.
|
||||
* Alias of {@link LazyMetadataFactory}.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link LazyMetadataFactory} instead.
|
||||
*/
|
||||
class ClassMetadataFactory implements MetadataFactoryInterface
|
||||
class ClassMetadataFactory extends LazyMetadataFactory
|
||||
{
|
||||
/**
|
||||
* The loader for loading the class metadata
|
||||
*
|
||||
* @var LoaderInterface
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The cache for caching class metadata
|
||||
*
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The loaded metadata, indexed by class name
|
||||
*
|
||||
* @var ClassMetadata[]
|
||||
*/
|
||||
protected $loadedClasses = array();
|
||||
|
||||
/**
|
||||
* Creates a new metadata factory.
|
||||
*
|
||||
* @param LoaderInterface|null $loader The loader for configuring new metadata
|
||||
* @param CacheInterface|null $cache The cache for persisting metadata
|
||||
* between multiple PHP requests
|
||||
*/
|
||||
public function __construct(LoaderInterface $loader = null, CacheInterface $cache = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata for the given class name or object.
|
||||
*
|
||||
* If the method was called with the same class name (or an object of that
|
||||
* class) before, the same metadata instance is returned.
|
||||
*
|
||||
* If the factory was configured with a cache, this method will first look
|
||||
* for an existing metadata instance in the cache. If an existing instance
|
||||
* is found, it will be returned without further ado.
|
||||
*
|
||||
* Otherwise, a new metadata instance is created. If the factory was
|
||||
* configured with a loader, the metadata is passed to the
|
||||
* {@link LoaderInterface::loadClassMetadata()} method for further
|
||||
* configuration. At last, the new object is returned.
|
||||
*
|
||||
* @param string|object $value A class name or an object
|
||||
*
|
||||
* @return MetadataInterface The metadata for the value
|
||||
*
|
||||
* @throws NoSuchMetadataException If no metadata exists for the given value
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
if (!is_object($value) && !is_string($value)) {
|
||||
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
|
||||
}
|
||||
|
||||
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
||||
|
||||
if (isset($this->loadedClasses[$class])) {
|
||||
return $this->loadedClasses[$class];
|
||||
}
|
||||
|
||||
if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
|
||||
return $this->loadedClasses[$class];
|
||||
}
|
||||
|
||||
if (!class_exists($class) && !interface_exists($class)) {
|
||||
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$metadata = new ClassMetadata($class);
|
||||
|
||||
// Include constraints from the parent class
|
||||
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
|
||||
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
|
||||
}
|
||||
|
||||
// Include constraints from all implemented interfaces
|
||||
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
|
||||
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
|
||||
continue;
|
||||
}
|
||||
$metadata->mergeConstraints($this->getMetadataFor($interface->name));
|
||||
}
|
||||
|
||||
if (null !== $this->loader) {
|
||||
$this->loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
if (null !== $this->cache) {
|
||||
$this->cache->write($metadata);
|
||||
}
|
||||
|
||||
return $this->loadedClasses[$class] = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the factory is able to return metadata for the given
|
||||
* class name or object.
|
||||
*
|
||||
* @param string|object $value A class name or an object
|
||||
*
|
||||
* @return Boolean Whether metadata can be returned for that class
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
if (!is_object($value) && !is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
||||
|
||||
if (class_exists($class) || interface_exists($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
<?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\Factory;
|
||||
|
||||
/**
|
||||
* Metadata factory that does not store metadata.
|
||||
*
|
||||
* This implementation is useful if you want to validate values against
|
||||
* constraints only and you don't need to add constraints to classes and
|
||||
* properties.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class BlackHoleMetadataFactory implements MetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
throw new \LogicException('This class does not support metadata.');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,165 @@
|
|||
<?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\Factory;
|
||||
|
||||
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
|
||||
use Symfony\Component\Validator\Mapping\Cache\CacheInterface;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
use Symfony\Component\Validator\Mapping\MetadataInterface;
|
||||
|
||||
/**
|
||||
* Creates new {@link ClassMetadataInterface} instances.
|
||||
*
|
||||
* Whenever {@link getMetadataFor()} is called for the first time with a given
|
||||
* class name or object of that class, a new metadata instance is created and
|
||||
* returned. On subsequent requests for the same class, the same metadata
|
||||
* instance will be returned.
|
||||
*
|
||||
* You can optionally pass a {@link LoaderInterface} instance to the constructor.
|
||||
* Whenever a new metadata instance is created, it is passed to the loader,
|
||||
* which can configure the metadata based on configuration loaded from the
|
||||
* filesystem or a database. If you want to use multiple loaders, wrap them in a
|
||||
* {@link Loader\LoaderChain}.
|
||||
*
|
||||
* You can also optionally pass a {@link CacheInterface} instance to the
|
||||
* constructor. This cache will be used for persisting the generated metadata
|
||||
* between multiple PHP requests.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LazyMetadataFactory implements MetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* The loader for loading the class metadata
|
||||
*
|
||||
* @var LoaderInterface
|
||||
*/
|
||||
protected $loader;
|
||||
|
||||
/**
|
||||
* The cache for caching class metadata
|
||||
*
|
||||
* @var CacheInterface
|
||||
*/
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The loaded metadata, indexed by class name
|
||||
*
|
||||
* @var ClassMetadata[]
|
||||
*/
|
||||
protected $loadedClasses = array();
|
||||
|
||||
/**
|
||||
* Creates a new metadata factory.
|
||||
*
|
||||
* @param LoaderInterface|null $loader The loader for configuring new metadata
|
||||
* @param CacheInterface|null $cache The cache for persisting metadata
|
||||
* between multiple PHP requests
|
||||
*/
|
||||
public function __construct(LoaderInterface $loader = null, CacheInterface $cache = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata for the given class name or object.
|
||||
*
|
||||
* If the method was called with the same class name (or an object of that
|
||||
* class) before, the same metadata instance is returned.
|
||||
*
|
||||
* If the factory was configured with a cache, this method will first look
|
||||
* for an existing metadata instance in the cache. If an existing instance
|
||||
* is found, it will be returned without further ado.
|
||||
*
|
||||
* Otherwise, a new metadata instance is created. If the factory was
|
||||
* configured with a loader, the metadata is passed to the
|
||||
* {@link LoaderInterface::loadClassMetadata()} method for further
|
||||
* configuration. At last, the new object is returned.
|
||||
*
|
||||
* @param string|object $value A class name or an object
|
||||
*
|
||||
* @return MetadataInterface The metadata for the value
|
||||
*
|
||||
* @throws NoSuchMetadataException If no metadata exists for the given value
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
if (!is_object($value) && !is_string($value)) {
|
||||
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: %s', gettype($value)));
|
||||
}
|
||||
|
||||
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
||||
|
||||
if (isset($this->loadedClasses[$class])) {
|
||||
return $this->loadedClasses[$class];
|
||||
}
|
||||
|
||||
if (null !== $this->cache && false !== ($this->loadedClasses[$class] = $this->cache->read($class))) {
|
||||
return $this->loadedClasses[$class];
|
||||
}
|
||||
|
||||
if (!class_exists($class) && !interface_exists($class)) {
|
||||
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$metadata = new ClassMetadata($class);
|
||||
|
||||
// Include constraints from the parent class
|
||||
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
|
||||
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
|
||||
}
|
||||
|
||||
// Include constraints from all implemented interfaces
|
||||
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
|
||||
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
|
||||
continue;
|
||||
}
|
||||
$metadata->mergeConstraints($this->getMetadataFor($interface->name));
|
||||
}
|
||||
|
||||
if (null !== $this->loader) {
|
||||
$this->loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
if (null !== $this->cache) {
|
||||
$this->cache->write($metadata);
|
||||
}
|
||||
|
||||
return $this->loadedClasses[$class] = $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the factory is able to return metadata for the given
|
||||
* class name or object.
|
||||
*
|
||||
* @param string|object $value A class name or an object
|
||||
*
|
||||
* @return Boolean Whether metadata can be returned for that class
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
if (!is_object($value) && !is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$class = ltrim(is_object($value) ? get_class($value) : $value, '\\');
|
||||
|
||||
if (class_exists($class) || interface_exists($class)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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\Factory;
|
||||
|
||||
use Symfony\Component\Validator\MetadataFactoryInterface as LegacyMetadataFactoryInterface;
|
||||
|
||||
/**
|
||||
* Returns {@link MetadataInterface} instances for values.
|
||||
*
|
||||
* @since 2.5
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface MetadataFactoryInterface extends LegacyMetadataFactoryInterface
|
||||
{
|
||||
}
|
|
@ -15,6 +15,9 @@ namespace Symfony\Component\Validator;
|
|||
* Returns {@link MetadataInterface} instances for values.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @deprecated Deprecated since version 2.5, to be removed in Symfony 3.0.
|
||||
* Use {@link Mapping\Factory\MetadataFactoryInterface} instead.
|
||||
*/
|
||||
interface MetadataFactoryInterface
|
||||
{
|
||||
|
|
|
@ -31,12 +31,8 @@ use Symfony\Component\Validator\Mapping\Loader\XmlFileLoader;
|
|||
use Symfony\Component\Validator\Mapping\Loader\XmlFilesLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Validator\Mapping\Loader\YamlFilesLoader;
|
||||
use Symfony\Component\Validator\NodeTraverser\NonRecursiveNodeTraverser;
|
||||
use Symfony\Component\Validator\NodeVisitor\NodeValidationVisitor;
|
||||
use Symfony\Component\Validator\NodeVisitor\ObjectInitializationVisitor;
|
||||
use Symfony\Component\Validator\Validator\LegacyValidator;
|
||||
use Symfony\Component\Validator\Validator\RecursiveValidator;
|
||||
use Symfony\Component\Validator\Validator\TraversingValidator;
|
||||
use Symfony\Component\Validator\Validator as ValidatorV24;
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue