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


PHP ExecutionContext::addViolation方法代码示例

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


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

示例1: setMessage

 /**
  * Wrapper for $this->context->addViolation()
  *
  * @deprecated
  */
 protected function setMessage($template, array $parameters = array())
 {
     $this->messageTemplate = $template;
     $this->messageParameters = $parameters;
     if (!$this->context instanceof ExecutionContext) {
         throw new ValidatorException('ConstraintValidator::initialize() must be called before setting violation messages');
     }
     $this->context->addViolation($template, $parameters);
 }
开发者ID:richardmiller,项目名称:symfony,代码行数:14,代码来源:ConstraintValidator.php

示例2: testAddViolationUsesPassedNullValue

    public function testAddViolationUsesPassedNullValue()
    {
        $this->translator->expects($this->once())
            ->method('trans')
            ->with('Error', array('foo1' => 'bar1'))
            ->will($this->returnValue('Translated error'));
        $this->translator->expects($this->once())
            ->method('transChoice')
            ->with('Choice error', 1, array('foo2' => 'bar2'))
            ->will($this->returnValue('Translated choice error'));

        // passed null value should override preconfigured value "invalid"
        $this->context->addViolation('Error', array('foo1' => 'bar1'), null);
        $this->context->addViolation('Choice error', array('foo2' => 'bar2'), null, 1);

        $this->assertEquals(new ConstraintViolationList(array(
            new ConstraintViolation(
                'Translated error',
                'Error',
                array('foo1' => 'bar1'),
                'Root',
                'foo.bar',
                null
            ),
            new ConstraintViolation(
                'Translated choice error',
                'Choice error',
                array('foo2' => 'bar2'),
                'Root',
                'foo.bar',
                null,
                1
            ),
        )), $this->context->getViolations());
    }
开发者ID:nysander,项目名称:symfony,代码行数:35,代码来源:ExecutionContextTest.php

示例3: areOptionsValid

 /**
  * Validation rule for attribute option values
  *
  * @param AbstractAttribute $attribute
  * @param ExecutionContext  $context
  */
 public static function areOptionsValid(AbstractAttribute $attribute, ExecutionContext $context)
 {
     $existingValues = array();
     foreach ($attribute->getOptions() as $option) {
         $code = $option->getCode();
         if (isset($existingValues[$code])) {
             $context->addViolation(self::VIOLATION_DUPLICATE_OPTION_CODE);
         } elseif ($code === null) {
             $context->addViolation(self::VIOLATION_OPTION_CODE_REQUIRED);
         } elseif (!is_string($code)) {
             $context->addViolation(self::VIOLATION_NON_STRING_CODE . sprintf(' Type "%s" found.', gettype($code)));
         } else {
             $existingValues[$code] = '';
         }
     }
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:22,代码来源:AttributeValidator.php

示例4: isVoteValid

 /**
  * {@inheritdoc}
  */
 public function isVoteValid(ExecutionContext $context)
 {
     if (!$this->checkValue($this->value)) {
         $propertyPath = $context->getPropertyPath() . '.value';
         $context->setPropertyPath($propertyPath);
         $context->addViolation('A vote cannot have a 0 value', array(), null);
     }
 }
开发者ID:radzikowski,项目名称:CraftyComponents,代码行数:11,代码来源:Vote.php

示例5: validateValueAsYaml

 public function validateValueAsYaml(ExecutionContext $context)
 {
     try {
         Inline::load($this->value);
     } catch (ParserException $e) {
         $context->setPropertyPath($context->getPropertyPath() . '.value');
         $context->addViolation('This value is not valid YAML syntax', array(), $this->value);
     }
 }
开发者ID:geoffreytran,项目名称:zym,代码行数:9,代码来源:Parameter.php

示例6:

 function it_does_not_validate_attribute_with_non_string_options(AbstractAttribute $attribute, ExecutionContext $context, AttributeOption $option1, AttributeOption $option2, AttributeOption $option3, AttributeOption $option4)
 {
     $option1->getCode()->willReturn('ab');
     $option2->getCode()->willReturn(0);
     $option3->getCode()->willReturn('ef');
     $option4->getCode()->willReturn('gh');
     $attribute->getOptions()->willReturn([$option1, $option2, $option3, $option4]);
     $context->addViolation('Code must be a string. Type "integer" found.')->shouldBeCalled();
     $this->areOptionsValid($attribute, $context);
 }
开发者ID:javiersantos,项目名称:pim-community-dev,代码行数:10,代码来源:AttributeValidatorSpec.php

示例7: isEmailValid

 public function isEmailValid(ExecutionContext $context)
 {
     // somehow you have an array of "fake email"
     $fakeEmails = array('test@test.com');
     // check if the name is actually a fake email
     if (in_array($this->getEmail(), $fakeEmails)) {
         $propertyPath = $context->getPropertyPath() . '.email';
         $context->setPropertyPath($propertyPath);
         $context->addViolation('Tu ne te moquerais pas un peu de moi avec cet email ?', array(), null);
     }
 }
开发者ID:rvalois,项目名称:Tutorial-Symfony2-SdZ,代码行数:11,代码来源:Contact.php

示例8: it_does_not_add_violation_if_the_given_value_is_valid_json

    public function it_does_not_add_violation_if_the_given_value_is_valid_json(ExecutionContext $context, ComposerJson $constraint)
    {
        $composerJsonContent = <<<'EOT'
{
    "require": {
        "monolog/monolog": "1.2.*"
    }
}
EOT;
        $context->addViolation(Argument::any())->shouldNotBeCalled();
        $this->validate($composerJsonContent, $constraint);
    }
开发者ID:pborreli,项目名称:composer-service,代码行数:12,代码来源:ComposerJsonValidatorSpec.php

示例9: testAddViolationPluralTranslationError

    public function testAddViolationPluralTranslationError()
    {
        $this->translator->expects($this->once())
            ->method('transChoice')
            ->with('foo')
            ->will($this->throwException(new \InvalidArgumentException()));
        $this->translator->expects($this->once())
            ->method('trans')
            ->with('foo');

        $this->context->addViolation('foo', array(), null, 2);
    }
开发者ID:nattaphat,项目名称:hgis,代码行数:12,代码来源:ExecutionContextTest.php

示例10: areImagesValid

 public function areImagesValid(ExecutionContext $context)
 {
     $captured_ids = array_map(function ($image) {
         return $image->getId();
     }, $this->images->toArray());
     $property_path = $context->getPropertyPath() . '.images';
     if (!count($captured_ids)) {
         $context->addViolationAt($property_path, 'Please select at least one image!', array(), null);
         return;
     }
     $count = $this->query_builder->andWhere($this->query_builder->expr()->in('i.id', $captured_ids))->select('COUNT(i.id)')->getQuery()->getSingleScalarResult();
     if (!$count) {
         $context->addViolation('Please select images from the list!', array(), null);
     }
 }
开发者ID:rodgermd,项目名称:mura-show.com,代码行数:15,代码来源:BulkImages.php

示例11: pickedOrderItems

 /**
  * @param  ExecutionContext $context
  * @return void
  * @deprecated
  */
 public function pickedOrderItems(ExecutionContext $context)
 {
     $count = 0;
     foreach ($this->items as $item) {
         $count += $item->getCount();
     }
     if ($count === 0) {
         /*
         $property_path = $context->getPropertyPath() . '.customer.phone';
         $property_path = $context->getPropertyPath() . '.items[0].count';
         $property_path = $context->getPropertyPath() . '.items.[0].count';
         $property_path = $context->getPropertyPath() . '.items.0.count';
         */
         $property_path = $context->getPropertyPath() . '.items[0].count';
         $context->setPropertyPath($property_path);
         $context->addViolation('You have to pick at least one pizza...', array(), null);
     }
 }
开发者ID:kadala,项目名称:AcmePizzaBundle,代码行数:23,代码来源:OrderFactory.php

示例12: validateTwo

 public function validateTwo(ExecutionContext $context)
 {
     $context->addViolation('Other message', array('{{ value }}' => 'baz'), 'otherInvalidValue');
     return false;
 }
开发者ID:richardmiller,项目名称:symfony,代码行数:5,代码来源:CallbackValidatorTest.php

示例13: esDniValido

 /**
  * Validador propio que comprueba si el DNI introducido es válido
  */
 public function esDniValido(ExecutionContext $context)
 {
     $nombre_propiedad = $context->getPropertyPath() . '.dni';
     $dni = $this->getDni();
     // Comprobar que el formato sea correcto
     if (0 === preg_match("/\\d{1,8}[a-z]/i", $dni)) {
         $context->setPropertyPath($nombre_propiedad);
         $context->addViolation('El DNI introducido no tiene el formato correcto (entre 1 y 8 números seguidos de una letra, sin guiones y sin dejar ningún espacio en blanco)', array(), null);
         return;
     }
     // Comprobar que la letra cumple con el algoritmo
     $numero = substr($dni, 0, -1);
     $letra = strtoupper(substr($dni, -1));
     if ($letra != substr("TRWAGMYFPDXBNJZSQVHLCKE", strtr($numero, "XYZ", "012") % 23, 1)) {
         $context->setPropertyPath($nombre_propiedad);
         $context->addViolation('La letra no coincide con el número del DNI. Comprueba que has escrito bien tanto el número como la letra', array(), null);
     }
 }
开发者ID:neozoe,项目名称:Cupon,代码行数:21,代码来源:Usuario.php

示例14: isPackageUnique

 public function isPackageUnique(ExecutionContext $context)
 {
     try {
         if ($this->entityRepository->findOneByName($this->name)) {
             $propertyPath = $context->getPropertyPath() . '.repository';
             $context->setPropertyPath($propertyPath);
             $context->addViolation('A package with the name ' . $this->name . ' already exists.', array(), null);
         }
     } catch (\Doctrine\ORM\NoResultException $e) {
     }
 }
开发者ID:nesQuick,项目名称:packagist,代码行数:11,代码来源:Package.php

示例15: isEntityValid

 public function isEntityValid(ExecutionContext $context)
 {
     $propertyPath = $context->getPropertyPath() . '.fieldName';
     if ($this->getFieldType() == 'entity') {
         if ($this->getFragment() == null || $this->getBundleName() == null || $this->getEntityName() == null || $this->getRelationType() == null || $this->getPropertyName() == null) {
             $context->setPropertyPath($propertyPath);
             $context->addViolation('Incomplete relation value for ' . $this->getFieldName(), array(), null);
         }
     }
 }
开发者ID:r4cker,项目名称:lowbi,代码行数:10,代码来源:Field.php


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