예제 #1
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     $fields = [];
     /** @var T\Type $class */
     foreach (self::getAllTypes() as $type => $class) {
         switch ($type) {
             case 'Identifier':
                 $fields[] = Fb::create($type, $class::create())->asAMap()->className('Gdbots\\Pbj\\WellKnown\\TimeUuidIdentifier')->build();
                 break;
             case 'IntEnum':
                 $fields[] = Fb::create($type, $class::create())->asAMap()->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\IntEnum')->build();
                 break;
             case 'StringEnum':
                 $fields[] = Fb::create($type, $class::create())->asAMap()->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\StringEnum')->build();
                 break;
             case 'Message':
                 $fields[] = Fb::create($type, $class::create())->asAMap()->className('Gdbots\\Tests\\Pbj\\Fixtures\\NestedMessage')->build();
                 break;
             default:
                 $fields[] = Fb::create($type, $class::create())->asAMap()->build();
         }
     }
     $schema = new Schema('pbj:gdbots:tests.pbj:fixtures:maps-message:1-0-0', __CLASS__, $fields);
     MessageResolver::registerSchema($schema);
     return $schema;
 }
예제 #2
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     $schema = new Schema('pbj:gdbots:tests.pbj:fixtures:email-message:1-0-0', __CLASS__, [Fb::create('id', T\TimeUuidType::create())->required()->build(), Fb::create('from_name', T\StringType::create())->build(), Fb::create('from_email', T\StringType::create())->required()->format('email')->build(), Fb::create('subject', T\StringType::create())->withDefault(function (EmailMessage $message = null) {
         if (!$message) {
             return null;
         }
         return implode(',', $message->get('labels', [])) . ' test';
     })->build(), Fb::create('body', T\StringType::create())->build(), Fb::create('priority', T\IntEnumType::create())->required()->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Priority')->withDefault(Priority::NORMAL)->build(), Fb::create('sent', T\BooleanType::create())->build(), Fb::create('date_sent', T\DateTimeType::create())->build(), Fb::create('microtime_sent', T\MicrotimeType::create())->build(), Fb::create('provider', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->withDefault(Provider::GMAIL())->build(), Fb::create('labels', T\StringType::create())->format(Format::HASHTAG())->asASet()->build(), Fb::create('nested', T\MessageType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\NestedMessage')->build(), Fb::create('enum_in_set', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->asASet()->build(), Fb::create('enum_in_list', T\StringEnumType::create())->className('Gdbots\\Tests\\Pbj\\Fixtures\\Enum\\Provider')->asAList()->build(), Fb::create('any_of_message', T\MessageType::create())->className('Gdbots\\Pbj\\Message')->asAList()->build(), Fb::create('dynamic_fields', T\DynamicFieldType::create())->asAList()->build()]);
     MessageResolver::registerSchema($schema);
     return $schema;
 }
예제 #3
0
 public function testInvalidValues()
 {
     $field = FieldBuilder::create('trinary_unknown', TrinaryType::create())->build();
     $type = $field->getType();
     $invalid = ['a', [], 3, -1, false, true];
     foreach ($invalid as $val) {
         try {
             $type->guard($val, $field);
             $thrown = false;
         } catch (\Exception $e) {
             $thrown = true;
         }
         if (!$thrown) {
             $this->fail(sprintf('TrinaryType field accepted invalid value [%s].', $val));
         }
     }
 }
예제 #4
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);
 }
예제 #5
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('node_ref', T\MessageRefType::create())->build(), Fb::create('slug', T\StringType::create())->format(Format::SLUG())->build(), Fb::create('publish_at', T\DateTimeType::create())->useTypeDefault(false)->build()];
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('node_ref', T\MessageRefType::create())->build(), Fb::create('new_node', T\MessageType::create())->className('Gdbots\\Schemas\\Ncr\\Mixin\\Node\\Node')->build(), Fb::create('old_node', T\MessageType::create())->className('Gdbots\\Schemas\\Ncr\\Mixin\\Node\\Node')->build()];
 }
예제 #7
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('request_id', T\UuidType::create())->required()->build(), Fb::create('occurred_at', T\MicrotimeType::create())->build(), Fb::create('ctx_retries', T\TinyIntType::create())->build(), Fb::create('ctx_causator_ref', T\MessageRefType::create())->build(), Fb::create('ctx_correlator_ref', T\MessageRefType::create())->build(), Fb::create('ctx_user_ref', T\MessageRefType::create())->build(), Fb::create('ctx_app', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\App')->build(), Fb::create('ctx_cloud', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\Cloud')->build(), Fb::create('ctx_ip', T\StringType::create())->format(Format::IPV4())->overridable(true)->build(), Fb::create('ctx_ua', T\TextType::create())->overridable(true)->build()];
 }
예제 #8
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:eme:solicits:node:solicit:1-0-0', __CLASS__, [Fb::create('_id', T\IdentifierType::create())->required()->withDefault(function () {
         return SolicitId::generate();
     })->className('Eme\\Schemas\\Solicits\\SolicitId')->build(), Fb::create('description', T\TextType::create())->build(), Fb::create('hashtags', T\StringType::create())->asASet()->format(Format::HASHTAG())->build(), Fb::create('story_enabled', T\BooleanType::create())->withDefault(true)->build(), Fb::create('story_required', T\BooleanType::create())->build(), Fb::create('story_label', T\StringType::create())->build(), Fb::create('utm_campaign', T\StringType::create())->maxLength(50)->pattern('^[\\w\\/\\.:-]+$')->build()], [AccountRefV1Mixin::create(), NodeV1Mixin::create(), ExpirableV1Mixin::create(), IndexedV1Mixin::create(), PublishableV1Mixin::create()]);
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('node_ref', T\MessageRefType::create())->build(), Fb::create('node_status', T\StringEnumType::create())->className('Gdbots\\Schemas\\Ncr\\Enum\\NodeStatus')->build(), Fb::create('new_slug', T\StringType::create())->format(Format::SLUG())->build(), Fb::create('old_slug', T\StringType::create())->format(Format::SLUG())->build()];
 }
예제 #10
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:gdbots:pbjx::envelope:1-0-0', __CLASS__, [Fb::create('envelope_id', T\UuidType::create())->required()->build(), Fb::create('ok', T\BooleanType::create())->withDefault(true)->build(), Fb::create('code', T\SmallIntType::create())->withDefault(Code::OK)->build(), Fb::create('http_code', T\IntEnumType::create())->withDefault(HttpCode::HTTP_OK())->className('Gdbots\\Schemas\\Pbjx\\Enum\\HttpCode')->build(), Fb::create('etag', T\StringType::create())->maxLength(100)->pattern('^[\\w\\.:-]+$')->build(), Fb::create('error_name', T\StringType::create())->pattern('^[\\w\\/\\.:-]+$')->build(), Fb::create('error_message', T\TextType::create())->build(), Fb::create('message_ref', T\MessageRefType::create())->build(), Fb::create('message', T\MessageType::create())->className('Gdbots\\Pbj\\Message')->build()]);
 }
예제 #11
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:gdbots:pbjx:event:event-execution-failed:1-0-0', __CLASS__, [Fb::create('event', T\MessageType::create())->className('Gdbots\\Schemas\\Pbjx\\Mixin\\Event\\Event')->build(), Fb::create('error_code', T\SmallIntType::create())->withDefault(Code::OK)->build(), Fb::create('error_name', T\StringType::create())->pattern('^[\\w\\/\\.:-]+$')->build(), Fb::create('error_message', T\TextType::create())->build()], [EventV1Mixin::create()]);
 }
예제 #12
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('ctx_ua', T\TextType::create())->overridable(true)->build(), Fb::create('ctx_ua_parsed', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\UserAgent')->build()];
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('from_ref', T\MessageRefType::create())->build(), Fb::create('to_ref', T\MessageRefType::create())->build(), Fb::create('multiplicity', T\StringEnumType::create())->withDefault(EdgeMultiplicity::MULTI())->className('Gdbots\\Schemas\\Ncr\\Enum\\EdgeMultiplicity')->overridable(true)->build(), Fb::create('created_at', T\MicrotimeType::create())->build()];
 }
예제 #14
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('collector', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\App')->build()];
 }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('response_id', T\UuidType::create())->required()->build(), Fb::create('created_at', T\MicrotimeType::create())->build(), Fb::create('ctx_request_ref', T\MessageRefType::create())->build(), Fb::create('ctx_correlator_ref', T\MessageRefType::create())->build()];
 }
예제 #16
0
파일: AppV1.php 프로젝트: gdbots/schemas
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:gdbots:contexts::app:1-0-0', __CLASS__, [Fb::create('_id', T\UuidType::create())->useTypeDefault(false)->build(), Fb::create('vendor', T\StringType::create())->maxLength(50)->pattern('^[a-z0-9-]+$')->build(), Fb::create('name', T\StringType::create())->maxLength(50)->pattern('^[a-z0-9\\.-]+$')->build(), Fb::create('version', T\StringType::create())->maxLength(10)->pattern('^[\\w\\.-]+$')->build(), Fb::create('build', T\StringType::create())->maxLength(50)->pattern('^[\\w\\.-]+$')->build(), Fb::create('variant', T\StringType::create())->maxLength(10)->pattern('^[\\w\\.-]+$')->build()]);
 }
예제 #17
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:eme:solicits:edge:submissions:1-0-0', __CLASS__, [Fb::create('multiplicity', T\StringEnumType::create())->withDefault(EdgeMultiplicity::ONE2MANY())->className('Gdbots\\Schemas\\Ncr\\Enum\\EdgeMultiplicity')->build()], [EdgeV1Mixin::create()]);
 }
예제 #18
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('command_id', T\TimeUuidType::create())->required()->build(), Fb::create('occurred_at', T\MicrotimeType::create())->build(), Fb::create('expected_etag', T\StringType::create())->maxLength(100)->pattern('^[\\w\\.:-]+$')->build(), Fb::create('ctx_retries', T\TinyIntType::create())->build(), Fb::create('ctx_causator_ref', T\MessageRefType::create())->build(), Fb::create('ctx_correlator_ref', T\MessageRefType::create())->build(), Fb::create('ctx_user_ref', T\MessageRefType::create())->build(), Fb::create('ctx_app', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\App')->build(), Fb::create('ctx_cloud', T\MessageType::create())->className('Gdbots\\Schemas\\Contexts\\Cloud')->build(), Fb::create('ctx_ip', T\StringType::create())->format(Format::IPV4())->overridable(true)->build(), Fb::create('ctx_ua', T\TextType::create())->overridable(true)->build()];
 }
예제 #19
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:gdbots:contexts::user-agent:1-0-0', __CLASS__, [Fb::create('br_family', T\StringType::create())->pattern('^[\\w\\s\\(\\)\\[\\]\\{\\}\\/\\.:;-]+$')->build(), Fb::create('br_major', T\SmallIntType::create())->build(), Fb::create('br_minor', T\SmallIntType::create())->build(), Fb::create('br_patch', T\SmallIntType::create())->build(), Fb::create('os_family', T\StringType::create())->pattern('^[\\w\\s\\(\\)\\[\\]\\{\\}\\/\\.:;-]+$')->build(), Fb::create('os_major', T\SmallIntType::create())->build(), Fb::create('os_minor', T\SmallIntType::create())->build(), Fb::create('os_patch', T\SmallIntType::create())->build(), Fb::create('os_patch_minor', T\SmallIntType::create())->build(), Fb::create('dvce_family', T\StringType::create())->pattern('^[\\w\\s\\(\\)\\[\\]\\{\\}\\/\\.:;-]+$')->build()]);
 }
예제 #20
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('month_of_year', T\IntEnumType::create())->withDefault(Month::UNKNOWN())->className('Gdbots\\Schemas\\Common\\Enum\\Month')->build(), Fb::create('day_of_month', T\TinyIntType::create())->max(31)->build(), Fb::create('day_of_week', T\IntEnumType::create())->withDefault(DayOfWeek::UNKNOWN())->className('Gdbots\\Schemas\\Common\\Enum\\DayOfWeek')->build(), Fb::create('is_weekend', T\BooleanType::create())->build(), Fb::create('hour_of_day', T\TinyIntType::create())->max(23)->build()];
 }
예제 #21
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:gdbots:ncr:event:edge-deleted:1-0-0', __CLASS__, [Fb::create('edge', T\MessageType::create())->className('Gdbots\\Schemas\\Ncr\\Mixin\\Edge\\Edge')->build()], [EventV1Mixin::create()]);
 }
예제 #22
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('slug', T\StringType::create())->format(Format::SLUG())->build()];
 }
예제 #23
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('nodes', T\MessageType::create())->asAList()->className('Gdbots\\Schemas\\Ncr\\Mixin\\Node\\Node')->build()];
 }
예제 #24
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('ctx_ip', T\StringType::create())->format(Format::IPV4())->overridable(true)->build(), Fb::create('ctx_ip_geo', T\MessageType::create())->className('Gdbots\\Schemas\\Geo\\Address')->build()];
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('node_ref', T\MessageRefType::create())->build(), Fb::create('_id', T\StringType::create())->pattern('^[\\w\\/\\.:-]+$')->build(), Fb::create('slug', T\StringType::create())->format(Format::SLUG())->build()];
 }
예제 #26
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     $schema = new Schema('pbj:gdbots:tests.pbj:fixtures:nested-message:1-0-0', __CLASS__, [Fb::create('test1', T\StringType::create())->build(), Fb::create('test2', T\IntType::create())->asASet()->build(), Fb::create('location', T\GeoPointType::create())->build(), Fb::create('refs', T\MessageRefType::create())->asASet()->build()]);
     MessageResolver::registerSchema($schema);
     return $schema;
 }
예제 #27
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('node_ref', T\MessageRefType::create())->build()];
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function getFields()
 {
     return [Fb::create('published_at', T\DateTimeType::create())->useTypeDefault(false)->build()];
 }
예제 #29
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:eme:solicits:command:send-submission:1-0-0', __CLASS__, [Fb::create('solicit_id', T\IdentifierType::create())->required()->className('Eme\\Schemas\\Solicits\\SolicitId')->build(), Fb::create('first_name', T\StringType::create())->build(), Fb::create('last_name', T\StringType::create())->build(), Fb::create('email', T\StringType::create())->format(Format::EMAIL())->build(), Fb::create('email_domain', T\StringType::create())->format(Format::HOSTNAME())->build(), Fb::create('address', T\MessageType::create())->className('Gdbots\\Schemas\\Geo\\Address')->build(), Fb::create('phone', T\StringType::create())->asAMap()->maxLength(20)->pattern('^\\+?[1-9]\\d{1,14}$')->build(), Fb::create('dob', T\DateType::create())->build(), Fb::create('age', T\TinyIntType::create())->max(120)->build(), Fb::create('gender', T\IntEnumType::create())->className('Gdbots\\Schemas\\Common\\Enum\\Gender')->build(), Fb::create('story', T\TextType::create())->build(), Fb::create('file_ids', T\IdentifierType::create())->asASet()->className('Gdbots\\Schemas\\Files\\FileId')->build(), Fb::create('photo_urls', T\StringType::create())->asAList()->format(Format::URL())->build(), Fb::create('video_urls', T\StringType::create())->asAList()->format(Format::URL())->build(), Fb::create('networks', T\StringType::create())->asAMap()->maxLength(50)->pattern('^[\\w\\.-]+$')->build(), Fb::create('ppid', T\StringType::create())->pattern('^[\\w\\/\\.:-]+$')->build(), Fb::create('cf', T\DynamicFieldType::create())->asAList()->build()], [AccountRefV1Mixin::create(), CommandV1Mixin::create(), CollectableV1Mixin::create(), TimePartingV1Mixin::create(), TimeSamplingV1Mixin::create(), UtmV1Mixin::create()]);
 }
예제 #30
0
 /**
  * @return Schema
  */
 protected static function defineSchema()
 {
     return new Schema('pbj:eme:solicits:request:search-submissions-request:1-0-0', __CLASS__, [Fb::create('solicit_id', T\IdentifierType::create())->className('Eme\\Schemas\\Solicits\\SolicitId')->build(), Fb::create('first_name', T\StringType::create())->build(), Fb::create('last_name', T\StringType::create())->build(), Fb::create('email', T\StringType::create())->format(Format::EMAIL())->build(), Fb::create('email_domain', T\StringType::create())->format(Format::HOSTNAME())->build(), Fb::create('address', T\MessageType::create())->className('Gdbots\\Schemas\\Geo\\Address')->build(), Fb::create('age_min', T\TinyIntType::create())->max(120)->build(), Fb::create('age_max', T\TinyIntType::create())->max(120)->build(), Fb::create('is_blocked', T\TrinaryType::create())->build(), Fb::create('is_read', T\TrinaryType::create())->build(), Fb::create('last_read_after', T\DateTimeType::create())->build(), Fb::create('last_read_before', T\DateTimeType::create())->build(), Fb::create('last_read_by_ref', T\MessageRefType::create())->build(), Fb::create('is_verified', T\TrinaryType::create())->build()], [AccountRefV1Mixin::create(), RequestV1Mixin::create(), SearchEventsRequestV1Mixin::create(), TrackedMessageV1Mixin::create()]);
 }