Example #1
0
 static function spec()
 {
     $spec = parent::spec();
     unset($spec['props']);
     unset($spec['rules']);
     return array_merge($spec, ['class' => ['required' => true, 'kind' => 'string'], 'parser' => ['type' => 'dep', 'kind' => \Nope\Parser::class], 'registry' => ['type' => 'dep', 'kind' => \Fulfil\Registry::class, 'required' => true]]);
 }
Example #2
0
 function __construct(...$args)
 {
     parent::__construct(...$args);
     if ($this->trueValues || $this->falseValues) {
         $this->allowLoose = true;
     }
     if ($this->trueValues) {
         foreach ($this->trueValues as &$value) {
             if (is_string($value)) {
                 $value = mb_strtolower(\Normalizer::normalize($value));
             } elseif (!is_scalar($value)) {
                 throw new \InvalidArgumentException();
             }
         }
         unset($value);
     }
     if ($this->falseValues) {
         foreach ($this->falseValues as &$value) {
             if (is_string($value)) {
                 $value = mb_strtolower(\Normalizer::normalize($value));
             } elseif (!is_scalar($value)) {
                 throw new \InvalidArgumentException();
             }
         }
         unset($value);
     }
 }
Example #3
0
 public function __construct(...$args)
 {
     parent::__construct(...$args);
     if ($this->casing && !in_array($this->casing, self::$validCasing)) {
         throw new \InvalidArgumentException("Casing must be one of " . implode(', ', self::$validCasing));
     }
 }
Example #4
0
 function __construct(...$args)
 {
     parent::__construct(...$args);
     if ($this->divisibleBy !== null) {
         $this->divisibleBy = BigNumbers\Decimal::create($this->divisibleBy);
         if (!$this->divisibleBy->isPositive()) {
             throw new \InvalidArgumentException("divisibleBy must be a positive integer");
         }
     }
 }
Example #5
0
 function __construct(...$args)
 {
     parent::__construct(...$args);
     if ($this->min !== null && $this->max !== null && $this->min > $this->max) {
         throw new \InvalidArgumentException();
     }
     if ($this->divisibleBy !== null && $this->divisibleBy <= 0) {
         throw new \InvalidArgumentException("divisibleBy must be a positive integer");
     }
 }
Example #6
0
 public function __construct(...$args)
 {
     parent::__construct(...$args);
     if (!is_array($this->formats)) {
         $this->formats = [$this->formats];
     }
     if (is_string($this->tz)) {
         $this->tz = new \DateTimeZone($this->tz);
     }
 }
Example #7
0
 function __construct(...$args)
 {
     parent::__construct(...$args);
     if ($this->min !== null && is_string($this->min)) {
         $this->min = \DateTime::createFromFormat(\DateTime::ISO8601, $this->min);
     }
     if ($this->max !== null && is_string($this->max)) {
         $this->max = \DateTime::createFromFormat(\DateTime::ISO8601, $this->max);
     }
 }
Example #8
0
 function initial()
 {
     if ($initial = parent::initial()) {
         return $initial;
     }
     foreach ($this->checks as $check) {
         if ($initial = $check->initial()) {
             return $initial;
         }
     }
 }
Example #9
0
 function export()
 {
     $out = parent::export();
     schemas:
     foreach ($out['schemas'] as &$v) {
         $v = $v->export();
     }
     rules:
     foreach ($this->rules as $k => $rule) {
         $out['rules'][$k] = $rule->export();
     }
     return $out;
 }
Example #10
0
 /**
  * When multiple checks are present, the first one to return a non-null
  * initial value is applied.
  */
 function initial()
 {
     $initial = parent::initial();
     if ($initial === null) {
         $initial = [];
         foreach ($this->props as $prop => $checks) {
             if ($checks === true) {
                 goto next_prop;
             }
             foreach ($checks as $c) {
                 $pInitial = $c->initial();
                 if ($pInitial !== null) {
                     $initial[$prop] = $pInitial;
                     goto next_prop;
                 }
             }
             $initial[$prop] = null;
             next_prop:
         }
     }
     return $initial;
 }
Example #11
0
 static function spec()
 {
     return array_merge(parent::spec(), ['min' => ['kind' => 'numeric'], 'max' => ['kind' => 'numeric'], 'divisibleBy' => ['kind' => 'numeric'], 'allowString' => ['kind' => 'bool', 'default' => false], 'allowInt' => ['kind' => 'bool', 'default' => true]]);
 }
Example #12
0
 static function spec()
 {
     return array_merge(parent::spec(), ['class' => ['kind' => 'string', 'required' => true]]);
 }
Example #13
0
 static function spec()
 {
     return array_merge(parent::spec(), ['emptyMode' => ['setter' => 'setEmptyMode'], 'lengthMin' => ['kind' => 'int'], 'lengthMax' => ['kind' => 'int'], 'length' => ['kind' => 'int'], 'bytesMax' => ['kind' => 'int'], 'pattern' => true]);
 }
Example #14
0
 static function spec()
 {
     return array_merge(parent::spec(), ['length' => ['kind' => 'int'], 'lengthMin' => ['kind' => 'int'], 'lengthMax' => ['kind' => 'int'], 'unique' => ['kind' => 'bool']]);
 }