use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Component\Validator\Mapping\CascadingStrategy;
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
+use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Mapping\GenericMetadata;
use Symfony\Component\Validator\Mapping\MetadataInterface;
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
use Symfony\Component\Validator\Mapping\TraversalStrategy;
-use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\ObjectInitializerInterface;
use Symfony\Component\Validator\Util\PropertyPath;
if (null !== $constraints) {
// You can pass a single constraint or an array of constraints
// Make sure to deal with an array in the rest of the code
- if (!is_array($constraints)) {
+ if (!\is_array($constraints)) {
$constraints = array($constraints);
}
$this->validateGenericNode(
$value,
$previousObject,
- is_object($value) ? spl_object_hash($value) : null,
+ \is_object($value) ? spl_object_hash($value) : null,
$metadata,
$this->defaultPropertyPath,
$groups,
// If an object is passed without explicit constraints, validate that
// object against the constraints defined for the object's class
- if (is_object($value)) {
+ if (\is_object($value)) {
$this->validateObject(
$value,
$this->defaultPropertyPath,
// If an array is passed without explicit constraints, validate each
// object in the array
- if (is_array($value)) {
+ if (\is_array($value)) {
$this->validateEachObjectIn(
$value,
$this->defaultPropertyPath,
return $this;
}
- throw new RuntimeException(sprintf(
- 'Cannot validate values of type "%s" automatically. Please '.
- 'provide a constraint.',
- gettype($value)
- ));
+ throw new RuntimeException(sprintf('Cannot validate values of type "%s" automatically. Please provide a constraint.', \gettype($value)));
}
/**
$classMetadata = $this->metadataFactory->getMetadataFor($object);
if (!$classMetadata instanceof ClassMetadataInterface) {
- throw new ValidatorException(sprintf(
- 'The metadata factory should return instances of '.
- '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
- 'got: "%s".',
- is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
- ));
+ throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}
$propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
$this->validateGenericNode(
$propertyValue,
$object,
- $cacheKey.':'.get_class($object).':'.$propertyName,
+ $cacheKey.':'.\get_class($object).':'.$propertyName,
$propertyMetadata,
$propertyPath,
$groups,
$classMetadata = $this->metadataFactory->getMetadataFor($objectOrClass);
if (!$classMetadata instanceof ClassMetadataInterface) {
- throw new ValidatorException(sprintf(
- 'The metadata factory should return instances of '.
- '"\Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
- 'got: "%s".',
- is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
- ));
+ throw new ValidatorException(sprintf('The metadata factory should return instances of "\Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}
$propertyMetadatas = $classMetadata->getPropertyMetadata($propertyName);
$groups = $groups ? $this->normalizeGroups($groups) : $this->defaultGroups;
- if (is_object($objectOrClass)) {
+ if (\is_object($objectOrClass)) {
$object = $objectOrClass;
- $class = get_class($object);
+ $class = \get_class($object);
$cacheKey = spl_object_hash($objectOrClass);
$propertyPath = PropertyPath::append($this->defaultPropertyPath, $propertyName);
} else {
/**
* Normalizes the given group or list of groups to an array.
*
- * @param mixed $groups The groups to normalize
+ * @param string|GroupSequence|(string|GroupSequence)[] $groups The groups to normalize
*
- * @return array A group array
+ * @return (string|GroupSequence)[] A group array
*/
protected function normalizeGroups($groups)
{
- if (is_array($groups)) {
+ if (\is_array($groups)) {
return $groups;
}
*
* @param object $object The object to cascade
* @param string $propertyPath The current property path
- * @param string[] $groups The validated groups
+ * @param (string|GroupSequence)[] $groups The validated groups
* @param int $traversalStrategy The strategy for traversing the
* cascaded object
* @param ExecutionContextInterface $context The current execution context
$classMetadata = $this->metadataFactory->getMetadataFor($object);
if (!$classMetadata instanceof ClassMetadataInterface) {
- throw new UnsupportedMetadataException(sprintf(
- 'The metadata factory should return instances of '.
- '"Symfony\Component\Validator\Mapping\ClassMetadataInterface", '.
- 'got: "%s".',
- is_object($classMetadata) ? get_class($classMetadata) : gettype($classMetadata)
- ));
+ throw new UnsupportedMetadataException(sprintf('The metadata factory should return instances of "Symfony\Component\Validator\Mapping\ClassMetadataInterface", got: "%s".', \is_object($classMetadata) ? \get_class($classMetadata) : \gettype($classMetadata)));
}
$this->validateClassNode(
*
* @param iterable $collection The collection
* @param string $propertyPath The current property path
- * @param string[] $groups The validated groups
+ * @param (string|GroupSequence)[] $groups The validated groups
* @param ExecutionContextInterface $context The current execution context
*
* @see ClassNode
private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context)
{
foreach ($collection as $key => $value) {
- if (is_array($value)) {
+ if (\is_array($value)) {
// Arrays are always cascaded, independent of the specified
// traversal strategy
$this->validateEachObjectIn(
}
// Scalar and null values in the collection are ignored
- if (is_object($value)) {
+ if (\is_object($value)) {
$this->validateObject(
$value,
$propertyPath.'['.$key.']',
* the object
* @param string $propertyPath The property path leading
* to the object
- * @param string[] $groups The groups in which the
+ * @param (string|GroupSequence)[] $groups The groups in which the
* object should be validated
* @param string[]|null $cascadedGroups The groups in which
* cascaded objects should
$defaultOverridden = false;
// Use the object hash for group sequences
- $groupHash = is_object($group) ? spl_object_hash($group) : $group;
+ $groupHash = \is_object($group) ? spl_object_hash($group) : $group;
if ($context->isGroupValidated($cacheKey, $groupHash)) {
// Skip this group when validating the properties and when
// If no more groups should be validated for the property nodes,
// we can safely quit
- if (0 === count($groups)) {
+ if (0 === \count($groups)) {
return;
}
// returns two metadata objects, not just one
foreach ($metadata->getPropertyMetadata($propertyName) as $propertyMetadata) {
if (!$propertyMetadata instanceof PropertyMetadataInterface) {
- throw new UnsupportedMetadataException(sprintf(
- 'The property metadata instances should implement '.
- '"Symfony\Component\Validator\Mapping\PropertyMetadataInterface", '.
- 'got: "%s".',
- is_object($propertyMetadata) ? get_class($propertyMetadata) : gettype($propertyMetadata)
- ));
+ throw new UnsupportedMetadataException(sprintf('The property metadata instances should implement "Symfony\Component\Validator\Mapping\PropertyMetadataInterface", got: "%s".', \is_object($propertyMetadata) ? \get_class($propertyMetadata) : \gettype($propertyMetadata)));
}
$propertyValue = $propertyMetadata->getPropertyValue($object);
$this->validateGenericNode(
$propertyValue,
$object,
- $cacheKey.':'.get_class($object).':'.$propertyName,
+ $cacheKey.':'.\get_class($object).':'.$propertyName,
$propertyMetadata,
PropertyPath::append($propertyPath, $propertyName),
$groups,
// If TRAVERSE, fail if we have no Traversable
if (!$object instanceof \Traversable) {
- throw new ConstraintDefinitionException(sprintf(
- 'Traversal was enabled for "%s", but this class '.
- 'does not implement "\Traversable".',
- get_class($object)
- ));
+ throw new ConstraintDefinitionException(sprintf('Traversal was enabled for "%s", but this class does not implement "\Traversable".', \get_class($object)));
}
$this->validateEachObjectIn(
* value
* @param string $propertyPath The property path leading
* to the value
- * @param string[] $groups The groups in which the
+ * @param (string|GroupSequence)[] $groups The groups in which the
* value should be validated
* @param string[]|null $cascadedGroups The groups in which
* cascaded objects should
$this->validateInGroup($value, $cacheKey, $metadata, $group, $context);
}
- if (0 === count($groups)) {
+ if (0 === \count($groups)) {
return;
}
$cascadingStrategy = $metadata->getCascadingStrategy();
// Quit unless we have an array or a cascaded object
- if (!is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) {
+ if (!\is_array($value) && !($cascadingStrategy & CascadingStrategy::CASCADE)) {
return;
}
// The $cascadedGroups property is set, if the "Default" group is
// overridden by a group sequence
// See validateClassNode()
- $cascadedGroups = null !== $cascadedGroups && count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
+ $cascadedGroups = null !== $cascadedGroups && \count($cascadedGroups) > 0 ? $cascadedGroups : $groups;
- if (is_array($value)) {
+ if (\is_array($value)) {
// Arrays are always traversed, independent of the specified
// traversal strategy
$this->validateEachObjectIn(
*/
private function stepThroughGroupSequence($value, $object, $cacheKey, MetadataInterface $metadata = null, $propertyPath, $traversalStrategy, GroupSequence $groupSequence, $cascadedGroup, ExecutionContextInterface $context)
{
- $violationCount = count($context->getViolations());
+ $violationCount = \count($context->getViolations());
$cascadedGroups = $cascadedGroup ? array($cascadedGroup) : null;
foreach ($groupSequence->groups as $groupInSequence) {
}
// Abort sequence validation if a violation was generated
- if (count($context->getViolations()) > $violationCount) {
+ if (\count($context->getViolations()) > $violationCount) {
break;
}
}