Returns the factory for ClassMetadata instances
public getMetadataFactory ( ) : Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface | ||
return | Symfony\Component\Validator\Mapping\ClassMetadataFactoryInterface |
private function validateXApiValidator(ValidatorInterface $validator) { $metadataFactory = $validator->getMetadataFactory(); $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity')); $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Agent')); $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity')); $this->assertTrue($metadataFactory->hasMetadataFor('\\XApi\\Model\\Activity')); }
private function validateXApiValidator(ValidatorInterface $validator) { if ($validator instanceof MetadataFactoryInterface) { $metadataFactory = $validator; } else { $metadataFactory = $validator->getMetadataFactory(); } $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity')); $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Agent')); $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity')); $this->assertTrue($metadataFactory->hasMetadataFor('\\Xabbuh\\XApi\\Model\\Activity')); }
/** * @param ValidatorInterface|LegacyValidatorInterface $validator * * @throws UnexpectedTypeException If $validator is invalid */ public function __construct($validator) { // 2.5 API if ($validator instanceof ValidatorInterface) { $metadata = $validator->getMetadataFor('Symfony\\Component\\Form\\Form'); // 2.4 API } elseif ($validator instanceof LegacyValidatorInterface) { $metadata = $validator->getMetadataFactory()->getMetadataFor('Symfony\\Component\\Form\\Form'); } else { throw new UnexpectedTypeException($validator, 'Symfony\\Component\\Validator\\Validator\\ValidatorInterface or Symfony\\Component\\Validator\\ValidatorInterface'); } // Register the form constraints in the validator programmatically. // This functionality is required when using the Form component without // the DIC, where the XML file is loaded automatically. Thus the following // code must be kept synchronized with validation.xml /** @var $metadata ClassMetadata */ $metadata->addConstraint(new Form()); $metadata->addPropertyConstraint('children', new Valid()); $this->validator = $validator; }
/** * @param ValidatorInterface|LegacyValidatorInterface $validator * * @throws UnexpectedTypeException If $validator is invalid */ public function __construct($validator) { // 2.5 API if ($validator instanceof ValidatorInterface) { $metadata = $validator->getMetadataFor('Symfony\\Component\\Form\\Form'); // 2.4 API } elseif ($validator instanceof LegacyValidatorInterface) { @trigger_error('Passing an instance of Symfony\\Component\\Validator\\ValidatorInterface as argument to the ' . __METHOD__ . ' method is deprecated since version 2.8 and will be removed in 3.0. Use an implementation of Symfony\\Component\\Validator\\Validator\\ValidatorInterface instead', E_USER_DEPRECATED); $metadata = $validator->getMetadataFactory()->getMetadataFor('Symfony\\Component\\Form\\Form'); } else { throw new UnexpectedTypeException($validator, 'Symfony\\Component\\Validator\\Validator\\ValidatorInterface or Symfony\\Component\\Validator\\ValidatorInterface'); } // Register the form constraints in the validator programmatically. // This functionality is required when using the Form component without // the DIC, where the XML file is loaded automatically. Thus the following // code must be kept synchronized with validation.xml /* @var $metadata ClassMetadata */ $metadata->addConstraint(new Form()); $metadata->addPropertyConstraint('children', new Valid()); $this->validator = $validator; }
/** * Attach the inline validator to the model metadata, this must be done once per admin. */ protected function attachInlineValidator() { $admin = $this; // add the custom inline validation option // TODO: Remove conditional method when bumping requirements to SF 2.5+ if (method_exists($this->validator, 'getMetadataFor')) { $metadata = $this->validator->getMetadataFor($this->getClass()); } else { $metadata = $this->validator->getMetadataFactory()->getMetadataFor($this->getClass()); } $metadata->addConstraint(new InlineConstraint(array('service' => $this, 'method' => function (ErrorElement $errorElement, $object) use($admin) { /* @var \Sonata\AdminBundle\Admin\AdminInterface $admin */ // This avoid the main validation to be cascaded to children // The problem occurs when a model Page has a collection of Page as property if ($admin->hasSubject() && spl_object_hash($object) !== spl_object_hash($admin->getSubject())) { return; } $admin->validate($errorElement, $object); foreach ($admin->getExtensions() as $extension) { $extension->validate($admin, $errorElement, $object); } }, 'serializingWarning' => true))); }
public function testGetMetadataFactory() { $this->assertSame($this->metadataFactory, $this->validator->getMetadataFactory()); }
/** * {@inheritdoc} */ public function getFormBuilder() { $admin = $this; // add the custom inline validation option $metadata = $this->validator->getMetadataFactory()->getClassMetadata($this->getClass()); $metadata->addConstraint(new \Sonata\AdminBundle\Validator\Constraints\InlineConstraint(array('service' => $this, 'method' => function (ErrorElement $errorElement, $object) use($admin) { /* @var \Sonata\AdminBundle\Admin\AdminInterface $admin */ // This avoid the main validation to be cascaded to children // The problem occurs when a model Page has a collection of Page as property if ($admin->hasSubject() && spl_object_hash($object) !== spl_object_hash($admin->getSubject())) { return; } $admin->validate($errorElement, $object); foreach ($admin->getExtensions() as $extension) { $extension->validate($admin, $errorElement, $object); } }))); $this->formOptions['data_class'] = $this->getActiveSubClass() ?: $this->getClass(); $formBuilder = $this->getFormContractor()->getFormBuilder($this->getUniqid(), $this->formOptions); $this->defineFormBuilder($formBuilder); return $formBuilder; }
/** * Gets metadata from system using the entity class name * * @param string $className * * @return ClassMetadata * @codeCoverageIgnore */ protected function getMetadataFor($className) { return $this->validator->getMetadataFactory()->getMetadataFor($className); }
public function getMetadataFactory() { return $this->wrappedValidator->getMetadataFactory(); }
public function __construct(ValidatorInterface $validator) { $this->validator = $validator; $this->validatorMetadataFactory = $validator->getMetadataFactory(); }