Пример #1
0
 /**
  * Generates and writes schema related files.
  *
  * @param SchemaDescriptor $schema
  *
  * @return GeneratorResponse
  */
 public function generateSchema(SchemaDescriptor $schema)
 {
     $response = new GeneratorResponse();
     foreach ($schema->getFields() as $field) {
         $this->updateFieldOptions($schema, $field);
     }
     foreach ($this->getSchemaTemplates($schema) as $template => $filename) {
         $response->addFile($this->renderFile($template, $this->getSchemaTarget($schema, $filename), $this->getSchemaParameters($schema)));
     }
     if ($schema->isLatestVersion()) {
         foreach ($this->getSchemaTemplates($schema) as $template => $filename) {
             if ($this->getSchemaTarget($schema, $filename) != $this->getSchemaTarget($schema, $filename, null, true)) {
                 $response->addFile($this->renderFile($template, $this->getSchemaTarget($schema, $filename, null, true), $this->getSchemaParameters($schema)));
             }
         }
     }
     return $response;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function generateManifest(array $schemas)
 {
     $messages = [];
     if (!($filename = $this->compileOptions->getManifest())) {
         return;
     }
     // extract previous schemas
     if (file_exists($filename)) {
         $content = file_get_contents($filename);
         if (preg_match_all('/\'([a-z0-9-]+:[a-z0-9\\.-]+:[a-z0-9-]+?:[a-z0-9-]+(:v[0-9]+)?)\' => \'(.*)\'/', $content, $matches) !== false) {
             foreach ($matches[1] as $key => $value) {
                 $messages[$value] = $matches[3][$key];
             }
         }
     }
     // merge with selected schemas (only non-mixin schema's)
     /** @var SchemaDescriptor $schema */
     foreach ($schemas as $schema) {
         if ($schema->isMixinSchema()) {
             continue;
         }
         if (!array_key_exists($schema->getId()->getCurie(), $messages)) {
             $messages[$schema->getId()->getCurie()] = sprintf('%s\\%sV%d', $schema->getLanguage('php')->get('namespace'), StringUtils::toCamelFromSlug($schema->getId()->getMessage()), $schema->getId()->getVersion()->getMajor());
         }
         if (SchemaStore::hasOtherSchemaMajorRev($schema->getId())) {
             /** @var SchemaDescriptor $s */
             foreach (SchemaStore::getOtherSchemaMajorRev($schema->getId()) as $s) {
                 if (!array_key_exists($s->getId()->getCurieWithMajorRev(), $messages)) {
                     $messages[$s->getId()->getCurieWithMajorRev()] = sprintf('%s\\%sV%d', $s->getLanguage('php')->get('namespace'), StringUtils::toCamelFromSlug($s->getId()->getMessage()), $s->getId()->getVersion()->getMajor());
                 }
             }
         }
     }
     // delete invalid schemas
     foreach ($messages as $key => $value) {
         if (!SchemaStore::getSchemaById($key, true)) {
             unset($messages[$key]);
         }
     }
     $response = new GeneratorResponse();
     $response->addFile($this->renderFile('manifest.twig', $filename, ['messages' => $messages]));
     return $response;
 }