当前位置: 首页>>代码示例>>PHP>>正文


PHP ValidatorInterface::getMetadataFor方法代码示例

本文整理汇总了PHP中Symfony\Component\Validator\ValidatorInterface::getMetadataFor方法的典型用法代码示例。如果您正苦于以下问题:PHP ValidatorInterface::getMetadataFor方法的具体用法?PHP ValidatorInterface::getMetadataFor怎么用?PHP ValidatorInterface::getMetadataFor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Validator\ValidatorInterface的用法示例。


在下文中一共展示了ValidatorInterface::getMetadataFor方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildView

 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $fieldName = $view->vars['full_name'];
     $parentForm = $form->getParent();
     if (!empty($parentForm)) {
         $config = $parentForm->getConfig();
         $options = $config->getOptions();
         $validationGroups = $options['validation_groups'];
         $dataClass = $config->getDataClass();
         $entityMetadata = $dataClass !== null ? $this->validator->getMetadataFor($dataClass) : null;
         $view->vars['entity_constraints'] = $this->prepareConstraintsAttributes($fieldName, $entityMetadata, $validationGroups);
     }
 }
开发者ID:pvdleek,项目名称:UberFrontendValidationBundle,代码行数:16,代码来源:UberFrontendValidationFormExtension.php

示例2: testPrepareConstraintsAttributes

 /**
  * Test preparing array of constraints based on entity metadata
  */
 public function testPrepareConstraintsAttributes()
 {
     $entityMetadata = $this->validator->getMetadataFor('Sleepness\\UberFrontendValidationBundle\\Tests\\Fixtures\\Model\\Post');
     $reflectedMethod = new ReflectionMethod($this->extension, 'prepareConstraintsAttributes');
     $reflectedMethod->setAccessible(TRUE);
     $preparedConstraintsAttributes = $reflectedMethod->invoke($this->extension, 'post[title]', $entityMetadata, array('Default'));
     $fullFieldNames = array_keys($preparedConstraintsAttributes);
     $constraintNames = array_keys($preparedConstraintsAttributes[$fullFieldNames[0]]);
     $constraintProperties = array_keys($preparedConstraintsAttributes[$fullFieldNames[0]][$constraintNames[0]]);
     $this->assertEquals('post[title]', $fullFieldNames[0]);
     $this->assertEquals('NotBlank', $constraintNames[0]);
     $this->assertEquals('Length', $constraintNames[1]);
     $this->assertEquals('message', $constraintProperties[0]);
     $this->assertEquals('Title should not be blank!', $preparedConstraintsAttributes[$fullFieldNames[0]][$constraintNames[0]]['message']);
 }
开发者ID:pvdleek,项目名称:UberFrontendValidationBundle,代码行数:18,代码来源:UberFrontendValidationFormExtensionTest.php

示例3: getEntityConstraints

 /**
  * @param FormInterface $form
  *
  * @return array
  */
 private function getEntityConstraints(FormInterface $form)
 {
     $config = $form->getParent()->getConfig();
     if (!$config->hasOption('data_class') || !class_exists($config->getOption('data_class'))) {
         return [];
     }
     $constraints = [];
     /** @var ClassMetadata $metadata */
     $metadata = $this->validator->getMetadataFor($config->getDataClass());
     /** @var PropertyMetadata[] $properties */
     $properties = $metadata->getPropertyMetadata($form->getName());
     foreach ($properties as $property) {
         $constraints = array_merge($constraints, $property->findConstraints($metadata->getDefaultGroup()));
     }
     return $constraints;
 }
开发者ID:J-Ben87,项目名称:ParsleyBundle,代码行数:21,代码来源:ParsleyTypeExtension.php

示例4: __construct

 /**
  * @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;
 }
开发者ID:lamzin-andrey,项目名称:skyengtt.loc,代码行数:25,代码来源:ValidatorExtension.php

示例5: __construct

 /**
  * @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;
 }
开发者ID:Kyra2778,项目名称:AMR,代码行数:26,代码来源:ValidatorExtension.php

示例6: attachInlineValidator

 /**
  * 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)));
 }
开发者ID:andrewtch,项目名称:SonataAdminBundle,代码行数:26,代码来源:Admin.php

示例7: getMetadataFor

 public function getMetadataFor($value)
 {
     return $this->wrappedValidator->getMetadataFor($value);
 }
开发者ID:sysdream,项目名称:LiipFunctionalTestBundle,代码行数:4,代码来源:DataCollectingValidator.php


注:本文中的Symfony\Component\Validator\ValidatorInterface::getMetadataFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。