login consent app sql
This commit is contained in:
42
vendor/symfony/validator/Mapping/AutoMappingStrategy.php
vendored
Normal file
42
vendor/symfony/validator/Mapping/AutoMappingStrategy.php
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Specifies how the auto-mapping feature should behave.
|
||||
*
|
||||
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
|
||||
*/
|
||||
final class AutoMappingStrategy
|
||||
{
|
||||
/**
|
||||
* Nothing explicitly set, rely on auto-mapping configured regex.
|
||||
*/
|
||||
public const NONE = 0;
|
||||
|
||||
/**
|
||||
* Explicitly enabled.
|
||||
*/
|
||||
public const ENABLED = 1;
|
||||
|
||||
/**
|
||||
* Explicitly disabled.
|
||||
*/
|
||||
public const DISABLED = 2;
|
||||
|
||||
/**
|
||||
* Not instantiable.
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
52
vendor/symfony/validator/Mapping/CascadingStrategy.php
vendored
Normal file
52
vendor/symfony/validator/Mapping/CascadingStrategy.php
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Specifies whether an object should be cascaded.
|
||||
*
|
||||
* Cascading is relevant for any node type but class nodes. If such a node
|
||||
* contains an object of value, and if cascading is enabled, then the node
|
||||
* traverser will try to find class metadata for that object and validate the
|
||||
* object against that metadata.
|
||||
*
|
||||
* If no metadata is found for a cascaded object, and if that object implements
|
||||
* {@link \Traversable}, the node traverser will iterate over the object and
|
||||
* cascade each object or collection contained within, unless iteration is
|
||||
* prohibited by the specified {@link TraversalStrategy}.
|
||||
*
|
||||
* Although the constants currently represent a boolean switch, they are
|
||||
* implemented as bit mask in order to allow future extensions.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
class CascadingStrategy
|
||||
{
|
||||
/**
|
||||
* Specifies that a node should not be cascaded.
|
||||
*/
|
||||
public const NONE = 1;
|
||||
|
||||
/**
|
||||
* Specifies that a node should be cascaded.
|
||||
*/
|
||||
public const CASCADE = 2;
|
||||
|
||||
/**
|
||||
* Not instantiable.
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
513
vendor/symfony/validator/Mapping/ClassMetadata.php
vendored
Normal file
513
vendor/symfony/validator/Mapping/ClassMetadata.php
vendored
Normal file
@ -0,0 +1,513 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Cascade;
|
||||
use Symfony\Component\Validator\Constraints\Composite;
|
||||
use Symfony\Component\Validator\Constraints\GroupSequence;
|
||||
use Symfony\Component\Validator\Constraints\Traverse;
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
use Symfony\Component\Validator\Exception\GroupDefinitionException;
|
||||
|
||||
/**
|
||||
* Default implementation of {@link ClassMetadataInterface}.
|
||||
*
|
||||
* This class supports serialization and cloning.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class ClassMetadata extends GenericMetadata implements ClassMetadataInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getClassName()} instead.
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getDefaultGroup()} instead.
|
||||
*/
|
||||
public $defaultGroup;
|
||||
|
||||
/**
|
||||
* @var MemberMetadata[][]
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getPropertyMetadata()} instead.
|
||||
*/
|
||||
public $members = [];
|
||||
|
||||
/**
|
||||
* @var PropertyMetadata[]
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getPropertyMetadata()} instead.
|
||||
*/
|
||||
public $properties = [];
|
||||
|
||||
/**
|
||||
* @var GetterMetadata[]
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getPropertyMetadata()} instead.
|
||||
*/
|
||||
public $getters = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getGroupSequence()} instead.
|
||||
*/
|
||||
public $groupSequence = [];
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link isGroupSequenceProvider()} instead.
|
||||
*/
|
||||
public $groupSequenceProvider = false;
|
||||
|
||||
/**
|
||||
* The strategy for traversing traversable objects.
|
||||
*
|
||||
* By default, only instances of {@link \Traversable} are traversed.
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getTraversalStrategy()} instead.
|
||||
*/
|
||||
public $traversalStrategy = TraversalStrategy::IMPLICIT;
|
||||
|
||||
/**
|
||||
* @var \ReflectionClass
|
||||
*/
|
||||
private $reflClass;
|
||||
|
||||
public function __construct(string $class)
|
||||
{
|
||||
$this->name = $class;
|
||||
// class name without namespace
|
||||
if (false !== $nsSep = strrpos($class, '\\')) {
|
||||
$this->defaultGroup = substr($class, $nsSep + 1);
|
||||
} else {
|
||||
$this->defaultGroup = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
$parentProperties = parent::__sleep();
|
||||
|
||||
// Don't store the cascading strategy. Classes never cascade.
|
||||
unset($parentProperties[array_search('cascadingStrategy', $parentProperties)]);
|
||||
|
||||
return array_merge($parentProperties, [
|
||||
'getters',
|
||||
'groupSequence',
|
||||
'groupSequenceProvider',
|
||||
'members',
|
||||
'name',
|
||||
'properties',
|
||||
'defaultGroup',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the default group for this class.
|
||||
*
|
||||
* For each class, the group "Default" is an alias for the group
|
||||
* "<ClassName>", where <ClassName> is the non-namespaced name of the
|
||||
* class. All constraints implicitly or explicitly assigned to group
|
||||
* "Default" belong to both of these groups, unless the class defines
|
||||
* a group sequence.
|
||||
*
|
||||
* If a class defines a group sequence, validating the class in "Default"
|
||||
* will validate the group sequence. The constraints assigned to "Default"
|
||||
* can still be validated by validating the class in "<ClassName>".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDefaultGroup()
|
||||
{
|
||||
return $this->defaultGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* If the constraint {@link Cascade} is added, the cascading strategy will be
|
||||
* changed to {@link CascadingStrategy::CASCADE}.
|
||||
*
|
||||
* If the constraint {@link Traverse} is added, the traversal strategy will be
|
||||
* changed. Depending on the $traverse property of that constraint,
|
||||
* the traversal strategy will be set to one of the following:
|
||||
*
|
||||
* - {@link TraversalStrategy::IMPLICIT} by default
|
||||
* - {@link TraversalStrategy::NONE} if $traverse is disabled
|
||||
* - {@link TraversalStrategy::TRAVERSE} if $traverse is enabled
|
||||
*/
|
||||
public function addConstraint(Constraint $constraint)
|
||||
{
|
||||
$this->checkConstraint($constraint);
|
||||
|
||||
if ($constraint instanceof Traverse) {
|
||||
if ($constraint->traverse) {
|
||||
// If traverse is true, traversal should be explicitly enabled
|
||||
$this->traversalStrategy = TraversalStrategy::TRAVERSE;
|
||||
} else {
|
||||
// If traverse is false, traversal should be explicitly disabled
|
||||
$this->traversalStrategy = TraversalStrategy::NONE;
|
||||
}
|
||||
|
||||
// The constraint is not added
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($constraint instanceof Cascade) {
|
||||
if (\PHP_VERSION_ID < 70400) {
|
||||
throw new ConstraintDefinitionException(sprintf('The constraint "%s" requires PHP 7.4.', Cascade::class));
|
||||
}
|
||||
|
||||
$this->cascadingStrategy = CascadingStrategy::CASCADE;
|
||||
|
||||
foreach ($this->getReflectionClass()->getProperties() as $property) {
|
||||
if ($property->hasType() && (('array' === $type = $property->getType()->getName()) || class_exists(($type)))) {
|
||||
$this->addPropertyConstraint($property->getName(), new Valid());
|
||||
}
|
||||
}
|
||||
|
||||
// The constraint is not added
|
||||
return $this;
|
||||
}
|
||||
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
|
||||
parent::addConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a constraint to the given property.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addPropertyConstraint(string $property, Constraint $constraint)
|
||||
{
|
||||
if (!isset($this->properties[$property])) {
|
||||
$this->properties[$property] = new PropertyMetadata($this->getClassName(), $property);
|
||||
|
||||
$this->addPropertyMetadata($this->properties[$property]);
|
||||
}
|
||||
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
|
||||
$this->properties[$property]->addConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Constraint[] $constraints
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addPropertyConstraints(string $property, array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addPropertyConstraint($property, $constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a constraint to the getter of the given property.
|
||||
*
|
||||
* The name of the getter is assumed to be the name of the property with an
|
||||
* uppercased first letter and the prefix "get", "is" or "has".
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addGetterConstraint(string $property, Constraint $constraint)
|
||||
{
|
||||
if (!isset($this->getters[$property])) {
|
||||
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property);
|
||||
|
||||
$this->addPropertyMetadata($this->getters[$property]);
|
||||
}
|
||||
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
|
||||
$this->getters[$property]->addConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a constraint to the getter of the given property.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addGetterMethodConstraint(string $property, string $method, Constraint $constraint)
|
||||
{
|
||||
if (!isset($this->getters[$property])) {
|
||||
$this->getters[$property] = new GetterMetadata($this->getClassName(), $property, $method);
|
||||
|
||||
$this->addPropertyMetadata($this->getters[$property]);
|
||||
}
|
||||
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
|
||||
$this->getters[$property]->addConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Constraint[] $constraints
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addGetterConstraints(string $property, array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addGetterConstraint($property, $constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Constraint[] $constraints
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addGetterMethodConstraints(string $property, string $method, array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addGetterMethodConstraint($property, $method, $constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the constraints of the given metadata into this object.
|
||||
*/
|
||||
public function mergeConstraints(self $source)
|
||||
{
|
||||
if ($source->isGroupSequenceProvider()) {
|
||||
$this->setGroupSequenceProvider(true);
|
||||
}
|
||||
|
||||
foreach ($source->getConstraints() as $constraint) {
|
||||
$this->addConstraint(clone $constraint);
|
||||
}
|
||||
|
||||
foreach ($source->getConstrainedProperties() as $property) {
|
||||
foreach ($source->getPropertyMetadata($property) as $member) {
|
||||
$member = clone $member;
|
||||
|
||||
foreach ($member->getConstraints() as $constraint) {
|
||||
if (\in_array($constraint::DEFAULT_GROUP, $constraint->groups, true)) {
|
||||
$member->constraintsByGroup[$this->getDefaultGroup()][] = $constraint;
|
||||
}
|
||||
|
||||
$constraint->addImplicitGroupName($this->getDefaultGroup());
|
||||
}
|
||||
|
||||
$this->addPropertyMetadata($member);
|
||||
|
||||
if ($member instanceof MemberMetadata && !$member->isPrivate($this->name)) {
|
||||
$property = $member->getPropertyName();
|
||||
|
||||
if ($member instanceof PropertyMetadata && !isset($this->properties[$property])) {
|
||||
$this->properties[$property] = $member;
|
||||
} elseif ($member instanceof GetterMetadata && !isset($this->getters[$property])) {
|
||||
$this->getters[$property] = $member;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasPropertyMetadata(string $property)
|
||||
{
|
||||
return \array_key_exists($property, $this->members);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPropertyMetadata(string $property)
|
||||
{
|
||||
return $this->members[$property] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConstrainedProperties()
|
||||
{
|
||||
return array_keys($this->members);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default group sequence for this class.
|
||||
*
|
||||
* @param string[]|GroupSequence $groupSequence An array of group names
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws GroupDefinitionException
|
||||
*/
|
||||
public function setGroupSequence($groupSequence)
|
||||
{
|
||||
if ($this->isGroupSequenceProvider()) {
|
||||
throw new GroupDefinitionException('Defining a static group sequence is not allowed with a group sequence provider.');
|
||||
}
|
||||
|
||||
if (\is_array($groupSequence)) {
|
||||
$groupSequence = new GroupSequence($groupSequence);
|
||||
}
|
||||
|
||||
if (\in_array(Constraint::DEFAULT_GROUP, $groupSequence->groups, true)) {
|
||||
throw new GroupDefinitionException(sprintf('The group "%s" is not allowed in group sequences.', Constraint::DEFAULT_GROUP));
|
||||
}
|
||||
|
||||
if (!\in_array($this->getDefaultGroup(), $groupSequence->groups, true)) {
|
||||
throw new GroupDefinitionException(sprintf('The group "%s" is missing in the group sequence.', $this->getDefaultGroup()));
|
||||
}
|
||||
|
||||
$this->groupSequence = $groupSequence;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasGroupSequence()
|
||||
{
|
||||
return $this->groupSequence && \count($this->groupSequence->groups) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getGroupSequence()
|
||||
{
|
||||
return $this->groupSequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ReflectionClass instance for this class.
|
||||
*
|
||||
* @return \ReflectionClass
|
||||
*/
|
||||
public function getReflectionClass()
|
||||
{
|
||||
if (!$this->reflClass) {
|
||||
$this->reflClass = new \ReflectionClass($this->getClassName());
|
||||
}
|
||||
|
||||
return $this->reflClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether a group sequence provider should be used.
|
||||
*
|
||||
* @throws GroupDefinitionException
|
||||
*/
|
||||
public function setGroupSequenceProvider(bool $active)
|
||||
{
|
||||
if ($this->hasGroupSequence()) {
|
||||
throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence.');
|
||||
}
|
||||
|
||||
if (!$this->getReflectionClass()->implementsInterface('Symfony\Component\Validator\GroupSequenceProviderInterface')) {
|
||||
throw new GroupDefinitionException(sprintf('Class "%s" must implement GroupSequenceProviderInterface.', $this->name));
|
||||
}
|
||||
|
||||
$this->groupSequenceProvider = $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function isGroupSequenceProvider()
|
||||
{
|
||||
return $this->groupSequenceProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCascadingStrategy()
|
||||
{
|
||||
return $this->cascadingStrategy;
|
||||
}
|
||||
|
||||
private function addPropertyMetadata(PropertyMetadataInterface $metadata)
|
||||
{
|
||||
$property = $metadata->getPropertyName();
|
||||
|
||||
$this->members[$property][] = $metadata;
|
||||
}
|
||||
|
||||
private function checkConstraint(Constraint $constraint)
|
||||
{
|
||||
if (!\in_array(Constraint::CLASS_CONSTRAINT, (array) $constraint->getTargets(), true)) {
|
||||
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on classes.', get_debug_type($constraint)));
|
||||
}
|
||||
|
||||
if ($constraint instanceof Composite) {
|
||||
foreach ($constraint->getNestedConstraints() as $nestedConstraint) {
|
||||
$this->checkConstraint($nestedConstraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
100
vendor/symfony/validator/Mapping/ClassMetadataInterface.php
vendored
Normal file
100
vendor/symfony/validator/Mapping/ClassMetadataInterface.php
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraints\GroupSequence;
|
||||
use Symfony\Component\Validator\GroupSequenceProviderInterface;
|
||||
|
||||
/**
|
||||
* Stores all metadata needed for validating objects of specific class.
|
||||
*
|
||||
* Most importantly, the metadata stores the constraints against which an object
|
||||
* and its properties should be validated.
|
||||
*
|
||||
* Additionally, the metadata stores whether the "Default" group is overridden
|
||||
* by a group sequence for that class and whether instances of that class
|
||||
* should be traversed or not.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see MetadataInterface
|
||||
* @see GroupSequence
|
||||
* @see GroupSequenceProviderInterface
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
interface ClassMetadataInterface extends MetadataInterface
|
||||
{
|
||||
/**
|
||||
* Returns the names of all constrained properties.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getConstrainedProperties();
|
||||
|
||||
/**
|
||||
* Returns whether the "Default" group is overridden by a group sequence.
|
||||
*
|
||||
* If it is, you can access the group sequence with {@link getGroupSequence()}.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasGroupSequence();
|
||||
|
||||
/**
|
||||
* Returns the group sequence that overrides the "Default" group for this
|
||||
* class.
|
||||
*
|
||||
* @return GroupSequence|null
|
||||
*/
|
||||
public function getGroupSequence();
|
||||
|
||||
/**
|
||||
* Returns whether the "Default" group is overridden by a dynamic group
|
||||
* sequence obtained by the validated objects.
|
||||
*
|
||||
* If this method returns true, the class must implement
|
||||
* {@link GroupSequenceProviderInterface}.
|
||||
* This interface will be used to obtain the group sequence when an object
|
||||
* of this class is validated.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGroupSequenceProvider();
|
||||
|
||||
/**
|
||||
* Check if there's any metadata attached to the given named property.
|
||||
*
|
||||
* @param string $property The property name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPropertyMetadata(string $property);
|
||||
|
||||
/**
|
||||
* Returns all metadata instances for the given named property.
|
||||
*
|
||||
* If your implementation does not support properties, throw an exception
|
||||
* in this method (for example a <tt>BadMethodCallException</tt>).
|
||||
*
|
||||
* @param string $property The property name
|
||||
*
|
||||
* @return PropertyMetadataInterface[]
|
||||
*/
|
||||
public function getPropertyMetadata(string $property);
|
||||
|
||||
/**
|
||||
* Returns the name of the backing PHP class.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName();
|
||||
}
|
42
vendor/symfony/validator/Mapping/Factory/BlackHoleMetadataFactory.php
vendored
Normal file
42
vendor/symfony/validator/Mapping/Factory/BlackHoleMetadataFactory.php
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
<?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\LogicException;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
165
vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php
vendored
Normal file
165
vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php
vendored
Normal file
@ -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 Psr\Cache\CacheItemPoolInterface;
|
||||
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Validator\Mapping\Loader\LoaderInterface;
|
||||
|
||||
/**
|
||||
* 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 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 LazyLoadingMetadataFactory implements MetadataFactoryInterface
|
||||
{
|
||||
protected $loader;
|
||||
protected $cache;
|
||||
|
||||
/**
|
||||
* The loaded metadata, indexed by class name.
|
||||
*
|
||||
* @var ClassMetadata[]
|
||||
*/
|
||||
protected $loadedClasses = [];
|
||||
|
||||
public function __construct(LoaderInterface $loader = null, CacheItemPoolInterface $cache = null)
|
||||
{
|
||||
$this->loader = $loader;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
public function getMetadataFor($value)
|
||||
{
|
||||
if (!\is_object($value) && !\is_string($value)) {
|
||||
throw new NoSuchMetadataException(sprintf('Cannot create metadata for non-objects. Got: "%s".', get_debug_type($value)));
|
||||
}
|
||||
|
||||
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
|
||||
|
||||
if (isset($this->loadedClasses[$class])) {
|
||||
return $this->loadedClasses[$class];
|
||||
}
|
||||
|
||||
if (!class_exists($class) && !interface_exists($class, false)) {
|
||||
throw new NoSuchMetadataException(sprintf('The class or interface "%s" does not exist.', $class));
|
||||
}
|
||||
|
||||
$cacheItem = null === $this->cache ? null : $this->cache->getItem($this->escapeClassName($class));
|
||||
if ($cacheItem && $cacheItem->isHit()) {
|
||||
$metadata = $cacheItem->get();
|
||||
|
||||
// Include constraints from the parent class
|
||||
$this->mergeConstraints($metadata);
|
||||
|
||||
return $this->loadedClasses[$class] = $metadata;
|
||||
}
|
||||
|
||||
$metadata = new ClassMetadata($class);
|
||||
|
||||
if (null !== $this->loader) {
|
||||
$this->loader->loadClassMetadata($metadata);
|
||||
}
|
||||
|
||||
if (null !== $cacheItem) {
|
||||
$this->cache->save($cacheItem->set($metadata));
|
||||
}
|
||||
|
||||
// Include constraints from the parent class
|
||||
$this->mergeConstraints($metadata);
|
||||
|
||||
return $this->loadedClasses[$class] = $metadata;
|
||||
}
|
||||
|
||||
private function mergeConstraints(ClassMetadata $metadata)
|
||||
{
|
||||
if ($metadata->getReflectionClass()->isInterface()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Include constraints from the parent class
|
||||
if ($parent = $metadata->getReflectionClass()->getParentClass()) {
|
||||
$metadata->mergeConstraints($this->getMetadataFor($parent->name));
|
||||
}
|
||||
|
||||
// Include constraints from all directly implemented interfaces
|
||||
foreach ($metadata->getReflectionClass()->getInterfaces() as $interface) {
|
||||
if ('Symfony\Component\Validator\GroupSequenceProviderInterface' === $interface->name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($parent && \in_array($interface->getName(), $parent->getInterfaceNames(), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$metadata->mergeConstraints($this->getMetadataFor($interface->name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasMetadataFor($value)
|
||||
{
|
||||
if (!\is_object($value) && !\is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$class = ltrim(\is_object($value) ? \get_class($value) : $value, '\\');
|
||||
|
||||
return class_exists($class) || interface_exists($class, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces backslashes by dots in a class name.
|
||||
*/
|
||||
private function escapeClassName(string $class): string
|
||||
{
|
||||
if (str_contains($class, '@')) {
|
||||
// anonymous class: replace all PSR6-reserved characters
|
||||
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class);
|
||||
}
|
||||
|
||||
return str_replace('\\', '.', $class);
|
||||
}
|
||||
}
|
43
vendor/symfony/validator/Mapping/Factory/MetadataFactoryInterface.php
vendored
Normal file
43
vendor/symfony/validator/Mapping/Factory/MetadataFactoryInterface.php
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
<?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\MetadataInterface;
|
||||
|
||||
/**
|
||||
* Returns {@link \Symfony\Component\Validator\Mapping\MetadataInterface} instances for values.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface MetadataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* Returns the metadata for the given value.
|
||||
*
|
||||
* @param mixed $value Some value
|
||||
*
|
||||
* @return MetadataInterface
|
||||
*
|
||||
* @throws NoSuchMetadataException If no metadata exists for the given value
|
||||
*/
|
||||
public function getMetadataFor($value);
|
||||
|
||||
/**
|
||||
* Returns whether the class is able to return metadata for the given value.
|
||||
*
|
||||
* @param mixed $value Some value
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMetadataFor($value);
|
||||
}
|
240
vendor/symfony/validator/Mapping/GenericMetadata.php
vendored
Normal file
240
vendor/symfony/validator/Mapping/GenericMetadata.php
vendored
Normal file
@ -0,0 +1,240 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Cascade;
|
||||
use Symfony\Component\Validator\Constraints\DisableAutoMapping;
|
||||
use Symfony\Component\Validator\Constraints\EnableAutoMapping;
|
||||
use Symfony\Component\Validator\Constraints\Traverse;
|
||||
use Symfony\Component\Validator\Constraints\Valid;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
|
||||
/**
|
||||
* A generic container of {@link Constraint} objects.
|
||||
*
|
||||
* This class supports serialization and cloning.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class GenericMetadata implements MetadataInterface
|
||||
{
|
||||
/**
|
||||
* @var Constraint[]
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getConstraints()} and {@link findConstraints()} instead.
|
||||
*/
|
||||
public $constraints = [];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link findConstraints()} instead.
|
||||
*/
|
||||
public $constraintsByGroup = [];
|
||||
|
||||
/**
|
||||
* The strategy for cascading objects.
|
||||
*
|
||||
* By default, objects are not cascaded.
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @see CascadingStrategy
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getCascadingStrategy()} instead.
|
||||
*/
|
||||
public $cascadingStrategy = CascadingStrategy::NONE;
|
||||
|
||||
/**
|
||||
* The strategy for traversing traversable objects.
|
||||
*
|
||||
* By default, traversable objects are not traversed.
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @see TraversalStrategy
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getTraversalStrategy()} instead.
|
||||
*/
|
||||
public $traversalStrategy = TraversalStrategy::NONE;
|
||||
|
||||
/**
|
||||
* Is auto-mapping enabled?
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
* @see AutoMappingStrategy
|
||||
*
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getAutoMappingStrategy()} instead.
|
||||
*/
|
||||
public $autoMappingStrategy = AutoMappingStrategy::NONE;
|
||||
|
||||
/**
|
||||
* Returns the names of the properties that should be serialized.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return [
|
||||
'constraints',
|
||||
'constraintsByGroup',
|
||||
'cascadingStrategy',
|
||||
'traversalStrategy',
|
||||
'autoMappingStrategy',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones this object.
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
$constraints = $this->constraints;
|
||||
|
||||
$this->constraints = [];
|
||||
$this->constraintsByGroup = [];
|
||||
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addConstraint(clone $constraint);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a constraint.
|
||||
*
|
||||
* If the constraint {@link Valid} is added, the cascading strategy will be
|
||||
* changed to {@link CascadingStrategy::CASCADE}. Depending on the
|
||||
* $traverse property of that constraint, the traversal strategy
|
||||
* will be set to one of the following:
|
||||
*
|
||||
* - {@link TraversalStrategy::IMPLICIT} if $traverse is enabled
|
||||
* - {@link TraversalStrategy::NONE} if $traverse is disabled
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @throws ConstraintDefinitionException When trying to add the {@link Cascade}
|
||||
* or {@link Traverse} constraint
|
||||
*/
|
||||
public function addConstraint(Constraint $constraint)
|
||||
{
|
||||
if ($constraint instanceof Traverse || $constraint instanceof Cascade) {
|
||||
throw new ConstraintDefinitionException(sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\Component\Validator\Constraints\Valid" instead.', get_debug_type($constraint)));
|
||||
}
|
||||
|
||||
if ($constraint instanceof Valid && null === $constraint->groups) {
|
||||
$this->cascadingStrategy = CascadingStrategy::CASCADE;
|
||||
|
||||
if ($constraint->traverse) {
|
||||
$this->traversalStrategy = TraversalStrategy::IMPLICIT;
|
||||
} else {
|
||||
$this->traversalStrategy = TraversalStrategy::NONE;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($constraint instanceof DisableAutoMapping || $constraint instanceof EnableAutoMapping) {
|
||||
$this->autoMappingStrategy = $constraint instanceof EnableAutoMapping ? AutoMappingStrategy::ENABLED : AutoMappingStrategy::DISABLED;
|
||||
|
||||
// The constraint is not added
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->constraints[] = $constraint;
|
||||
|
||||
foreach ($constraint->groups as $group) {
|
||||
$this->constraintsByGroup[$group][] = $constraint;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an list of constraints.
|
||||
*
|
||||
* @param Constraint[] $constraints The constraints to add
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function addConstraints(array $constraints)
|
||||
{
|
||||
foreach ($constraints as $constraint) {
|
||||
$this->addConstraint($constraint);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConstraints()
|
||||
{
|
||||
return $this->constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this element has any constraints.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasConstraints()
|
||||
{
|
||||
return \count($this->constraints) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* Aware of the global group (* group).
|
||||
*/
|
||||
public function findConstraints(string $group)
|
||||
{
|
||||
return $this->constraintsByGroup[$group] ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCascadingStrategy()
|
||||
{
|
||||
return $this->cascadingStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTraversalStrategy()
|
||||
{
|
||||
return $this->traversalStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AutoMappingStrategy
|
||||
*/
|
||||
public function getAutoMappingStrategy(): int
|
||||
{
|
||||
return $this->autoMappingStrategy;
|
||||
}
|
||||
}
|
80
vendor/symfony/validator/Mapping/GetterMetadata.php
vendored
Normal file
80
vendor/symfony/validator/Mapping/GetterMetadata.php
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
|
||||
/**
|
||||
* Stores all metadata needed for validating a class property via its getter
|
||||
* method.
|
||||
*
|
||||
* A property getter is any method that is equal to the property's name,
|
||||
* prefixed with "get", "is" or "has". That method will be used to access the
|
||||
* property's value.
|
||||
*
|
||||
* The getter will be invoked by reflection, so the access of private and
|
||||
* protected getters is supported.
|
||||
*
|
||||
* This class supports serialization and cloning.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see PropertyMetadataInterface
|
||||
*/
|
||||
class GetterMetadata extends MemberMetadata
|
||||
{
|
||||
/**
|
||||
* @param string $class The class the getter is defined on
|
||||
* @param string $property The property which the getter returns
|
||||
* @param string|null $method The method that is called to retrieve the value being validated (null for auto-detection)
|
||||
*
|
||||
* @throws ValidatorException
|
||||
*/
|
||||
public function __construct(string $class, string $property, string $method = null)
|
||||
{
|
||||
if (null === $method) {
|
||||
$getMethod = 'get'.ucfirst($property);
|
||||
$isMethod = 'is'.ucfirst($property);
|
||||
$hasMethod = 'has'.ucfirst($property);
|
||||
|
||||
if (method_exists($class, $getMethod)) {
|
||||
$method = $getMethod;
|
||||
} elseif (method_exists($class, $isMethod)) {
|
||||
$method = $isMethod;
|
||||
} elseif (method_exists($class, $hasMethod)) {
|
||||
$method = $hasMethod;
|
||||
} else {
|
||||
throw new ValidatorException(sprintf('Neither of these methods exist in class "%s": "%s", "%s", "%s".', $class, $getMethod, $isMethod, $hasMethod));
|
||||
}
|
||||
} elseif (!method_exists($class, $method)) {
|
||||
throw new ValidatorException(sprintf('The "%s()" method does not exist in class "%s".', $method, $class));
|
||||
}
|
||||
|
||||
parent::__construct($class, $method, $property);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPropertyValue($object)
|
||||
{
|
||||
return $this->newReflectionMember($object)->invoke($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function newReflectionMember($objectOrClassName)
|
||||
{
|
||||
return new \ReflectionMethod($objectOrClassName, $this->getName());
|
||||
}
|
||||
}
|
85
vendor/symfony/validator/Mapping/Loader/AbstractLoader.php
vendored
Normal file
85
vendor/symfony/validator/Mapping/Loader/AbstractLoader.php
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
|
||||
/**
|
||||
* Base loader for validation metadata.
|
||||
*
|
||||
* This loader supports the loading of constraints from Symfony's default
|
||||
* namespace (see {@link DEFAULT_NAMESPACE}) using the short class names of
|
||||
* those constraints. Constraints can also be loaded using their fully
|
||||
* qualified class names. At last, namespace aliases can be defined to load
|
||||
* constraints with the syntax "alias:ShortName".
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
abstract class AbstractLoader implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* The namespace to load constraints from by default.
|
||||
*/
|
||||
public const DEFAULT_NAMESPACE = '\\Symfony\\Component\\Validator\\Constraints\\';
|
||||
|
||||
protected $namespaces = [];
|
||||
|
||||
/**
|
||||
* Adds a namespace alias.
|
||||
*
|
||||
* The namespace alias can be used to reference constraints from specific
|
||||
* namespaces in {@link newConstraint()}:
|
||||
*
|
||||
* $this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\');
|
||||
*
|
||||
* $constraint = $this->newConstraint('mynamespace:NotNull');
|
||||
*/
|
||||
protected function addNamespaceAlias(string $alias, string $namespace)
|
||||
{
|
||||
$this->namespaces[$alias] = $namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new constraint instance for the given constraint name.
|
||||
*
|
||||
* @param string $name The constraint name. Either a constraint relative
|
||||
* to the default constraint namespace, or a fully
|
||||
* qualified class name. Alternatively, the constraint
|
||||
* may be preceded by a namespace alias and a colon.
|
||||
* The namespace alias must have been defined using
|
||||
* {@link addNamespaceAlias()}.
|
||||
* @param mixed $options The constraint options
|
||||
*
|
||||
* @return Constraint
|
||||
*
|
||||
* @throws MappingException If the namespace prefix is undefined
|
||||
*/
|
||||
protected function newConstraint(string $name, $options = null)
|
||||
{
|
||||
if (str_contains($name, '\\') && class_exists($name)) {
|
||||
$className = $name;
|
||||
} elseif (str_contains($name, ':')) {
|
||||
[$prefix, $className] = explode(':', $name, 2);
|
||||
|
||||
if (!isset($this->namespaces[$prefix])) {
|
||||
throw new MappingException(sprintf('Undefined namespace prefix "%s".', $prefix));
|
||||
}
|
||||
|
||||
$className = $this->namespaces[$prefix].$className;
|
||||
} else {
|
||||
$className = self::DEFAULT_NAMESPACE.$name;
|
||||
}
|
||||
|
||||
return new $className($options);
|
||||
}
|
||||
}
|
123
vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php
vendored
Normal file
123
vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Doctrine\Common\Annotations\Reader;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Constraints\GroupSequence;
|
||||
use Symfony\Component\Validator\Constraints\GroupSequenceProvider;
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Loads validation metadata using a Doctrine annotation {@link Reader} or using PHP 8 attributes.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
* @author Alexander M. Turek <me@derrabus.de>
|
||||
*/
|
||||
class AnnotationLoader implements LoaderInterface
|
||||
{
|
||||
protected $reader;
|
||||
|
||||
public function __construct(Reader $reader = null)
|
||||
{
|
||||
$this->reader = $reader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$reflClass = $metadata->getReflectionClass();
|
||||
$className = $reflClass->name;
|
||||
$success = false;
|
||||
|
||||
foreach ($this->getAnnotations($reflClass) as $constraint) {
|
||||
if ($constraint instanceof GroupSequence) {
|
||||
$metadata->setGroupSequence($constraint->groups);
|
||||
} elseif ($constraint instanceof GroupSequenceProvider) {
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
} elseif ($constraint instanceof Constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
}
|
||||
|
||||
foreach ($reflClass->getProperties() as $property) {
|
||||
if ($property->getDeclaringClass()->name === $className) {
|
||||
foreach ($this->getAnnotations($property) as $constraint) {
|
||||
if ($constraint instanceof Constraint) {
|
||||
$metadata->addPropertyConstraint($property->name, $constraint);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($reflClass->getMethods() as $method) {
|
||||
if ($method->getDeclaringClass()->name === $className) {
|
||||
foreach ($this->getAnnotations($method) as $constraint) {
|
||||
if ($constraint instanceof Callback) {
|
||||
$constraint->callback = $method->getName();
|
||||
|
||||
$metadata->addConstraint($constraint);
|
||||
} elseif ($constraint instanceof Constraint) {
|
||||
if (preg_match('/^(get|is|has)(.+)$/i', $method->name, $matches)) {
|
||||
$metadata->addGetterMethodConstraint(lcfirst($matches[2]), $matches[0], $constraint);
|
||||
} else {
|
||||
throw new MappingException(sprintf('The constraint on "%s::%s()" cannot be added. Constraints can only be added on methods beginning with "get", "is" or "has".', $className, $method->name));
|
||||
}
|
||||
}
|
||||
|
||||
$success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionClass|\ReflectionMethod|\ReflectionProperty $reflection
|
||||
*/
|
||||
private function getAnnotations(object $reflection): iterable
|
||||
{
|
||||
if (\PHP_VERSION_ID >= 80000) {
|
||||
foreach ($reflection->getAttributes(GroupSequence::class) as $attribute) {
|
||||
yield $attribute->newInstance();
|
||||
}
|
||||
foreach ($reflection->getAttributes(GroupSequenceProvider::class) as $attribute) {
|
||||
yield $attribute->newInstance();
|
||||
}
|
||||
foreach ($reflection->getAttributes(Constraint::class, \ReflectionAttribute::IS_INSTANCEOF) as $attribute) {
|
||||
yield $attribute->newInstance();
|
||||
}
|
||||
}
|
||||
if (!$this->reader) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($reflection instanceof \ReflectionClass) {
|
||||
yield from $this->reader->getClassAnnotations($reflection);
|
||||
}
|
||||
if ($reflection instanceof \ReflectionMethod) {
|
||||
yield from $this->reader->getMethodAnnotations($reflection);
|
||||
}
|
||||
if ($reflection instanceof \ReflectionProperty) {
|
||||
yield from $this->reader->getPropertyAnnotations($reflection);
|
||||
}
|
||||
}
|
||||
}
|
34
vendor/symfony/validator/Mapping/Loader/AutoMappingTrait.php
vendored
Normal file
34
vendor/symfony/validator/Mapping/Loader/AutoMappingTrait.php
vendored
Normal file
@ -0,0 +1,34 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\AutoMappingStrategy;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Utility methods to create auto mapping loaders.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
trait AutoMappingTrait
|
||||
{
|
||||
private function isAutoMappingEnabledForClass(ClassMetadata $metadata, string $classValidatorRegexp = null): bool
|
||||
{
|
||||
// Check if AutoMapping constraint is set first
|
||||
if (AutoMappingStrategy::NONE !== $strategy = $metadata->getAutoMappingStrategy()) {
|
||||
return AutoMappingStrategy::ENABLED === $strategy;
|
||||
}
|
||||
|
||||
// Fallback on the config
|
||||
return null !== $classValidatorRegexp && preg_match($classValidatorRegexp, $metadata->getClassName());
|
||||
}
|
||||
}
|
51
vendor/symfony/validator/Mapping/Loader/FileLoader.php
vendored
Normal file
51
vendor/symfony/validator/Mapping/Loader/FileLoader.php
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
|
||||
/**
|
||||
* Base loader for loading validation metadata from a file.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see YamlFileLoader
|
||||
* @see XmlFileLoader
|
||||
*/
|
||||
abstract class FileLoader extends AbstractLoader
|
||||
{
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* Creates a new loader.
|
||||
*
|
||||
* @param string $file The mapping file to load
|
||||
*
|
||||
* @throws MappingException If the file does not exist or is not readable
|
||||
*/
|
||||
public function __construct(string $file)
|
||||
{
|
||||
if (!is_file($file)) {
|
||||
throw new MappingException(sprintf('The mapping file "%s" does not exist.', $file));
|
||||
}
|
||||
|
||||
if (!is_readable($file)) {
|
||||
throw new MappingException(sprintf('The mapping file "%s" is not readable.', $file));
|
||||
}
|
||||
|
||||
if (!stream_is_local($this->file)) {
|
||||
throw new MappingException(sprintf('The mapping file "%s" is not a local file.', $file));
|
||||
}
|
||||
|
||||
$this->file = $file;
|
||||
}
|
||||
}
|
57
vendor/symfony/validator/Mapping/Loader/FilesLoader.php
vendored
Normal file
57
vendor/symfony/validator/Mapping/Loader/FilesLoader.php
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
<?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\Loader;
|
||||
|
||||
/**
|
||||
* Base loader for loading validation metadata from a list of files.
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see YamlFilesLoader
|
||||
* @see XmlFilesLoader
|
||||
*/
|
||||
abstract class FilesLoader extends LoaderChain
|
||||
{
|
||||
/**
|
||||
* Creates a new loader.
|
||||
*
|
||||
* @param array $paths An array of file paths
|
||||
*/
|
||||
public function __construct(array $paths)
|
||||
{
|
||||
parent::__construct($this->getFileLoaders($paths));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of file loaders for the given file paths.
|
||||
*
|
||||
* @return LoaderInterface[]
|
||||
*/
|
||||
protected function getFileLoaders(array $paths)
|
||||
{
|
||||
$loaders = [];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
$loaders[] = $this->getFileLoaderInstance($path);
|
||||
}
|
||||
|
||||
return $loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a loader for the given file path.
|
||||
*
|
||||
* @return LoaderInterface
|
||||
*/
|
||||
abstract protected function getFileLoaderInstance(string $path);
|
||||
}
|
67
vendor/symfony/validator/Mapping/Loader/LoaderChain.php
vendored
Normal file
67
vendor/symfony/validator/Mapping/Loader/LoaderChain.php
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Loads validation metadata from multiple {@link LoaderInterface} instances.
|
||||
*
|
||||
* Pass the loaders when constructing the chain. Once
|
||||
* {@link loadClassMetadata()} is called, that method will be called on all
|
||||
* loaders in the chain.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class LoaderChain implements LoaderInterface
|
||||
{
|
||||
protected $loaders;
|
||||
|
||||
/**
|
||||
* @param LoaderInterface[] $loaders The metadata loaders to use
|
||||
*
|
||||
* @throws MappingException If any of the loaders has an invalid type
|
||||
*/
|
||||
public function __construct(array $loaders)
|
||||
{
|
||||
foreach ($loaders as $loader) {
|
||||
if (!$loader instanceof LoaderInterface) {
|
||||
throw new MappingException(sprintf('Class "%s" is expected to implement LoaderInterface.', get_debug_type($loader)));
|
||||
}
|
||||
}
|
||||
|
||||
$this->loaders = $loaders;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$success = false;
|
||||
|
||||
foreach ($this->loaders as $loader) {
|
||||
$success = $loader->loadClassMetadata($metadata) || $success;
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoaderInterface[]
|
||||
*/
|
||||
public function getLoaders()
|
||||
{
|
||||
return $this->loaders;
|
||||
}
|
||||
}
|
29
vendor/symfony/validator/Mapping/Loader/LoaderInterface.php
vendored
Normal file
29
vendor/symfony/validator/Mapping/Loader/LoaderInterface.php
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Loads validation metadata into {@link ClassMetadata} instances.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
interface LoaderInterface
|
||||
{
|
||||
/**
|
||||
* Loads validation metadata into a {@link ClassMetadata} instance.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata);
|
||||
}
|
179
vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php
vendored
Normal file
179
vendor/symfony/validator/Mapping/Loader/PropertyInfoLoader.php
vendored
Normal file
@ -0,0 +1,179 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
|
||||
use Symfony\Component\PropertyInfo\Type as PropertyInfoType;
|
||||
use Symfony\Component\Validator\Constraints\All;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Symfony\Component\Validator\Constraints\NotNull;
|
||||
use Symfony\Component\Validator\Constraints\Type;
|
||||
use Symfony\Component\Validator\Mapping\AutoMappingStrategy;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Guesses and loads the appropriate constraints using PropertyInfo.
|
||||
*
|
||||
* @author Kévin Dunglas <dunglas@gmail.com>
|
||||
*/
|
||||
final class PropertyInfoLoader implements LoaderInterface
|
||||
{
|
||||
use AutoMappingTrait;
|
||||
|
||||
private $listExtractor;
|
||||
private $typeExtractor;
|
||||
private $accessExtractor;
|
||||
private $classValidatorRegexp;
|
||||
|
||||
public function __construct(PropertyListExtractorInterface $listExtractor, PropertyTypeExtractorInterface $typeExtractor, PropertyAccessExtractorInterface $accessExtractor, string $classValidatorRegexp = null)
|
||||
{
|
||||
$this->listExtractor = $listExtractor;
|
||||
$this->typeExtractor = $typeExtractor;
|
||||
$this->accessExtractor = $accessExtractor;
|
||||
$this->classValidatorRegexp = $classValidatorRegexp;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata): bool
|
||||
{
|
||||
$className = $metadata->getClassName();
|
||||
if (!$properties = $this->listExtractor->getProperties($className)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$loaded = false;
|
||||
$enabledForClass = $this->isAutoMappingEnabledForClass($metadata, $this->classValidatorRegexp);
|
||||
foreach ($properties as $property) {
|
||||
if (false === $this->accessExtractor->isWritable($className, $property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!property_exists($className, $property)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$types = $this->typeExtractor->getTypes($className, $property);
|
||||
if (null === $types) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$enabledForProperty = $enabledForClass;
|
||||
$hasTypeConstraint = false;
|
||||
$hasNotNullConstraint = false;
|
||||
$hasNotBlankConstraint = false;
|
||||
$allConstraint = null;
|
||||
foreach ($metadata->getPropertyMetadata($property) as $propertyMetadata) {
|
||||
// Enabling or disabling auto-mapping explicitly always takes precedence
|
||||
if (AutoMappingStrategy::DISABLED === $propertyMetadata->getAutoMappingStrategy()) {
|
||||
continue 2;
|
||||
}
|
||||
|
||||
if (AutoMappingStrategy::ENABLED === $propertyMetadata->getAutoMappingStrategy()) {
|
||||
$enabledForProperty = true;
|
||||
}
|
||||
|
||||
foreach ($propertyMetadata->getConstraints() as $constraint) {
|
||||
if ($constraint instanceof Type) {
|
||||
$hasTypeConstraint = true;
|
||||
} elseif ($constraint instanceof NotNull) {
|
||||
$hasNotNullConstraint = true;
|
||||
} elseif ($constraint instanceof NotBlank) {
|
||||
$hasNotBlankConstraint = true;
|
||||
} elseif ($constraint instanceof All) {
|
||||
$allConstraint = $constraint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$enabledForProperty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$loaded = true;
|
||||
$builtinTypes = [];
|
||||
$nullable = false;
|
||||
$scalar = true;
|
||||
foreach ($types as $type) {
|
||||
$builtinTypes[] = $type->getBuiltinType();
|
||||
|
||||
if ($scalar && !\in_array($type->getBuiltinType(), [PropertyInfoType::BUILTIN_TYPE_INT, PropertyInfoType::BUILTIN_TYPE_FLOAT, PropertyInfoType::BUILTIN_TYPE_STRING, PropertyInfoType::BUILTIN_TYPE_BOOL], true)) {
|
||||
$scalar = false;
|
||||
}
|
||||
|
||||
if (!$nullable && $type->isNullable()) {
|
||||
$nullable = true;
|
||||
}
|
||||
}
|
||||
if (!$hasTypeConstraint) {
|
||||
if (1 === \count($builtinTypes)) {
|
||||
if ($types[0]->isCollection() && \count($collectionValueType = $types[0]->getCollectionValueTypes()) > 0) {
|
||||
[$collectionValueType] = $collectionValueType;
|
||||
$this->handleAllConstraint($property, $allConstraint, $collectionValueType, $metadata);
|
||||
}
|
||||
|
||||
$metadata->addPropertyConstraint($property, $this->getTypeConstraint($builtinTypes[0], $types[0]));
|
||||
} elseif ($scalar) {
|
||||
$metadata->addPropertyConstraint($property, new Type(['type' => 'scalar']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!$nullable && !$hasNotBlankConstraint && !$hasNotNullConstraint) {
|
||||
$metadata->addPropertyConstraint($property, new NotNull());
|
||||
}
|
||||
}
|
||||
|
||||
return $loaded;
|
||||
}
|
||||
|
||||
private function getTypeConstraint(string $builtinType, PropertyInfoType $type): Type
|
||||
{
|
||||
if (PropertyInfoType::BUILTIN_TYPE_OBJECT === $builtinType && null !== $className = $type->getClassName()) {
|
||||
return new Type(['type' => $className]);
|
||||
}
|
||||
|
||||
return new Type(['type' => $builtinType]);
|
||||
}
|
||||
|
||||
private function handleAllConstraint(string $property, ?All $allConstraint, PropertyInfoType $propertyInfoType, ClassMetadata $metadata)
|
||||
{
|
||||
$containsTypeConstraint = false;
|
||||
$containsNotNullConstraint = false;
|
||||
if (null !== $allConstraint) {
|
||||
foreach ($allConstraint->constraints as $constraint) {
|
||||
if ($constraint instanceof Type) {
|
||||
$containsTypeConstraint = true;
|
||||
} elseif ($constraint instanceof NotNull) {
|
||||
$containsNotNullConstraint = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$constraints = [];
|
||||
if (!$containsNotNullConstraint && !$propertyInfoType->isNullable()) {
|
||||
$constraints[] = new NotNull();
|
||||
}
|
||||
|
||||
if (!$containsTypeConstraint) {
|
||||
$constraints[] = $this->getTypeConstraint($propertyInfoType->getBuiltinType(), $propertyInfoType);
|
||||
}
|
||||
|
||||
if (null === $allConstraint) {
|
||||
$metadata->addPropertyConstraint($property, new All(['constraints' => $constraints]));
|
||||
} else {
|
||||
$allConstraint->constraints = array_merge($allConstraint->constraints, $constraints);
|
||||
}
|
||||
}
|
||||
}
|
66
vendor/symfony/validator/Mapping/Loader/StaticMethodLoader.php
vendored
Normal file
66
vendor/symfony/validator/Mapping/Loader/StaticMethodLoader.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Loads validation metadata by calling a static method on the loaded class.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class StaticMethodLoader implements LoaderInterface
|
||||
{
|
||||
protected $methodName;
|
||||
|
||||
/**
|
||||
* Creates a new loader.
|
||||
*
|
||||
* @param string $methodName The name of the static method to call
|
||||
*/
|
||||
public function __construct(string $methodName = 'loadValidatorMetadata')
|
||||
{
|
||||
$this->methodName = $methodName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
/** @var \ReflectionClass $reflClass */
|
||||
$reflClass = $metadata->getReflectionClass();
|
||||
|
||||
if (!$reflClass->isInterface() && $reflClass->hasMethod($this->methodName)) {
|
||||
$reflMethod = $reflClass->getMethod($this->methodName);
|
||||
|
||||
if ($reflMethod->isAbstract()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$reflMethod->isStatic()) {
|
||||
throw new MappingException(sprintf('The method "%s::%s()" should be static.', $reflClass->name, $this->methodName));
|
||||
}
|
||||
|
||||
if ($reflMethod->getDeclaringClass()->name != $reflClass->name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$reflMethod->invoke(null, $metadata);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
231
vendor/symfony/validator/Mapping/Loader/XmlFileLoader.php
vendored
Normal file
231
vendor/symfony/validator/Mapping/Loader/XmlFileLoader.php
vendored
Normal file
@ -0,0 +1,231 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Config\Util\XmlUtils;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Exception\MappingException;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
|
||||
/**
|
||||
* Loads validation metadata from an XML file.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class XmlFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* The XML nodes of the mapping file.
|
||||
*
|
||||
* @var \SimpleXMLElement[]|null
|
||||
*/
|
||||
protected $classes;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
if (null === $this->classes) {
|
||||
$this->loadClassesFromXml();
|
||||
}
|
||||
|
||||
if (isset($this->classes[$metadata->getClassName()])) {
|
||||
$classDescription = $this->classes[$metadata->getClassName()];
|
||||
|
||||
$this->loadClassMetadataFromXml($metadata, $classDescription);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of the classes mapped in this file.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMappedClasses()
|
||||
{
|
||||
if (null === $this->classes) {
|
||||
$this->loadClassesFromXml();
|
||||
}
|
||||
|
||||
return array_keys($this->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a collection of "constraint" XML nodes.
|
||||
*
|
||||
* @param \SimpleXMLElement $nodes The XML nodes
|
||||
*
|
||||
* @return Constraint[]
|
||||
*/
|
||||
protected function parseConstraints(\SimpleXMLElement $nodes)
|
||||
{
|
||||
$constraints = [];
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if (\count($node) > 0) {
|
||||
if (\count($node->value) > 0) {
|
||||
$options = $this->parseValues($node->value);
|
||||
} elseif (\count($node->constraint) > 0) {
|
||||
$options = $this->parseConstraints($node->constraint);
|
||||
} elseif (\count($node->option) > 0) {
|
||||
$options = $this->parseOptions($node->option);
|
||||
} else {
|
||||
$options = [];
|
||||
}
|
||||
} elseif ('' !== (string) $node) {
|
||||
$options = XmlUtils::phpize(trim($node));
|
||||
} else {
|
||||
$options = null;
|
||||
}
|
||||
|
||||
$constraints[] = $this->newConstraint((string) $node['name'], $options);
|
||||
}
|
||||
|
||||
return $constraints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a collection of "value" XML nodes.
|
||||
*
|
||||
* @param \SimpleXMLElement $nodes The XML nodes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseValues(\SimpleXMLElement $nodes)
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if (\count($node) > 0) {
|
||||
if (\count($node->value) > 0) {
|
||||
$value = $this->parseValues($node->value);
|
||||
} elseif (\count($node->constraint) > 0) {
|
||||
$value = $this->parseConstraints($node->constraint);
|
||||
} else {
|
||||
$value = [];
|
||||
}
|
||||
} else {
|
||||
$value = trim($node);
|
||||
}
|
||||
|
||||
if (isset($node['key'])) {
|
||||
$values[(string) $node['key']] = $value;
|
||||
} else {
|
||||
$values[] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a collection of "option" XML nodes.
|
||||
*
|
||||
* @param \SimpleXMLElement $nodes The XML nodes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseOptions(\SimpleXMLElement $nodes)
|
||||
{
|
||||
$options = [];
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
if (\count($node) > 0) {
|
||||
if (\count($node->value) > 0) {
|
||||
$value = $this->parseValues($node->value);
|
||||
} elseif (\count($node->constraint) > 0) {
|
||||
$value = $this->parseConstraints($node->constraint);
|
||||
} else {
|
||||
$value = [];
|
||||
}
|
||||
} else {
|
||||
$value = XmlUtils::phpize($node);
|
||||
if (\is_string($value)) {
|
||||
$value = trim($value);
|
||||
}
|
||||
}
|
||||
|
||||
$options[(string) $node['name']] = $value;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the XML class descriptions from the given file.
|
||||
*
|
||||
* @return \SimpleXMLElement
|
||||
*
|
||||
* @throws MappingException If the file could not be loaded
|
||||
*/
|
||||
protected function parseFile(string $path)
|
||||
{
|
||||
try {
|
||||
$dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');
|
||||
} catch (\Exception $e) {
|
||||
throw new MappingException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
return simplexml_import_dom($dom);
|
||||
}
|
||||
|
||||
private function loadClassesFromXml()
|
||||
{
|
||||
// This method may throw an exception. Do not modify the class'
|
||||
// state before it completes
|
||||
$xml = $this->parseFile($this->file);
|
||||
|
||||
$this->classes = [];
|
||||
|
||||
foreach ($xml->namespace as $namespace) {
|
||||
$this->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace));
|
||||
}
|
||||
|
||||
foreach ($xml->class as $class) {
|
||||
$this->classes[(string) $class['name']] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadClassMetadataFromXml(ClassMetadata $metadata, \SimpleXMLElement $classDescription)
|
||||
{
|
||||
if (\count($classDescription->{'group-sequence-provider'}) > 0) {
|
||||
$metadata->setGroupSequenceProvider(true);
|
||||
}
|
||||
|
||||
foreach ($classDescription->{'group-sequence'} as $groupSequence) {
|
||||
if (\count($groupSequence->value) > 0) {
|
||||
$metadata->setGroupSequence($this->parseValues($groupSequence[0]->value));
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->parseConstraints($classDescription->constraint) as $constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
}
|
||||
|
||||
foreach ($classDescription->property as $property) {
|
||||
foreach ($this->parseConstraints($property->constraint) as $constraint) {
|
||||
$metadata->addPropertyConstraint((string) $property['name'], $constraint);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($classDescription->getter as $getter) {
|
||||
foreach ($this->parseConstraints($getter->constraint) as $constraint) {
|
||||
$metadata->addGetterConstraint((string) $getter['property'], $constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
vendor/symfony/validator/Mapping/Loader/XmlFilesLoader.php
vendored
Normal file
31
vendor/symfony/validator/Mapping/Loader/XmlFilesLoader.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Loader;
|
||||
|
||||
/**
|
||||
* Loads validation metadata from a list of XML files.
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see FilesLoader
|
||||
*/
|
||||
class XmlFilesLoader extends FilesLoader
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFileLoaderInstance(string $file)
|
||||
{
|
||||
return new XmlFileLoader($file);
|
||||
}
|
||||
}
|
189
vendor/symfony/validator/Mapping/Loader/YamlFileLoader.php
vendored
Normal file
189
vendor/symfony/validator/Mapping/Loader/YamlFileLoader.php
vendored
Normal file
@ -0,0 +1,189 @@
|
||||
<?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\Loader;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadata;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Parser as YamlParser;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
* Loads validation metadata from a YAML file.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*/
|
||||
class YamlFileLoader extends FileLoader
|
||||
{
|
||||
/**
|
||||
* An array of YAML class descriptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $classes = null;
|
||||
|
||||
/**
|
||||
* Caches the used YAML parser.
|
||||
*
|
||||
* @var YamlParser
|
||||
*/
|
||||
private $yamlParser;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function loadClassMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
if (null === $this->classes) {
|
||||
$this->loadClassesFromYaml();
|
||||
}
|
||||
|
||||
if (isset($this->classes[$metadata->getClassName()])) {
|
||||
$classDescription = $this->classes[$metadata->getClassName()];
|
||||
|
||||
$this->loadClassMetadataFromYaml($metadata, $classDescription);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the names of the classes mapped in this file.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMappedClasses()
|
||||
{
|
||||
if (null === $this->classes) {
|
||||
$this->loadClassesFromYaml();
|
||||
}
|
||||
|
||||
return array_keys($this->classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a collection of YAML nodes.
|
||||
*
|
||||
* @param array $nodes The YAML nodes
|
||||
*
|
||||
* @return array<array|scalar|Constraint>
|
||||
*/
|
||||
protected function parseNodes(array $nodes)
|
||||
{
|
||||
$values = [];
|
||||
|
||||
foreach ($nodes as $name => $childNodes) {
|
||||
if (is_numeric($name) && \is_array($childNodes) && 1 === \count($childNodes)) {
|
||||
$options = current($childNodes);
|
||||
|
||||
if (\is_array($options)) {
|
||||
$options = $this->parseNodes($options);
|
||||
}
|
||||
|
||||
$values[] = $this->newConstraint(key($childNodes), $options);
|
||||
} else {
|
||||
if (\is_array($childNodes)) {
|
||||
$childNodes = $this->parseNodes($childNodes);
|
||||
}
|
||||
|
||||
$values[$name] = $childNodes;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the YAML class descriptions from the given file.
|
||||
*
|
||||
* @throws \InvalidArgumentException If the file could not be loaded or did
|
||||
* not contain a YAML array
|
||||
*/
|
||||
private function parseFile(string $path): array
|
||||
{
|
||||
try {
|
||||
$classes = $this->yamlParser->parseFile($path, Yaml::PARSE_CONSTANT);
|
||||
} catch (ParseException $e) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML: ', $path).$e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
// empty file
|
||||
if (null === $classes) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// not an array
|
||||
if (!\is_array($classes)) {
|
||||
throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $this->file));
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
private function loadClassesFromYaml()
|
||||
{
|
||||
if (null === $this->yamlParser) {
|
||||
$this->yamlParser = new YamlParser();
|
||||
}
|
||||
|
||||
$this->classes = $this->parseFile($this->file);
|
||||
|
||||
if (isset($this->classes['namespaces'])) {
|
||||
foreach ($this->classes['namespaces'] as $alias => $namespace) {
|
||||
$this->addNamespaceAlias($alias, $namespace);
|
||||
}
|
||||
|
||||
unset($this->classes['namespaces']);
|
||||
}
|
||||
}
|
||||
|
||||
private function loadClassMetadataFromYaml(ClassMetadata $metadata, array $classDescription)
|
||||
{
|
||||
if (isset($classDescription['group_sequence_provider'])) {
|
||||
$metadata->setGroupSequenceProvider(
|
||||
(bool) $classDescription['group_sequence_provider']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($classDescription['group_sequence'])) {
|
||||
$metadata->setGroupSequence($classDescription['group_sequence']);
|
||||
}
|
||||
|
||||
if (isset($classDescription['constraints']) && \is_array($classDescription['constraints'])) {
|
||||
foreach ($this->parseNodes($classDescription['constraints']) as $constraint) {
|
||||
$metadata->addConstraint($constraint);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($classDescription['properties']) && \is_array($classDescription['properties'])) {
|
||||
foreach ($classDescription['properties'] as $property => $constraints) {
|
||||
if (null !== $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addPropertyConstraint($property, $constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($classDescription['getters']) && \is_array($classDescription['getters'])) {
|
||||
foreach ($classDescription['getters'] as $getter => $constraints) {
|
||||
if (null !== $constraints) {
|
||||
foreach ($this->parseNodes($constraints) as $constraint) {
|
||||
$metadata->addGetterConstraint($getter, $constraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
31
vendor/symfony/validator/Mapping/Loader/YamlFilesLoader.php
vendored
Normal file
31
vendor/symfony/validator/Mapping/Loader/YamlFilesLoader.php
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
<?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\Loader;
|
||||
|
||||
/**
|
||||
* Loads validation metadata from a list of YAML files.
|
||||
*
|
||||
* @author Bulat Shakirzyanov <mallluhuct@gmail.com>
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see FilesLoader
|
||||
*/
|
||||
class YamlFilesLoader extends FilesLoader
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFileLoaderInstance(string $file)
|
||||
{
|
||||
return new YamlFileLoader($file);
|
||||
}
|
||||
}
|
160
vendor/symfony/validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd
vendored
Normal file
160
vendor/symfony/validator/Mapping/Loader/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd
vendored
Normal file
@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" ?>
|
||||
|
||||
<xsd:schema xmlns="http://symfony.com/schema/dic/constraint-mapping"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
targetNamespace="http://symfony.com/schema/dic/constraint-mapping"
|
||||
elementFormDefault="qualified">
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Symfony Validator Constraint Mapping Schema, version 1.0
|
||||
Authors: Bernhard Schussek
|
||||
|
||||
A constraint mapping connects classes, properties and getters with
|
||||
validation constraints.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:element name="constraint-mapping" type="constraint-mapping" />
|
||||
|
||||
<xsd:complexType name="constraint-mapping">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The root element of the constraint mapping definition.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="namespace" type="namespace" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="class" type="class" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="namespace">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains the abbreviation for a namespace.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleContent>
|
||||
<xsd:extension base="xsd:string">
|
||||
<xsd:attribute name="prefix" type="xsd:string" use="required" />
|
||||
</xsd:extension>
|
||||
</xsd:simpleContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="class">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains constraints for a single class.
|
||||
|
||||
Nested elements may be class constraints, property and/or getter
|
||||
definitions.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:choice minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="group-sequence-provider" type="group-sequence-provider" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="group-sequence" type="group-sequence" minOccurs="0" maxOccurs="1" />
|
||||
<xsd:element name="constraint" type="constraint" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="property" type="property" minOccurs="0" maxOccurs="unbounded" />
|
||||
<xsd:element name="getter" type="getter" minOccurs="0" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="group-sequence">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains the group sequence of a class. Each group should be written
|
||||
into a "value" tag.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="group-sequence-provider">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines the name of the group sequence provider for a class.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="property">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains constraints for a single property. The name of the property
|
||||
should be given in the "name" option.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="constraint" type="constraint" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="getter">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains constraints for a getter method. The name of the corresponding
|
||||
property should be given in the "property" option.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="constraint" type="constraint" maxOccurs="unbounded" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="property" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="constraint" mixed="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains a constraint definition. The name of the constraint should be
|
||||
given in the "name" option.
|
||||
|
||||
May contain a single value, multiple "constraint" elements,
|
||||
multiple "value" elements or multiple "option" elements.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="constraint" type="constraint" minOccurs="1" maxOccurs="unbounded" />
|
||||
<xsd:element name="option" type="option" minOccurs="1" maxOccurs="unbounded" />
|
||||
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="option" mixed="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Contains a constraint option definition. The name of the option
|
||||
should be given in the "name" option.
|
||||
|
||||
May contain a single value, multiple "value" elements or multiple
|
||||
"constraint" elements.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="constraint" type="constraint" minOccurs="1" maxOccurs="unbounded" />
|
||||
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="value" mixed="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
A value of an element.
|
||||
|
||||
May contain a single value, multiple "value" elements or multiple
|
||||
"constraint" elements.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:choice minOccurs="0">
|
||||
<xsd:element name="constraint" type="constraint" minOccurs="1" maxOccurs="unbounded" />
|
||||
<xsd:element name="value" type="value" minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
<xsd:attribute name="key" type="xsd:string" use="optional" />
|
||||
</xsd:complexType>
|
||||
</xsd:schema>
|
194
vendor/symfony/validator/Mapping/MemberMetadata.php
vendored
Normal file
194
vendor/symfony/validator/Mapping/MemberMetadata.php
vendored
Normal file
@ -0,0 +1,194 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\Constraints\Composite;
|
||||
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
||||
|
||||
/**
|
||||
* Stores all metadata needed for validating a class property.
|
||||
*
|
||||
* The method of accessing the property's value must be specified by subclasses
|
||||
* by implementing the {@link newReflectionMember()} method.
|
||||
*
|
||||
* This class supports serialization and cloning.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see PropertyMetadataInterface
|
||||
*/
|
||||
abstract class MemberMetadata extends GenericMetadata implements PropertyMetadataInterface
|
||||
{
|
||||
/**
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getClassName()} instead.
|
||||
*/
|
||||
public $class;
|
||||
|
||||
/**
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getName()} instead.
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @internal This property is public in order to reduce the size of the
|
||||
* class' serialized representation. Do not access it. Use
|
||||
* {@link getPropertyName()} instead.
|
||||
*/
|
||||
public $property;
|
||||
|
||||
/**
|
||||
* @var \ReflectionMethod[]|\ReflectionProperty[]
|
||||
*/
|
||||
private $reflMember = [];
|
||||
|
||||
/**
|
||||
* @param string $class The name of the class this member is defined on
|
||||
* @param string $name The name of the member
|
||||
* @param string $property The property the member belongs to
|
||||
*/
|
||||
public function __construct(string $class, string $name, string $property)
|
||||
{
|
||||
$this->class = $class;
|
||||
$this->name = $name;
|
||||
$this->property = $property;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addConstraint(Constraint $constraint)
|
||||
{
|
||||
$this->checkConstraint($constraint);
|
||||
|
||||
parent::addConstraint($constraint);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __sleep()
|
||||
{
|
||||
return array_merge(parent::__sleep(), [
|
||||
'class',
|
||||
'name',
|
||||
'property',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the member.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPropertyName()
|
||||
{
|
||||
return $this->property;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this member is public.
|
||||
*
|
||||
* @param object|string $objectOrClassName The object or the class name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPublic($objectOrClassName)
|
||||
{
|
||||
return $this->getReflectionMember($objectOrClassName)->isPublic();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this member is protected.
|
||||
*
|
||||
* @param object|string $objectOrClassName The object or the class name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProtected($objectOrClassName)
|
||||
{
|
||||
return $this->getReflectionMember($objectOrClassName)->isProtected();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this member is private.
|
||||
*
|
||||
* @param object|string $objectOrClassName The object or the class name
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrivate($objectOrClassName)
|
||||
{
|
||||
return $this->getReflectionMember($objectOrClassName)->isPrivate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the reflection instance for accessing the member's value.
|
||||
*
|
||||
* @param object|string $objectOrClassName The object or the class name
|
||||
*
|
||||
* @return \ReflectionMethod|\ReflectionProperty
|
||||
*/
|
||||
public function getReflectionMember($objectOrClassName)
|
||||
{
|
||||
$className = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
|
||||
if (!isset($this->reflMember[$className])) {
|
||||
$this->reflMember[$className] = $this->newReflectionMember($objectOrClassName);
|
||||
}
|
||||
|
||||
return $this->reflMember[$className];
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new reflection instance for accessing the member's value.
|
||||
*
|
||||
* @param object|string $objectOrClassName The object or the class name
|
||||
*
|
||||
* @return \ReflectionMethod|\ReflectionProperty
|
||||
*/
|
||||
abstract protected function newReflectionMember($objectOrClassName);
|
||||
|
||||
private function checkConstraint(Constraint $constraint)
|
||||
{
|
||||
if (!\in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets(), true)) {
|
||||
throw new ConstraintDefinitionException(sprintf('The constraint "%s" cannot be put on properties or getters.', get_debug_type($constraint)));
|
||||
}
|
||||
|
||||
if ($constraint instanceof Composite) {
|
||||
foreach ($constraint->getNestedConstraints() as $nestedConstraint) {
|
||||
$this->checkConstraint($nestedConstraint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
66
vendor/symfony/validator/Mapping/MetadataInterface.php
vendored
Normal file
66
vendor/symfony/validator/Mapping/MetadataInterface.php
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* A container for validation metadata.
|
||||
*
|
||||
* Most importantly, the metadata stores the constraints against which an object
|
||||
* and its properties should be validated.
|
||||
*
|
||||
* Additionally, the metadata stores whether objects should be validated
|
||||
* against their class' metadata and whether traversable objects should be
|
||||
* traversed or not.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see CascadingStrategy
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
interface MetadataInterface
|
||||
{
|
||||
/**
|
||||
* Returns the strategy for cascading objects.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @see CascadingStrategy
|
||||
*/
|
||||
public function getCascadingStrategy();
|
||||
|
||||
/**
|
||||
* Returns the strategy for traversing traversable objects.
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
public function getTraversalStrategy();
|
||||
|
||||
/**
|
||||
* Returns all constraints of this element.
|
||||
*
|
||||
* @return Constraint[]
|
||||
*/
|
||||
public function getConstraints();
|
||||
|
||||
/**
|
||||
* Returns all constraints for a given validation group.
|
||||
*
|
||||
* @param string $group The validation group
|
||||
*
|
||||
* @return Constraint[]
|
||||
*/
|
||||
public function findConstraints(string $group);
|
||||
}
|
93
vendor/symfony/validator/Mapping/PropertyMetadata.php
vendored
Normal file
93
vendor/symfony/validator/Mapping/PropertyMetadata.php
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
<?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;
|
||||
|
||||
use Symfony\Component\Validator\Exception\ValidatorException;
|
||||
|
||||
/**
|
||||
* Stores all metadata needed for validating a class property.
|
||||
*
|
||||
* The value of the property is obtained by directly accessing the property.
|
||||
* The property will be accessed by reflection, so the access of private and
|
||||
* protected properties is supported.
|
||||
*
|
||||
* This class supports serialization and cloning.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see PropertyMetadataInterface
|
||||
*/
|
||||
class PropertyMetadata extends MemberMetadata
|
||||
{
|
||||
/**
|
||||
* @param string $class The class this property is defined on
|
||||
* @param string $name The name of this property
|
||||
*
|
||||
* @throws ValidatorException
|
||||
*/
|
||||
public function __construct(string $class, string $name)
|
||||
{
|
||||
if (!property_exists($class, $name)) {
|
||||
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s".', $name, $class));
|
||||
}
|
||||
|
||||
parent::__construct($class, $name, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getPropertyValue($object)
|
||||
{
|
||||
$reflProperty = $this->getReflectionMember($object);
|
||||
|
||||
if (\PHP_VERSION_ID >= 70400 && $reflProperty->hasType() && !$reflProperty->isInitialized($object)) {
|
||||
// There is no way to check if a property has been unset or if it is uninitialized.
|
||||
// When trying to access an uninitialized property, __get method is triggered.
|
||||
|
||||
// If __get method is not present, no fallback is possible
|
||||
// Otherwise we need to catch an Error in case we are trying to access an uninitialized but set property.
|
||||
if (!method_exists($object, '__get')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $reflProperty->getValue($object);
|
||||
} catch (\Error $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return $reflProperty->getValue($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function newReflectionMember($objectOrClassName)
|
||||
{
|
||||
$originalClass = \is_string($objectOrClassName) ? $objectOrClassName : \get_class($objectOrClassName);
|
||||
|
||||
while (!property_exists($objectOrClassName, $this->getName())) {
|
||||
$objectOrClassName = get_parent_class($objectOrClassName);
|
||||
|
||||
if (false === $objectOrClassName) {
|
||||
throw new ValidatorException(sprintf('Property "%s" does not exist in class "%s".', $this->getName(), $originalClass));
|
||||
}
|
||||
}
|
||||
|
||||
$member = new \ReflectionProperty($objectOrClassName, $this->getName());
|
||||
$member->setAccessible(true);
|
||||
|
||||
return $member;
|
||||
}
|
||||
}
|
47
vendor/symfony/validator/Mapping/PropertyMetadataInterface.php
vendored
Normal file
47
vendor/symfony/validator/Mapping/PropertyMetadataInterface.php
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Stores all metadata needed for validating the value of a class property.
|
||||
*
|
||||
* Most importantly, the metadata stores the constraints against which the
|
||||
* property's value should be validated.
|
||||
*
|
||||
* Additionally, the metadata stores whether objects stored in the property
|
||||
* should be validated against their class' metadata and whether traversable
|
||||
* objects should be traversed or not.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see MetadataInterface
|
||||
* @see CascadingStrategy
|
||||
* @see TraversalStrategy
|
||||
*/
|
||||
interface PropertyMetadataInterface extends MetadataInterface
|
||||
{
|
||||
/**
|
||||
* Returns the name of the property.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPropertyName();
|
||||
|
||||
/**
|
||||
* Extracts the value of the property from the given container.
|
||||
*
|
||||
* @param mixed $containingValue The container to extract the property value from
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPropertyValue($containingValue);
|
||||
}
|
55
vendor/symfony/validator/Mapping/TraversalStrategy.php
vendored
Normal file
55
vendor/symfony/validator/Mapping/TraversalStrategy.php
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* Specifies whether and how a traversable object should be traversed.
|
||||
*
|
||||
* If the node traverser traverses a node whose value is an instance of
|
||||
* {@link \Traversable}, and if that node is either a class node or if
|
||||
* cascading is enabled, then the node's traversal strategy will be checked.
|
||||
* Depending on the requested traversal strategy, the node traverser will
|
||||
* iterate over the object and cascade each object or collection returned by
|
||||
* the iterator.
|
||||
*
|
||||
* The traversal strategy is ignored for arrays. Arrays are always iterated.
|
||||
*
|
||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||
*
|
||||
* @see CascadingStrategy
|
||||
*/
|
||||
class TraversalStrategy
|
||||
{
|
||||
/**
|
||||
* Specifies that a node's value should be iterated only if it is an
|
||||
* instance of {@link \Traversable}.
|
||||
*/
|
||||
public const IMPLICIT = 1;
|
||||
|
||||
/**
|
||||
* Specifies that a node's value should never be iterated.
|
||||
*/
|
||||
public const NONE = 2;
|
||||
|
||||
/**
|
||||
* Specifies that a node's value should always be iterated. If the value is
|
||||
* not an instance of {@link \Traversable}, an exception should be thrown.
|
||||
*/
|
||||
public const TRAVERSE = 4;
|
||||
|
||||
/**
|
||||
* Not instantiable.
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user