예제 #1
0
 /**
  * @param string $kind
  *
  * @return Field
  */
 private static function createField($kind)
 {
     if (!isset(self::$fields[$kind])) {
         switch ($kind) {
             case DynamicFieldKind::STRING_VAL:
                 $type = StringType::create();
                 break;
             case DynamicFieldKind::TEXT_VAL:
                 $type = TextType::create();
                 break;
             case DynamicFieldKind::INT_VAL:
                 $type = IntType::create();
                 break;
             case DynamicFieldKind::BOOL_VAL:
                 $type = BooleanType::create();
                 break;
             case DynamicFieldKind::FLOAT_VAL:
                 $type = FloatType::create();
                 break;
             case DynamicFieldKind::DATE_VAL:
                 $type = DateType::create();
                 break;
             default:
                 throw new InvalidArgumentException(sprintf('DynamicField "%s" is not a valid type.', $kind));
         }
         self::$fields[$kind] = new Field($kind, $type, FieldRule::A_SINGLE_VALUE(), true);
     }
     return self::$fields[$kind];
 }
예제 #2
0
파일: Field.php 프로젝트: gdbots/pbj-php
 /**
  * @param FieldRule $rule
  * @throws AssertionFailed
  */
 private function applyFieldRule(FieldRule $rule = null)
 {
     $this->rule = $rule ?: FieldRule::A_SINGLE_VALUE();
     if ($this->isASet()) {
         Assertion::true($this->type->allowedInSet(), sprintf('Field [%s] with type [%s] cannot be used in a set.', $this->name, $this->type->getTypeValue()));
     }
 }
예제 #3
0
 /**
  * @return Field
  */
 public function build()
 {
     if (null === $this->rule) {
         $this->rule = FieldRule::A_SINGLE_VALUE();
     }
     return new Field($this->name, $this->type, $this->rule, $this->required, $this->minLength, $this->maxLength, $this->pattern, $this->format, $this->min, $this->max, $this->precision, $this->scale, $this->default, $this->useTypeDefault, $this->className, $this->anyOfClassNames, $this->assertion, $this->overridable);
 }