public function __construct(array $enum = [], $validateType = false, $default = null) { parent::__construct(); $this->enum = $enum; $this->validateType = $validateType; $this->default = $default; }
/** * @param float|null $minimum * @param float|null $maximum * @param boolean|null $exclusiveMinimum * @param boolean|null $exclusiveMaximum * @param float|null $multipleOf * @throws \Exception */ public function __construct($minimum = null, $maximum = null, $exclusiveMinimum = null, $exclusiveMaximum = null, $multipleOf = null) { parent::__construct(); if ($minimum !== null && !is_numeric($minimum)) { throw new \Exception('Minimum must be numeric'); } if ($maximum !== null && !is_numeric($maximum)) { throw new \Exception('Maximum must be numeric'); } if ($maximum !== null && $minimum !== null && $maximum < $minimum) { throw new \Exception('maximum cant be less than minimum'); } if ($exclusiveMinimum !== null && !is_bool($exclusiveMinimum)) { throw new \Exception('exclusiveMinimum must be boolean'); } if ($exclusiveMaximum !== null && !is_bool($exclusiveMaximum)) { throw new \Exception('exclusiveMaximum must be boolean'); } if ($multipleOf !== null && !is_numeric($multipleOf)) { throw new \Exception('multipleOf must be numeric'); } $this->minimum = $minimum; $this->maximum = $maximum; $this->exclusiveMinimum = $exclusiveMinimum; $this->exclusiveMaximum = $exclusiveMaximum; $this->multipleOf = $multipleOf; }
/** * @param array $anyOf * @throws \Exception * @example * ```php * $validator = new AnyOf([ * new IntegerValidator(), * new ArrayValidator( * 1, * 4, * new IntegerValidator() * ) * ]); * * //Will parse successfully both * * $parsed = $validator->parse(8); * $parsed = $validator->parse([8, 10]); * ``` */ public function __construct(array $anyOf) { parent::__construct(); foreach ($anyOf as $validator) { if (!$validator instanceof \Phramework\Validate\BaseValidator) { throw new \Exception(sprintf('Items of %s parameter MUST be instances of Phramework\\Validate\\BaseValidator', $this->anyOfProperty)); } } $this->{$this->anyOfProperty} = $anyOf; }
/** * @param integer $minLength *[Optional]* * Minimum number of its characters, default is 0 * @param integer|null $maxLength *[Optional]* * Maximum number of its characters, default is null * @param string|null $pattern *[Optional]* * Regular expression pattern for validating, default is null * @param boolean $raw *[Optional]* * Keep raw value, don't sanitize value after validation, default is false * @throws \Exception */ public function __construct($minLength = 0, $maxLength = null, $pattern = null, $raw = false) { parent::__construct(); if (!is_int($minLength) || $minLength < 0) { throw new \Exception('minLength must be positive integer'); } if ($maxLength !== null && (!is_int($maxLength) || $maxLength < $minLength)) { throw new \Exception('maxLength must be positive integer'); } $this->minLength = $minLength; $this->maxLength = $maxLength; $this->pattern = $pattern; $this->raw = $raw; }
/** * @param object $properties * *[Optional]* Properties * @param string[] $required * *[Optional]* Required properties keys * @param object|boolean|null $additionalProperties * *[Optional]* Default is null * @param integer $minProperties * *[Optional]* Default is 0 * @param integer $maxProperties * *[Optional]* Default is null * @param object|null $dependencies * @throws \Exception */ public function __construct($properties = [], $required = [], $additionalProperties = null, $minProperties = 0, $maxProperties = null, $dependencies = null, $xVisibility = null) { parent::__construct(); //Work with objects if (is_array($properties)) { $properties = (object) $properties; } if (!is_int($minProperties) || $minProperties < 0) { throw new \Exception('minProperties must be positive integer'); } if ($maxProperties !== null && !is_int($maxProperties) || $maxProperties < $minProperties) { throw new \Exception('maxProperties must be positive integer'); } if ($additionalProperties !== null && !is_bool($additionalProperties)) { throw new \Exception('For now only boolean values supported for "additionalProperties"'); } if ($dependencies == null) { $dependencies = new \stdClass(); } else { if (!is_object($dependencies)) { throw new \Exception('dependencies must be object'); } foreach ($dependencies as $key => $value) { if (!is_array($value)) { throw new \Exception('dependencies member values must be arrays'); } } } if ($xVisibility !== null) { if (!is_object($xVisibility)) { throw new \Exception('x-visibility must be object'); } foreach ($xVisibility as $key => $value) { if (!is_array($value)) { throw new \Exception('visibility member values must be arrays'); } } } $this->minProperties = $minProperties; $this->maxProperties = $maxProperties; $this->properties = $properties; $this->required = $required; $this->additionalProperties = $additionalProperties; $this->dependencies = $dependencies; $this->{'x-visibility'} = $xVisibility; }
/** * @param integer $minItems * *[Optional]* Default is 0 * @param integer|null $maxItems * *[Optional]* * @param BaseValidator|null $items * *[Optional]* Default is null * @param Boolean $uniqueItems * *[Optional]* * @throws \Exception */ public function __construct($minItems = 0, $maxItems = null, $items = null, $uniqueItems = false) { parent::__construct(); if (is_array($items)) { throw new \Exception('Array for attribute "items" are not supported yet'); } if (!is_int($minItems) || $minItems < 0) { throw new \Exception('minItems must be positive integer'); } if ($maxItems !== null && !is_int($maxItems) || $maxItems < $minItems) { throw new \Exception('maxItems must be positive integer'); } if ($items !== null && !is_subclass_of($items, BaseValidator::class, true)) { throw new \Exception(sprintf('Property "items" MUST extend "%s"', BaseValidator::class)); } $this->minItems = $minItems; $this->maxItems = $maxItems; $this->items = $items; $this->uniqueItems = $uniqueItems; }
public function __construct($default = null) { parent::__construct(); $this->default = $default; }