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


PHP Validator\Constraint类代码示例

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


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

示例1: validate

 /**
  * Checks if current workflow item allows transition
  *
  * @param WorkflowData $value
  * @param TransitionIsAllowed $constraint
  */
 public function validate($value, Constraint $constraint)
 {
     /** @var WorkflowItem $workflowItem */
     $workflowItem = $constraint->getWorkflowItem();
     $transitionName = $constraint->getTransitionName();
     $workflow = $this->registry->getWorkflow($workflowItem->getWorkflowName());
     $errors = new ArrayCollection();
     $result = false;
     try {
         $result = $workflow->isTransitionAllowed($workflowItem, $transitionName, $errors, true);
     } catch (InvalidTransitionException $e) {
         switch ($e->getCode()) {
             case InvalidTransitionException::UNKNOWN_TRANSITION:
                 $errors->add(array('message' => $constraint->unknownTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName)));
                 break;
             case InvalidTransitionException::NOT_START_TRANSITION:
                 $errors->add(array('message' => $constraint->notStartTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName)));
                 break;
             case InvalidTransitionException::STEP_HAS_NO_ALLOWED_TRANSITION:
                 $errors->add(array('message' => $constraint->stepHasNotAllowedTransitionMessage, 'parameters' => array('{{ transition }}' => $transitionName, '{{ step }}' => $workflowItem->getCurrentStep()->getName())));
                 break;
         }
     }
     if (!$result) {
         if ($errors->count()) {
             foreach ($errors as $error) {
                 $this->context->addViolation($error['message'], $error['parameters']);
             }
         } else {
             $this->context->addViolation($constraint->someConditionsNotMetMessage);
         }
     }
 }
开发者ID:Maksold,项目名称:platform,代码行数:39,代码来源:TransitionIsAllowedValidator.php

示例2: validate

 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof TokenEntity) {
         throw new \InvalidArgumentException('Given constraint must ne instance of TokenEntity class');
     }
     if ($value) {
         $configValidation = false;
         try {
             /** @var StorageApi $storageApi */
             $storageApi = $constraint->getStorageApi();
             $token = $storageApi->getToken($value);
             if (!$token) {
                 throw new \Exception('Token does not exists');
             }
             $userToken = new Token($storageApi);
             $configValidation = true;
             $components = new Components(new StorageApi(array('token' => $token['token'], 'url' => $storageApi->getApiUrl(), 'userAgent' => $storageApi->getUserAgent())));
             $components->listComponents(new ListConfigurationsOptions());
         } catch (\Exception $e) {
             if ($e instanceof \Keboola\StorageApi\ClientException && $e->getCode() === 403) {
                 //@FIXME jak zmenit api exception code
                 if ($configValidation) {
                     $this->context->addViolation($constraint->configMessage, array('%string%' => $value), null, null, 'TOKEN_PERMISSION');
                 } else {
                     $this->context->addViolation($constraint->permissionsMessage, array(), null, null, 'TOKEN_PERMISSION');
                 }
             } else {
                 $this->context->addViolation($constraint->message, array('%string%' => $value));
             }
             return;
         }
         //@FIXME doplnit validaci na master token!!!
     }
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:34,代码来源:TokenEntityValidator.php

示例3: validate

 /**
  * {@inheritdoc}
  *
  * @throws UnexpectedTypeException When the constraint isn't a subclass of {@see AbstractAssertionConstraint}
  * @throws ConstraintDefinitionException When the assertion doesn't exist on the assertion class
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof AbstractAssertionConstraint) {
         throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\AbstractAssertionConstraint');
     }
     $methodName = $constraint->getAssertionMethodName();
     $callable = [static::$assertClass, $methodName];
     $override = null;
     if (is_callable($callable) === false) {
         throw new ConstraintDefinitionException('Must be a valid callable on the assertion class');
     }
     $parameters = array($value);
     foreach ($constraint->getAssertionParameterNames() as $name) {
         $parameters[] = $constraint->{$name};
     }
     try {
         call_user_func_array($callable, $parameters);
     } catch (\Exception $e) {
         if ($e instanceof static::$assertExceptionClass) {
             $this->context->buildViolation($e->getMessage())->setParameter('{{ value }}', $this->formatValue($value))->setCode($e->getCode())->setCause($e)->addViolation();
         } else {
             throw $e;
         }
     }
 }
开发者ID:myschoolmanagement,项目名称:assert-constraint,代码行数:31,代码来源:AssertionValidator.php

示例4: getInstance

 /**
  * Returns the validator for the supplied constraint.
  *
  * @param Constraint $constraint A constraint
  *
  * @return ConstraintValidatorInterface A validator for the supplied constraint
  *
  * @throws UnexpectedTypeException When the validator is not an instance of ConstraintValidatorInterface
  */
 public function getInstance(Constraint $constraint)
 {
     $name = $constraint->validatedBy();
     if (!isset($this->validators[$name])) {
         switch (get_class($constraint)) {
             case self::BASE_NAMESPACE . '\\All':
                 $name = self::BASE_NAMESPACE . '\\LegacyAllValidator';
                 break;
             case self::BASE_NAMESPACE . '\\Choice':
                 $name = self::BASE_NAMESPACE . '\\LegacyChoiceValidator';
                 break;
             case self::BASE_NAMESPACE . '\\Collection':
                 $name = self::BASE_NAMESPACE . '\\LegacyCollectionValidator';
                 break;
             case self::BASE_NAMESPACE . '\\Count':
                 $name = self::BASE_NAMESPACE . '\\LegacyCountValidator';
                 break;
             case self::BASE_NAMESPACE . '\\Length':
                 $name = self::BASE_NAMESPACE . '\\LegacyLengthValidator';
                 break;
             case self::FORM_BASE_NAMESPACE . '\\Form':
                 $name = self::FORM_BASE_NAMESPACE . '\\LegacyFormValidator';
                 break;
         }
         $this->validators[$name] = new $name();
     } elseif (is_string($this->validators[$name])) {
         $this->validators[$name] = $this->container->get($this->validators[$name]);
     }
     if (!$this->validators[$name] instanceof ConstraintValidatorInterface) {
         throw new UnexpectedTypeException($this->validators[$name], 'Symfony\\Component\\Validator\\ConstraintValidatorInterface');
     }
     return $this->validators[$name];
 }
开发者ID:raphael-thibierge,项目名称:ProgWebServerProject,代码行数:42,代码来源:LegacyConstraintValidatorFactory.php

示例5: validate

 /**
  * Checks if the passed value is valid.
  *
  * @param mixed $value The value that should be validated
  * @param Constraint $constraint The constraint for the validation
  * @return bool
  */
 public function validate($value, Constraint $constraint)
 {
     /** @var EntityExists $constraint */
     if ($constraint->validate($value)) {
         $this->context->addViolation($constraint->message, ['{{ type }}' => $constraint->entityClass, '{{ value }}' => $value]);
     }
 }
开发者ID:apitude,项目名称:apitude,代码行数:14,代码来源:EntityDoesNotExistValidator.php

示例6: validate

 public function validate($value, Constraint $constraint)
 {
     if (!$constraint instanceof OrchestrationTableEntity) {
         throw new \InvalidArgumentException('Given constraint must ne instance of OrchestrationTableEntity class');
     }
     if ($value) {
         // table exists
         try {
             /** @var StorageApi $storageApi */
             $storageApi = $constraint->getStorageApi();
             if (!$storageApi->tableExists($value)) {
                 throw new \Exception('Configuration table does not exists');
             }
         } catch (\Exception $e) {
             $this->context->addViolation($constraint->message, array('%string%' => $value));
             return;
         }
         // table structure
         try {
             /** @var StorageApi $storageApi */
             $storageApi = $constraint->getStorageApi();
             $table = $storageApi->getTable($value);
             $token = new Token($storageApi);
             $requiredColumns = self::getRequiredColumns();
             $missingColumns = array_diff($requiredColumns, $table['columns']);
             if (!empty($missingColumns)) {
                 throw new \Exception('Invalid configuration table structure');
             }
         } catch (\Exception $e) {
             $this->context->addViolation($constraint->structureMessage, array('%string%' => implode(', ', $requiredColumns)));
             return;
         }
     }
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:34,代码来源:OrchestrationTableEntityValidator.php

示例7: getInstance

 /**
  * {@inheritDoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $className = $constraint->validatedBy();
     if (!isset($this->validators[$className]) || $className === 'Symfony\\Component\\Validator\\Constraints\\CollectionValidator') {
         $this->validators[$className] = new $className();
     }
     return $this->validators[$className];
 }
开发者ID:senthil-r-wiredelta,项目名称:meilleure-visite,代码行数:11,代码来源:ConstraintValidatorFactory.php

示例8: getInstance

 /**
  * {@inheritdoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $class_name = $constraint->validatedBy();
     if (!isset($this->validators[$class_name])) {
         $this->validators[$class_name] = $this->classResolver->getInstanceFromDefinition($class_name);
     }
     return $this->validators[$class_name];
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:11,代码来源:ConstraintValidatorFactory.php

示例9: getInstance

 /**
  * {@inheritdoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $className = $constraint->validatedBy();
     if (!isset($this->validators[$className])) {
         $this->validators[$className] = 'validator.expression' === $className ? new ExpressionValidator($this->propertyAccessor) : new $className();
     }
     return $this->validators[$className];
 }
开发者ID:rolas123,项目名称:weather-homework,代码行数:11,代码来源:ConstraintValidatorFactory.php

示例10: getInstance

 /**
  * @param Constraint $constraint
  * @return \Symfony\Component\Validator\ConstraintValidatorInterface
  */
 public function getInstance(Constraint $constraint)
 {
     $class_name = $constraint->validatedBy();
     if (!isset($this->validators[$class_name])) {
         $this->validators[$class_name] = new $class_name();
     }
     return $this->validators[$class_name];
 }
开发者ID:ragebat,项目名称:chamilo-lms,代码行数:12,代码来源:ConstraintValidatorFactory.php

示例11: addConstraint

 /**
  * {@inheritdoc}
  */
 public function addConstraint(Constraint $constraint)
 {
     if (!in_array(Constraint::PROPERTY_CONSTRAINT, (array) $constraint->getTargets())) {
         throw new ConstraintDefinitionException(sprintf('The constraint %s cannot be put on properties or getters', get_class($constraint)));
     }
     parent::addConstraint($constraint);
     return $this;
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:11,代码来源:MemberMetadata.php

示例12: getInstance

 /**
  * {@inheritdoc}
  */
 public function getInstance(Constraint $constraint)
 {
     $name = $constraint->validatedBy();
     if (isset($this->serviceNames[$name])) {
         return $this->container[$this->serviceNames[$name]];
     }
     return parent::getInstance($constraint);
 }
开发者ID:speedwork,项目名称:provider,代码行数:11,代码来源:ConstraintValidatorFactory.php

示例13:

 function it_doesnt_support_multi_targets_constraint($guesser, $factory, ClassMetadata $metadata, ProductValueInterface $value, AttributeInterface $attribute, Constraint $multiTargets, Constraint $validNumber)
 {
     $factory->createMetadata(Argument::any())->willReturn($metadata);
     $value->getAttribute()->willReturn($attribute);
     $attribute->getBackendType()->willReturn('varchar');
     $guesser->guessConstraints($attribute)->willReturn([$multiTargets]);
     $multiTargets->getTargets()->willReturn([Constraint::PROPERTY_CONSTRAINT, Constraint::CLASS_CONSTRAINT]);
     $this->shouldThrow(new \LogicException('No support provided for constraint on many targets'))->duringGetMetadataFor($value);
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:9,代码来源:ProductValueMetadataFactorySpec.php

示例14: getInstance

 /**
  * Returns the validator for the supplied constraint.
  *
  * @param  Constraint          $constraint A constraint
  * @return ConstraintValidator A validator for the supplied constraint
  */
 public function getInstance(Constraint $constraint)
 {
     $name = $constraint->validatedBy();
     if (isset($this->validators[$name])) {
         return $this->validators[$name];
     }
     $this->validators[$name] = $this->createValidator($name);
     return $this->validators[$name];
 }
开发者ID:hafedhbou,项目名称:hetic-p2017,代码行数:15,代码来源:ConstraintValidatorFactory.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate($entity, Constraint $constraint)
 {
     if (!isset($entity)) {
         return;
     }
     if (!in_array($entity->bundle(), $constraint->getBundleOption())) {
         $this->context->addViolation($constraint->message, array('%bundle' => implode(', ', $constraint->getBundleOption())));
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:12,代码来源:BundleConstraintValidator.php


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