當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validator\ExecutionContext類代碼示例

本文整理匯總了PHP中Symfony\Component\Validator\ExecutionContext的典型用法代碼示例。如果您正苦於以下問題:PHP ExecutionContext類的具體用法?PHP ExecutionContext怎麽用?PHP ExecutionContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ExecutionContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isValid

 public function isValid(ExecutionContext $context)
 {
     $is_valid = $this->start <= $this->end;
     if (!$is_valid) {
         $context->addViolationAtSubPath('end', 'cjsissingh_calendar.validation.event_dates', array(), null);
     }
 }
開發者ID:cjsissingh,項目名稱:calendar-bundle,代碼行數:7,代碼來源:Event.php

示例2: isVoteValid

 /**
  * {@inheritdoc}
  */
 public function isVoteValid(ExecutionContext $context)
 {
     if (!$this->checkValue($this->value)) {
         $message = 'A vote cannot have a 0 value';
         $propertyPath = $context->getPropertyPath() . '.value';
         $context->addViolationAtPath($propertyPath, $message);
     }
 }
開發者ID:rampelli,項目名稱:FOSCommentBundle,代碼行數:11,代碼來源:Vote.php

示例3: 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

示例4: setUp

 protected function setUp()
 {
     $walker = $this->getMock('Symfony\\Component\\Validator\\GraphWalker', array(), array(), '', false);
     $factory = $this->getMock('Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactoryInterface');
     $context = new ExecutionContext('root', $walker, $factory);
     $context->setCurrentClass(__CLASS__);
     $this->validator = new ChoiceValidator();
     $this->validator->initialize($context);
 }
開發者ID:nickaggarwal,項目名稱:sample-symfony2,代碼行數:9,代碼來源:ChoiceValidatorTest.php

示例5: 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

示例6: 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

示例7:

 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

示例8:

 function it_validates_if_user_with_given_email_is_already_registered(UserRepository $userRepository, TokenStorageInterface $tokenStorage, AuthorizationCheckerInterface $authorizationChecker, ExecutionContext $context, TokenInterface $token, UniqueReviewerEmail $constraint, ReviewInterface $review, CustomerInterface $customer, CustomerInterface $existingUser)
 {
     $tokenStorage->getToken()->willReturn($token);
     $authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')->willReturn(false);
     $review->getAuthor()->willReturn($customer);
     $customer->getEmail()->willReturn('john.doe@example.com');
     $userRepository->findOneByEmail('john.doe@example.com')->willReturn($existingUser);
     $constraint->message = 'This email is already registered. Please log in.';
     $context->addViolationAt('author', 'This email is already registered. Please log in.', [], null)->shouldBeCalled();
     $this->validate($review, $constraint);
 }
開發者ID:TheMadeleine,項目名稱:Sylius,代碼行數:11,代碼來源:UniqueReviewerEmailValidatorSpec.php

示例9: 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

示例10: 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

示例11: validateFormChildren

 public static function validateFormChildren(FormInterface $form, ExecutionContext $context)
 {
     if ($form->getAttribute('cascade_validation')) {
         $propertyPath = $context->getPropertyPath();
         $graphWalker = $context->getGraphWalker();
         // Adjust the property path accordingly
         if (!empty($propertyPath)) {
             $propertyPath .= '.';
         }
         $propertyPath .= 'children';
         $graphWalker->walkReference($form->getChildren(), Constraint::DEFAULT_GROUP, $propertyPath, true);
     }
 }
開發者ID:rouffj,項目名稱:symfony,代碼行數:13,代碼來源:DelegatingValidationListener.php

示例12: 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

示例13: 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

示例14: testNotExistingFormData

 public function testNotExistingFormData()
 {
     $formConfig = $this->getMock('\\Symfony\\Component\\Form\\FormConfigInterface');
     $form = new Form($formConfig);
     $this->context = $this->getMock('\\Symfony\\Component\\Validator\\ExecutionContextInterface');
     $this->context->expects($this->any())->method('getRoot')->will($this->returnValue($form));
     $this->validator->initialize($this->context);
     $this->assertNull($this->validator->validate(false, $this->constraint));
 }
開發者ID:ramunasd,項目名稱:platform,代碼行數:9,代碼來源:DateEarlierThanValidatorTest.php

示例15: validateFormData

 /**
  * Validates the data of a form
  *
  * This method is called automatically during the validation process.
  *
  * @param FormInterface    $form    The validated form
  * @param ExecutionContext $context The current validation context
  */
 public static function validateFormData(FormInterface $form, ExecutionContext $context)
 {
     if (is_object($form->getData()) || is_array($form->getData())) {
         $propertyPath = $context->getPropertyPath();
         $graphWalker = $context->getGraphWalker();
         // The Execute constraint is called on class level, so we need to
         // set the property manually
         $context->setCurrentProperty('data');
         // Adjust the property path accordingly
         if (!empty($propertyPath)) {
             $propertyPath .= '.';
         }
         $propertyPath .= 'data';
         foreach (self::getFormValidationGroups($form) as $group) {
             $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
         }
     }
 }
開發者ID:rfc1483,項目名稱:blog,代碼行數:26,代碼來源:DelegatingValidator.php


注:本文中的Symfony\Component\Validator\ExecutionContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。