Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * @param string $string
  * @param \DateTime $date
  * @return static
  */
 public static function create($string, \DateTime $date = null)
 {
     $slug = SlugUtils::create($string, true);
     if (SlugUtils::containsDate($slug)) {
         return new static($slug);
     }
     $date = $date ?: new \DateTime();
     $slug = SlugUtils::addDate($slug, $date);
     return new static($slug);
 }
Esempio n. 3
0
 /**
  * @param string $string
  *
  * @return string
  */
 public function slugify($string)
 {
     return SlugUtils::create($string);
 }
Esempio n. 4
0
 /**
  * @param string $string
  * @return static
  */
 public static function create($string)
 {
     return new static(SlugUtils::create($string));
 }