當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。