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


PHP Constraint::__construct方法代码示例

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


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

示例1: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     // no known options set? $options is the fields array
     if (is_array($options) && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
         $options = array('fields' => $options);
     }
     parent::__construct($options);
     if (!is_array($this->fields)) {
         throw new ConstraintDefinitionException(sprintf('The option "fields" is expected to be an array in constraint %s', __CLASS__));
     }
     foreach ($this->fields as $fieldName => $field) {
         // the XmlFileLoader and YamlFileLoader pass the field Optional
         // and Required constraint as an array with exactly one element
         if (is_array($field) && count($field) == 1) {
             $this->fields[$fieldName] = $field = $field[0];
         }
         if (!$field instanceof Optional && !$field instanceof Required) {
             $this->fields[$fieldName] = $field = new Required($field);
         }
         if (!is_array($field->constraints)) {
             $field->constraints = array($field->constraints);
         }
         foreach ($field->constraints as $constraint) {
             if (!$constraint instanceof Constraint) {
                 throw new ConstraintDefinitionException(sprintf('The value %s of the field %s is not an instance of Constraint in constraint %s', $constraint, $fieldName, __CLASS__));
             }
             if ($constraint instanceof Valid) {
                 throw new ConstraintDefinitionException(sprintf('The constraint Valid cannot be nested inside constraint %s. You can only declare the Valid constraint directly on a field or method.', __CLASS__));
             }
         }
     }
 }
开发者ID:NivalM,项目名称:VacantesJannaMotors,代码行数:35,代码来源:Collection.php

示例2: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = null)
 {
     if (is_array($options) && !array_intersect(array_keys($options), array('constraints', 'stopOnError'))) {
         $options = array('constraints' => $options);
     }
     parent::__construct($options);
     // convert array of constraints into SplPriorityQueue
     if (is_array($this->constraints)) {
         $queue = new \SplPriorityQueue();
         $constraints = $this->constraints;
         $constraints = array_reverse($constraints);
         foreach ($constraints as $index => $constraint) {
             $queue->insert($constraint, $index);
         }
         $this->constraints = $queue;
     }
     if (!$this->constraints instanceof \SplPriorityQueue) {
         throw new ConstraintDefinitionException('The option "constraints" is expected to be a SplPriorityQueue in constraint ' . __CLASS__ . '.');
     }
     $constraintsCopy = $this->getConstraints();
     // set extraction mode to both priority and data
     $constraintsCopy->setExtractFlags(\SplPriorityQueue::EXTR_BOTH);
     // loop through the priority chain for options validation
     while ($constraintsCopy->valid()) {
         $constraint = $constraintsCopy->current();
         // fail if the constraint is not actually a constraint
         if (!$constraint['data'] instanceof Constraint) {
             throw new ConstraintDefinitionException('The option "constraints" (priority: ' . $constraint['priority'] . ') is not a Constraint, in ' . __CLASS__ . '.');
         }
         // move to next constraint
         $constraintsCopy->next();
     }
 }
开发者ID:markwilson,项目名称:symfony2-validator-priority-chain,代码行数:36,代码来源:PriorityChain.php

示例3: __construct

 public function __construct($options = null)
 {
     parent::__construct($options);
     if (!$this->countryCode) {
         throw new MissingOptionsException('Country must be given to validate social security numbers', array('countryCode'));
     }
 }
开发者ID:rickard2,项目名称:luhnar-validator,代码行数:7,代码来源:SocialSecurityNumber.php

示例4: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     if ((!is_string($this->service) || !is_string($this->method)) && $this->serializingWarning !== true) {
         throw new \RuntimeException('You are using a closure with the `InlineConstraint`, this constraint' . ' cannot be serialized. You need to re-attach the `InlineConstraint` on each request.' . ' Once done, you can set the `serializingWarning` option to `true` to avoid this message.');
     }
 }
开发者ID:Uplink03,项目名称:SonataCoreBundle,代码行数:10,代码来源:InlineConstraint.php

示例5: __construct

 public function __construct($options = null)
 {
     parent::__construct($options);
     if (null === $this->min && null === $this->max) {
         throw new MissingOptionsException(sprintf('Either option "min" or "max" must be given for constraint %s', __CLASS__), array('min', 'max'));
     }
 }
开发者ID:ewrwq,项目名称:xh,代码行数:7,代码来源:Range.php

示例6: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = null)
 {
     // no known options set? $options is the fields array
     if (is_array($options) && !array_intersect(array_keys($options), array('groups', 'fields', 'allowExtraFields', 'allowMissingFields', 'extraFieldsMessage', 'missingFieldsMessage'))) {
         $options = array('fields' => $options);
     }
     parent::__construct($options);
     if (!is_array($this->fields)) {
         throw new ConstraintDefinitionException('The option "fields" is expected to be an array in constraint ' . __CLASS__);
     }
     foreach ($this->fields as $fieldName => $field) {
         if (!$field instanceof Optional && !$field instanceof Required) {
             $this->fields[$fieldName] = $field = new Required($field);
         }
         if (!is_array($field->constraints)) {
             $field->constraints = array($field->constraints);
         }
         foreach ($field->constraints as $constraint) {
             if (!$constraint instanceof Constraint) {
                 throw new ConstraintDefinitionException('The value ' . $constraint . ' of the field ' . $fieldName . ' is not an instance of Constraint in constraint ' . __CLASS__);
             }
             if ($constraint instanceof Valid) {
                 throw new ConstraintDefinitionException('The constraint Valid cannot be nested inside constraint ' . __CLASS__ . '. You can only declare the Valid constraint directly on a field or method.');
             }
         }
     }
 }
开发者ID:joan16v,项目名称:symfony2_test,代码行数:30,代码来源:Collection.php

示例7: __construct

 /**
  * @param \Spryker\Zed\Category\Persistence\CategoryQueryContainerInterface $queryContainer
  * @param int $idCategory
  * @param \Generated\Shared\Transfer\LocaleTransfer $locale
  * @param mixed $options
  */
 public function __construct(CategoryQueryContainerInterface $queryContainer, $idCategory, LocaleTransfer $locale, $options = null)
 {
     parent::__construct($options);
     $this->queryContainer = $queryContainer;
     $this->idCategory = $idCategory;
     $this->locale = $locale;
 }
开发者ID:spryker,项目名称:Category,代码行数:13,代码来源:CategoryNameExists.php

示例8: __construct

 public function __construct($options = null)
 {
     parent::__construct($options);
     if (null !== $this->maxSize) {
         $this->normalizeBinaryFormat($this->maxSize);
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:7,代码来源:File.php

示例9: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (!is_int($this->filter)) {
         throw new ConstraintDefinitionException('The option "filter" must be a valid FILTER_ constant in constraint ' . __CLASS__ . '.');
     }
 }
开发者ID:markwilson,项目名称:symfony2-validator-native-filter,代码行数:10,代码来源:NativeFilter.php

示例10: __construct

 /**
  * @inheritDoc
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (!in_array($this->version, self::$versions)) {
         throw new ConstraintDefinitionException(sprintf('The option "version" must be one of "%s"', implode('", "', self::$versions)));
     }
 }
开发者ID:Gregwar,项目名称:symfony,代码行数:10,代码来源:Ip.php

示例11: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = null)
 {
     if (!isset($options['value'])) {
         throw new ConstraintDefinitionException(sprintf('The %s constraint requires the "value" option to be set.', get_class($this)));
     }
     parent::__construct($options);
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:10,代码来源:AbstractComparison.php

示例12: __construct

 public function __construct($options = null)
 {
     if (is_array($options) && array_key_exists('groups', $options)) {
         throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint %s', __CLASS__));
     }
     parent::__construct($options);
 }
开发者ID:BusinessCookies,项目名称:CoffeeMachineProject,代码行数:7,代码来源:Traverse.php

示例13: __construct

 public function __construct($options = null)
 {
     parent::__construct($options);
     if (null === $this->repository || null === $this->property) {
         throw new MissingOptionsException(sprintf('The options "repository" and "property" must be given for constraint %s', __CLASS__), array('repository', 'property'));
     }
 }
开发者ID:nicolas-grekas,项目名称:workshop-symfony3,代码行数:7,代码来源:UniqueAttribute.php

示例14: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     // Validate all fields by default.
     if (empty($this->fields)) {
         $this->fields = AddressField::getAll();
     }
 }
开发者ID:commerceguys,项目名称:addressing,代码行数:11,代码来源:AddressFormatConstraint.php

示例15: __construct

 /**
  * {@inheritDoc}
  */
 public function __construct($options = NULL)
 {
     parent::__construct($options);
     // Validate all fields by default.
     if (empty($this->fields)) {
         $this->fields = array_values(AddressField::getAll());
     }
 }
开发者ID:seongbae,项目名称:drumo-distribution,代码行数:11,代码来源:AddressFormatConstraint.php


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