Beispiel #1
0
 /**
  * @param Schema $schema
  * @param \stdClass $rootObject
  * @param string $path
  * @return array
  */
 protected function mapSchema(Schema $schema, \stdClass $rootObject, $path = null)
 {
     $map = [];
     foreach ($schema->getFields() as $field) {
         $fieldName = $field->getName();
         $type = $field->getType();
         $fieldPath = empty($path) ? $fieldName : $path . '.' . $fieldName;
         if ($fieldName === Schema::PBJ_FIELD_NAME) {
             $map[$fieldName] = ['type' => 'string', 'index' => 'not_analyzed', 'include_in_all' => false];
             continue;
         }
         $method = 'map' . ucfirst(StringUtils::toCamelFromSlug($type->getTypeValue()));
         if ($field->isAMap()) {
             $templateName = str_replace('-', '_', SlugUtils::create($fieldPath . '-template'));
             if (is_callable([$this, $method])) {
                 $rootObject->dynamic_templates[] = [$templateName => ['path_match' => $fieldPath . '.*', 'mapping' => $this->{$method}($field, $rootObject, $fieldPath)]];
             } else {
                 $rootObject->dynamic_templates[] = [$templateName => ['path_match' => $fieldPath . '.*', 'mapping' => $this->applyAnalyzer($this->types[$type->getTypeValue()], $field, $rootObject, $path)]];
             }
         } else {
             if (is_callable([$this, $method])) {
                 $map[$fieldName] = $this->{$method}($field, $rootObject, $fieldPath);
             } else {
                 $map[$fieldName] = $this->applyAnalyzer($this->types[$type->getTypeValue()], $field, $rootObject, $path);
             }
         }
     }
     return $map;
 }
Beispiel #2
0
 /**
  * Adds a single schema to the resolver.  This is used in tests or dynamic
  * message schema creation (not a typical use case).
  *
  * @param Schema $schema
  */
 public static function registerSchema(Schema $schema)
 {
     self::$messages[$schema->getId()->getCurieMajor()] = $schema->getClassName();
 }