Пример #1
0
 /**
  * @param string $name
  * @param Type $type
  * @param FieldRule $rule
  * @param bool $required
  * @param null|int $minLength
  * @param null|int $maxLength
  * @param null|string $pattern
  * @param null|string $format
  * @param null|int $min
  * @param null|int $max
  * @param int $precision
  * @param int $scale
  * @param null|mixed $default
  * @param bool $useTypeDefault
  * @param null|string $className
  * @param null|array $anyOfClassNames
  * @param \Closure|null $assertion
  * @param bool $overridable
  */
 public function __construct($name, Type $type, FieldRule $rule = null, $required = false, $minLength = null, $maxLength = null, $pattern = null, $format = null, $min = null, $max = null, $precision = 10, $scale = 2, $default = null, $useTypeDefault = true, $className = null, array $anyOfClassNames = null, \Closure $assertion = null, $overridable = false)
 {
     Assertion::betweenLength($name, 1, 127);
     Assertion::regex($name, self::VALID_NAME_PATTERN, sprintf('Field [%s] must match pattern [%s].', $name, self::VALID_NAME_PATTERN));
     Assertion::boolean($required);
     Assertion::boolean($useTypeDefault);
     Assertion::boolean($overridable);
     /*
      * a message type allows for interfaces to be used
      * as the "className".  so long as the provided argument
      * passes the instanceof check it's okay.
      */
     if ($type->getTypeValue() === TypeName::MESSAGE) {
         if (!class_exists($className) && !interface_exists($className)) {
             Assertion::true(false, sprintf('Field [%s] className [%s] must be a class or interface.', $name, $className));
         }
     } else {
         // anyOf is only supported on nested messages
         Assertion::nullOrClassExists($className);
         $anyOfClassNames = null;
     }
     $this->name = $name;
     $this->type = $type;
     $this->required = $required;
     $this->useTypeDefault = $useTypeDefault;
     $this->className = $className;
     $this->anyOfClassNames = $anyOfClassNames;
     $this->assertion = $assertion;
     $this->overridable = $overridable;
     $this->applyFieldRule($rule);
     $this->applyStringOptions($minLength, $maxLength, $pattern, $format);
     $this->applyNumericOptions($min, $max, $precision, $scale);
     $this->applyDefault($default);
 }