Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function getSchemaTarget(SchemaDescriptor $schema, $filename, $directory = null, $isLatest = false)
 {
     if ($isLatest) {
         $filename = str_replace('{version}', 'latest', $filename);
     }
     $directory = sprintf('%s/%s/%s/%s', $schema->getId()->getVendor(), $schema->getId()->getPackage(), $schema->getId()->getCategory(), $schema->getId()->getMessage());
     return parent::getSchemaTarget($schema, $filename, $directory, $isLatest);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function validate(SchemaDescriptor $a, SchemaDescriptor $b)
 {
     /** @var FieldDescriptor[] $currentFields */
     /** @var FieldDescriptor[] $inheritedFields */
     $currentFields = $a->getFields();
     $inheritedFields = $a->getInheritedFields();
     $diff = array_intersect(array_keys($currentFields), array_keys($inheritedFields));
     if (count($diff)) {
         /** @var \ReflectionClass $ref */
         $ref = new \ReflectionClass(new FieldDescriptor('reflection', ['type' => 'string']));
         foreach ($diff as $name) {
             foreach ($ref->getProperties() as $property) {
                 // skip
                 if (in_array($property->getName(), ['default', 'overridable', 'description', 'languages', 'deprecated'])) {
                     continue;
                 }
                 $method = 'get' . ucfirst($property->getName());
                 if (!$ref->hasMethod($method)) {
                     $method = 'is' . ucfirst($property->getName());
                     if (!$ref->hasMethod($method)) {
                         continue;
                     }
                 }
                 /** @var FieldDescriptor $fa */
                 /** @var FieldDescriptor $fb */
                 $fa = $currentFields[$name];
                 $fb = $inheritedFields[$name];
                 if ($fa && $fb && $fa->{$method}() != $fb->{$method}()) {
                     throw new \RuntimeException(sprintf('The schema "%s" field "%s" is invalid. See inherited mixin fields.', $a->getId()->toString(), $property->getName()));
                 }
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * @param SchemaDescriptor $schema
  * @param string           $filename
  * @param string           $directory
  * @param bool             $isLatest
  *
  * @return string
  */
 protected function getSchemaTarget(SchemaDescriptor $schema, $filename, $directory = null, $isLatest = false)
 {
     $filename = str_replace(['{vendor}', '{package}', '{category}', '{version}', '{major}'], [$schema->getId()->getVendor(), $schema->getId()->getPackage(), $schema->getId()->getCategory(), $schema->getId()->getVersion()->toString(), $schema->getId()->getVersion()->getMajor()], $filename);
     if ($directory === null) {
         $directory = sprintf('%s/%s/%s', StringUtils::toCamelFromSlug($schema->getId()->getVendor()), StringUtils::toCamelFromSlug($schema->getId()->getPackage()), StringUtils::toCamelFromSlug($schema->getId()->getCategory()));
     }
     if ($directory) {
         $directory .= '/';
     }
     return sprintf('%s/%s%s%s', $this->compileOptions->getOutput(), $directory, $filename, $this->extension);
 }
Esempio n. 4
0
 /**
  * Validates a single schema against previous version.
  *
  * @param SchemaDescriptor $schema
  *
  * @throws \RuntimeException
  */
 public function validate(SchemaDescriptor $schema)
 {
     if ($prevSchema = SchemaStore::getPreviousSchema($schema->getId())) {
         if (!$prevSchema instanceof SchemaDescriptor) {
             throw new \RuntimeException(sprintf('Un-parsed schema "%s".', $prevSchema['id']));
         }
         /** @var \Gdbots\Pbjc\Validator\Constraint $constraint */
         foreach ($this->constraints as $constraint) {
             $constraint->validate($prevSchema, $schema);
         }
     }
     $constraint = new Constraint\SchemaDependencyVersion();
     $constraint->validate($schema, $schema);
     $constraint = new Constraint\SchemaInheritanceFields();
     $constraint->validate($schema, $schema);
     $constraint = new Constraint\FieldValidEnumValue();
     $constraint->validate($schema, $schema);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 protected function getSchemaTarget(SchemaDescriptor $schema, $filename, $directory = null, $isLatest = false)
 {
     $filename = str_replace(['{className}'], [StringUtils::toCamelFromSlug($schema->getId()->getMessage())], $filename);
     $directory = str_replace('\\', '/', $schema->getLanguage('php')->get('namespace'));
     return parent::getSchemaTarget($schema, $filename, $directory, $isLatest);
 }
Esempio n. 6
0
 /**
  * @param SchemaDescriptor $schema
  *
  * @return array
  */
 public function getAllVersions(SchemaDescriptor $schema)
 {
     return SchemaStore::getAllSchemaVersions($schema->getId());
 }