Skip to content

Commit

Permalink
Merge pull request #35 from beblife/master
Browse files Browse the repository at this point in the history
Add method to configure dynamic mapping on index
  • Loading branch information
babenkoivan authored Apr 25, 2023
2 parents 949ca4a + 0f7f745 commit 25f5ca3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Indices/Mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ final class Mapping implements Arrayable
private ?bool $isSourceEnabled;
private MappingProperties $properties;
private array $dynamicTemplates = [];
/**
* @var string|bool|null
*/
private $dynamic;

public function __construct()
{
Expand Down Expand Up @@ -90,6 +94,16 @@ public function disableSource(): self
return $this;
}

/**
* @param string|bool $dynamic
*/
public function dynamic($dynamic): self
{
$this->dynamic = $dynamic;

return $this;
}

public function dynamicTemplate(string $name, array $parameters): self
{
$this->dynamicTemplates[] = [$name => $parameters];
Expand Down Expand Up @@ -119,6 +133,10 @@ public function toArray(): array
];
}

if(isset($this->dynamic)) {
$mapping['dynamic'] = $this->dynamic;
}

if (!empty($properties)) {
$mapping['properties'] = $properties;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Indices/MappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public function test_source_can_be_enabled(): void
], $mapping->toArray());
}

public function test_dynamic_mapping_can_be_configured(): void
{
$mapping = (new Mapping())->dynamic('strict');

$this->assertSame([
'dynamic' => 'strict',
], $mapping->toArray());
}

public function test_default_array_casting(): void
{
$this->assertSame([], (new Mapping())->toArray());
Expand Down

0 comments on commit 25f5ca3

Please sign in to comment.