/** * {@inheritDoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = array(); $xml = $this->parseFile($this->file); foreach ($xml->namespace as $namespace) { $this->namespaces[(string) $namespace['prefix']] = trim((string) $namespace); } foreach ($xml->class as $class) { $this->classes[(string) $class['name']] = $class; } } if (isset($this->classes[$metadata->getClassName()])) { $xml = $this->classes[$metadata->getClassName()]; foreach ($this->parseConstraints($xml->constraint) as $constraint) { $metadata->addConstraint($constraint); } foreach ($xml->property as $property) { foreach ($this->parseConstraints($property->constraint) as $constraint) { $metadata->addPropertyConstraint((string) $property['name'], $constraint); } } foreach ($xml->getter as $getter) { foreach ($this->parseConstraints($getter->constraint) as $constraint) { $metadata->addGetterConstraint((string) $getter['property'], $constraint); } } return true; } return false; }
/** * {@inheritDoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = Yaml::load($this->file); } // TODO validation if (isset($this->classes[$metadata->getClassName()])) { $yaml = $this->classes[$metadata->getClassName()]; if (isset($yaml['constraints'])) { foreach ($this->parseNodes($yaml['constraints']) as $constraint) { $metadata->addConstraint($constraint); } } if (isset($yaml['properties'])) { foreach ($yaml['properties'] as $property => $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addPropertyConstraint($property, $constraint); } } } if (isset($yaml['getters'])) { foreach ($yaml['getters'] as $getter => $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addGetterConstraint($getter, $constraint); } } } return true; } return false; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { if (null === $this->yamlParser) { $this->yamlParser = new YamlParser(); } // This method may throw an exception. Do not modify the class' // state before it completes if (false === ($classes = $this->parseFile($this->file))) { return false; } $this->classes = $classes; if (isset($this->classes['namespaces'])) { foreach ($this->classes['namespaces'] as $alias => $namespace) { $this->addNamespaceAlias($alias, $namespace); } unset($this->classes['namespaces']); } } if (isset($this->classes[$metadata->getClassName()])) { $classDescription = $this->classes[$metadata->getClassName()]; $this->loadClassMetadataFromYaml($metadata, $classDescription); return true; } return false; }
/** * {@inheritDoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = Yaml::parse($this->file); // empty file if (null === $this->classes) { return false; } // not an array if (!is_array($this->classes)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $this->file)); } if (isset($this->classes['namespaces'])) { foreach ($this->classes['namespaces'] as $alias => $namespace) { $this->addNamespaceAlias($alias, $namespace); } unset($this->classes['namespaces']); } } // TODO validation if (isset($this->classes[$metadata->getClassName()])) { $yaml = $this->classes[$metadata->getClassName()]; if (isset($yaml['group_sequence_provider'])) { $metadata->setGroupSequenceProvider((bool) $yaml['group_sequence_provider']); } if (isset($yaml['group_sequence'])) { $metadata->setGroupSequence($yaml['group_sequence']); } if (isset($yaml['constraints']) && is_array($yaml['constraints'])) { foreach ($this->parseNodes($yaml['constraints']) as $constraint) { $metadata->addConstraint($constraint); } } if (isset($yaml['properties']) && is_array($yaml['properties'])) { foreach ($yaml['properties'] as $property => $constraints) { if (null !== $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addPropertyConstraint($property, $constraint); } } } } if (isset($yaml['getters']) && is_array($yaml['getters'])) { foreach ($yaml['getters'] as $getter => $constraints) { if (null !== $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addGetterConstraint($getter, $constraint); } } } } return true; } return false; }
/** * {@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; }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { // This method may throw an exception. Do not modify the class' // state before it completes $xml = $this->parseFile($this->file); $this->classes = array(); foreach ($xml->namespace as $namespace) { $this->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace)); } foreach ($xml->class as $class) { $this->classes[(string) $class['name']] = $class; } } if (isset($this->classes[$metadata->getClassName()])) { $classDescription = $this->classes[$metadata->getClassName()]; $this->loadClassMetadataFromXml($metadata, $classDescription); return true; } return false; }
/** * {@inheritDoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = Yaml::load($this->file); } // empty file if (null === $this->classes) { return false; } // not an array if (!is_array($this->classes)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a YAML array.', $this->file)); } // TODO validation if (isset($this->classes[$metadata->getClassName()])) { $yaml = $this->classes[$metadata->getClassName()]; if (isset($yaml['constraints'])) { foreach ($this->parseNodes($yaml['constraints']) as $constraint) { $metadata->addConstraint($constraint); } } if (isset($yaml['properties'])) { foreach ($yaml['properties'] as $property => $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addPropertyConstraint($property, $constraint); } } } if (isset($yaml['getters'])) { foreach ($yaml['getters'] as $getter => $constraints) { foreach ($this->parseNodes($constraints) as $constraint) { $metadata->addGetterConstraint($getter, $constraint); } } } return true; } return false; }
public function walkClass(ClassMetadata $metadata, $object, $group, $propertyPath) { $this->context->setCurrentClass($metadata->getClassName()); foreach ($metadata->findConstraints($group) as $constraint) { $this->walkConstraint($constraint, $object, $group, $propertyPath); } if ($object !== null) { foreach ($metadata->getConstrainedProperties() as $property) { $localPropertyPath = empty($propertyPath) ? $property : $propertyPath . '.' . $property; $this->walkProperty($metadata, $property, $object, $group, $localPropertyPath); } } }
/** * {@inheritDoc} */ public function loadClassMetadata(ClassMetadata $metadata) { if (null === $this->classes) { $this->classes = array(); $xml = $this->parseFile($this->file); foreach ($xml->namespace as $namespace) { $this->addNamespaceAlias((string) $namespace['prefix'], trim((string) $namespace)); } foreach ($xml->class as $class) { $this->classes[(string) $class['name']] = $class; } } if (isset($this->classes[$metadata->getClassName()])) { $xml = $this->classes[$metadata->getClassName()]; foreach ($xml->{'group-sequence-provider'} as $provider) { $metadata->setGroupSequenceProvider(true); } foreach ($xml->{'group-sequence'} as $groupSequence) { if (count($groupSequence->value) > 0) { $metadata->setGroupSequence($this->parseValues($groupSequence[0]->value)); } } foreach ($this->parseConstraints($xml->constraint) as $constraint) { $metadata->addConstraint($constraint); } foreach ($xml->property as $property) { foreach ($this->parseConstraints($property->constraint) as $constraint) { $metadata->addPropertyConstraint((string) $property['name'], $constraint); } } foreach ($xml->getter as $getter) { foreach ($this->parseConstraints($getter->constraint) as $constraint) { $metadata->addGetterConstraint((string) $getter['property'], $constraint); } } return true; } return false; }
/** * Initialize validation on the given object using the given metadata * instance and validation group. * * @param ClassMetadata $metadata * @param object $object The object to validate * @param string $group The validator group to use for validation * @param string $propertyPath */ public function walkObject(ClassMetadata $metadata, $object, $group, $propertyPath) { $this->context->setCurrentClass($metadata->getClassName()); if ($group === Constraint::DEFAULT_GROUP && $metadata->hasGroupSequence()) { $groups = $metadata->getGroupSequence(); foreach ($groups as $group) { $this->walkObjectForGroup($metadata, $object, $group, $propertyPath, Constraint::DEFAULT_GROUP); if (count($this->getViolations()) > 0) { break; } } } else { $this->walkObjectForGroup($metadata, $object, $group, $propertyPath); } }
/** * Initialize validation on the given object using the given metadata * instance and validation group. * * @param ClassMetadata $metadata * @param object $object The object to validate * @param string $group The validator group to use for validation * @param string $propertyPath */ public function walkObject(ClassMetadata $metadata, $object, $group, $propertyPath) { foreach ($this->validatorInitializers as $initializer) { if (!$initializer instanceof ObjectInitializerInterface) { throw new \LogicException('Validator initializers must implement ObjectInitializerInterface.'); } $initializer->initialize($object); } $this->context->setCurrentClass($metadata->getClassName()); if ($group === Constraint::DEFAULT_GROUP && $metadata->hasGroupSequence()) { $groups = $metadata->getGroupSequence(); foreach ($groups as $group) { $this->walkObjectForGroup($metadata, $object, $group, $propertyPath, Constraint::DEFAULT_GROUP); if (count($this->getViolations()) > 0) { break; } } } else { $this->walkObjectForGroup($metadata, $object, $group, $propertyPath); } }
/** * {@inheritdoc} */ public function loadClassMetadata(ClassMetadata $metadata) { $className = $metadata->getClassName(); if (empty($this->constraintsMapping) || !$this->formConfigProvider->hasConfig($className)) { return false; } $formConfigs = $this->formConfigProvider->getConfigs($className); foreach ($formConfigs as $formConfig) { if (!$formConfig->is('is_enabled')) { continue; } /** @var FieldConfigId $fieldConfigId */ $fieldConfigId = $formConfig->getId(); $fieldName = $fieldConfigId->getFieldName(); if (!$this->isApplicable($className, $fieldName)) { continue; } $constraints = $this->getConstraintsByFieldType($fieldConfigId->getFieldType()); foreach ($constraints as $constraint) { $metadata->addPropertyConstraint($fieldName, $constraint); } } return true; }
public function addMetadata(ClassMetadata $metadata) { $this->metadatas[$metadata->getClassName()] = $metadata; }
protected function walkObjectForGroup(ClassMetadata $metadata, $object, $group, $propertyPath, $propagatedGroup = null) { $hash = spl_object_hash($object); // Exit, if the object is already validated for the current group if (isset($this->validatedObjects[$hash][$group])) { return; } // Remember validating this object before starting and possibly // traversing the object graph $this->validatedObjects[$hash][$group] = true; $currentClass = $metadata->getClassName(); foreach ($metadata->findConstraints($group) as $constraint) { $this->walkConstraint($constraint, $object, $group, $propertyPath, $currentClass); } if (null !== $object) { $pathPrefix = empty($propertyPath) ? '' : $propertyPath . '.'; foreach ($metadata->getConstrainedProperties() as $property) { $this->walkProperty($metadata, $property, $object, $group, $pathPrefix . $property, $propagatedGroup); } } }
public function write(ClassMetadata $metadata) { $this->cache[$metadata->getClassName()] = $metadata; }
/** * {@inheritdoc} */ public function write(ClassMetadata $metadata) { $item = $this->cacheItemPool->getItem($this->escapeClassName($metadata->getClassName())); $item->set($metadata); $this->cacheItemPool->save($item); }
/** * {@inheritdoc} */ public function write(ClassMetadata $metadata) { $item = $this->pool->getItem($this->normalizeKey($metadata->getClassName())); $item->set($metadata); $this->pool->save($item); }