コード例 #1
0
ファイル: Schema.php プロジェクト: gdbots/pbj-php
 /**
  * @param SchemaId|string $id
  * @param string $className
  * @param Field[] $fields
  * @param Mixin[] $mixins
  */
 public function __construct($id, $className, array $fields = [], array $mixins = [])
 {
     Assertion::classExists($className, null, 'className');
     Assertion::allIsInstanceOf($fields, 'Gdbots\\Pbj\\Field', null, 'fields');
     Assertion::allIsInstanceOf($mixins, 'Gdbots\\Pbj\\Mixin', null, 'mixins');
     $this->id = $id instanceof SchemaId ? $id : SchemaId::fromString($id);
     $this->className = $className;
     $this->classShortName = ClassUtils::getShortName($this->className);
     $this->addField(FieldBuilder::create(self::PBJ_FIELD_NAME, Type\StringType::create())->required()->pattern(SchemaId::VALID_PATTERN)->withDefault($this->id->toString())->build());
     foreach ($mixins as $mixin) {
         $this->addMixin($mixin);
     }
     foreach ($fields as $field) {
         $this->addField($field);
     }
     $this->mixinIds = array_keys($this->mixins);
     $this->mixinCuries = array_keys($this->mixinsByCurie);
 }