__construct() public method

You should pass an associative array. The keys should be the names of existing properties in this class. The values should be the value for these properties. Alternatively you can override the method getDefaultOption() to return the name of an existing property. If no associative array is passed, this property is set instead. You can force that certain options are set by overriding getRequiredOptions() to return the names of these options. If any option is not set here, an exception is thrown.
public __construct ( mixed $options = null )
$options mixed The options (as associative array) or the value for the default option (any other type)
コード例 #1
0
 /**
  * {@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__));
             }
         }
     }
 }
コード例 #2
0
 /**
  * {@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();
     }
 }
コード例 #3
0
 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'));
     }
 }
コード例 #4
0
 /**
  * {@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.');
     }
 }
コード例 #5
0
ファイル: Range.php プロジェクト: ewrwq/xh
 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'));
     }
 }
コード例 #6
0
ファイル: Collection.php プロジェクト: joan16v/symfony2_test
 /**
  * {@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.');
             }
         }
     }
 }
コード例 #7
0
 /**
  * @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;
 }
コード例 #8
0
ファイル: File.php プロジェクト: ddrozdik/dmaps
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (null !== $this->maxSize) {
         $this->normalizeBinaryFormat($this->maxSize);
     }
 }
コード例 #9
0
 /**
  * {@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__ . '.');
     }
 }
コード例 #10
0
ファイル: Ip.php プロジェクト: Gregwar/symfony
 /**
  * @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)));
     }
 }
コード例 #11
0
 /**
  * {@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);
 }
コード例 #12
0
 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);
 }
コード例 #13
0
 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'));
     }
 }
コード例 #14
0
 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     parent::__construct($options);
     // Validate all fields by default.
     if (empty($this->fields)) {
         $this->fields = AddressField::getAll();
     }
 }
コード例 #15
0
 /**
  * {@inheritDoc}
  */
 public function __construct($options = NULL)
 {
     parent::__construct($options);
     // Validate all fields by default.
     if (empty($this->fields)) {
         $this->fields = array_values(AddressField::getAll());
     }
 }
コード例 #16
0
ファイル: Collection.php プロジェクト: rfc1483/blog
 /**
  * {@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);
 }
コード例 #17
0
 /**
  * ZipCode constructor.
  * @param mixed $options
  */
 public function __construct($options = null)
 {
     if (null !== $options && !is_array($options)) {
         $options = array('iso' => $options);
     }
     parent::__construct($options);
     if (null === $this->iso && null === $this->getter) {
         throw new MissingOptionsException(sprintf('Either the option "iso" or "getter" must be given for constraint %s', __CLASS__), array('iso', 'getter'));
     }
 }
コード例 #18
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (!in_array($this->scale, self::$valid_scales)) {
         throw new ConstraintDefinitionException(sprintf('The option "scale" must be one of "%s"', implode('", "', self::$valid_scales)));
     }
     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'));
     }
 }
コード例 #19
0
 /**
  * @param array $options Options
  *
  * @throw MissingOptionsException when the allowedValues option is missing
  */
 public function __construct($options = null)
 {
     if (null !== $options && is_array($options) && !isset($options['allowedValues'])) {
         $options = array('allowedValues' => $options);
     }
     parent::__construct($options);
     if (null === $this->allowedValues) {
         throw new MissingOptionsException(sprintf('The option "allowedValues" must be given for constraint %s.', __CLASS__), array('allowedValues'));
     }
 }
コード例 #20
0
ファイル: Isbn.php プロジェクト: TuxCoffeeCorner/tcc
 public function __construct($options = null)
 {
     if (null !== $options && !is_array($options)) {
         $options = array('isbn10' => $options, 'isbn13' => $options);
     }
     parent::__construct($options);
     if (null === $this->isbn10 && null === $this->isbn13) {
         throw new MissingOptionsException(sprintf('Either option "isbn10" or "isbn13" must be given for constraint "%s".', __CLASS__), array('isbn10', 'isbn13'));
     }
 }
コード例 #21
0
ファイル: Count.php プロジェクト: ronaldlunaramos/webstore
 public function __construct($options = null)
 {
     if (null !== $options && !is_array($options)) {
         $options = array('min' => $options, 'max' => $options);
     }
     parent::__construct($options);
     if (null === $this->min && null === $this->max) {
         throw new MissingOptionsException('Either option "min" or "max" must be given for constraint ' . __CLASS__, array('min', 'max'));
     }
 }
コード例 #22
0
ファイル: Valid.php プロジェクト: ddrozdik/dmaps
 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__));
     }
     if (is_array($options) && array_key_exists('deep', $options)) {
         @trigger_error('The "deep" option for the Valid constraint is deprecated since version 2.5 and will be removed in 3.0. When traversing arrays, nested arrays are always traversed. When traversing nested objects, their traversal strategy is used.', E_USER_DEPRECATED);
     }
     parent::__construct($options);
 }
コード例 #23
0
 /**
  * @param mixed $options
  */
 public function __construct(AbstractMapper $mapper, AbstractEntity $entity = null, $options = null)
 {
     if (!method_exists($mapper, 'findById')) {
         $message = sprintf('Mapper injected into %s must use FinderTrait', get_class($this));
         throw new LogicException($message);
     }
     $this->mapper = $mapper;
     $this->entity = $entity;
     parent::__construct($options);
 }
コード例 #24
0
 /**
  * @param $options
  *
  * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
  */
 public function __construct($options = null)
 {
     if (null !== $options && !is_array($options)) {
         $options = ['min' => $options];
     }
     parent::__construct($options);
     if (null === $this->min) {
         throw new MissingOptionsException(sprintf('Option "min" must be given for constraint %s', __CLASS__), ['min']);
     }
 }
コード例 #25
0
ファイル: CreditCardDate.php プロジェクト: eamador/Payum
 public function __construct($options = null)
 {
     parent::__construct($options);
     if (null === $this->min) {
         throw new MissingOptionsException('Either option "min" must be given for constraint ' . __CLASS__, array('min'));
     }
     if (null !== $this->min) {
         $this->min = new \DateTime($this->min);
         $this->min->modify('last day of this month');
     }
 }
コード例 #26
0
ファイル: EqualsField.php プロジェクト: KasaiDot/FoolFrame
 public function __construct($options = null)
 {
     if (!isset($options['field'])) {
         throw new ConstraintDefinitionException(sprintf('The %s constraint requires the "field" option to be set.', get_class($this)));
     }
     if (!isset($options['value'])) {
         throw new ConstraintDefinitionException(sprintf('The %s constraint requires the "value" option to be set.', get_class($this)));
     }
     $this->message = _i('This field should match the contents of {{ field }}.');
     parent::__construct($options);
 }
コード例 #27
0
ファイル: Callback.php プロジェクト: unexge/symfony
 /**
  * {@inheritdoc}
  */
 public function __construct($options = null)
 {
     // Invocation through annotations with an array parameter only
     if (is_array($options) && 1 === count($options) && isset($options['value'])) {
         $options = $options['value'];
     }
     if (is_array($options) && !isset($options['callback']) && !isset($options['groups']) && !isset($options['payload'])) {
         $options = array('callback' => $options);
     }
     parent::__construct($options);
 }
コード例 #28
0
ファイル: EntityExists.php プロジェクト: apitude/apitude
 /**
  * RecordExists constructor.
  *
  * @param EntityManagerInterface $em
  * @param string $entityClass
  * @param array $options {valuesCallback, identifierField, message, ...}
  */
 public function __construct(EntityManagerInterface $em, $entityClass, $options = [])
 {
     $this->em = $em;
     $this->entityClass = $entityClass;
     if (array_key_exists('valuesCallback', $options)) {
         $this->valuesCallback = $options['valuesCallback'];
     }
     if (array_key_exists('identifierField', $options)) {
         $this->identifierField = $options['identifierField'];
     }
     parent::__construct($options);
 }
コード例 #29
0
 /**
  * Constructs a HasCodeConstraint instance.
  *
  * @param null $options
  */
 public function __construct($options = NULL)
 {
     if ($options !== NULL && is_string($options)) {
         parent::__construct(['code' => $options]);
     }
     if ($options !== NULL && is_array($options) && isset($options['code'])) {
         parent::__construct($options);
     }
     if ($this->code === NULL) {
         throw new MissingOptionsException('The code option is required', __CLASS__);
     }
 }
コード例 #30
0
ファイル: Parameter.php プロジェクト: fabricius/fabricius
 public function __construct(array $options)
 {
     if (null !== $options && !is_array($options)) {
         $options = array('required' => false, 'format' => false);
     }
     if (!isset($options['required'])) {
         $options['required'] = false;
     }
     if (!isset($options['format'])) {
         $options['format'] = false;
     }
     parent::__construct($options);
 }