vendor/api-platform/core/src/Elasticsearch/Metadata/Document/DocumentMetadata.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the API Platform project.
  4. *
  5. * (c) Kévin Dunglas <dunglas@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. declare(strict_types=1);
  11. namespace ApiPlatform\Elasticsearch\Metadata\Document;
  12. /**
  13. * Document metadata.
  14. *
  15. * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-fields.html
  16. *
  17. * @experimental
  18. *
  19. * @author Baptiste Meyer <baptiste.meyer@gmail.com>
  20. */
  21. final class DocumentMetadata
  22. {
  23. public const DEFAULT_TYPE = '_doc';
  24. private $index;
  25. private $type;
  26. public function __construct(string $index = null, string $type = self::DEFAULT_TYPE)
  27. {
  28. $this->index = $index;
  29. $this->type = $type;
  30. }
  31. /**
  32. * Gets a new instance with the given index.
  33. */
  34. public function withIndex(string $index): self
  35. {
  36. $metadata = clone $this;
  37. $metadata->index = $index;
  38. return $metadata;
  39. }
  40. /**
  41. * Gets the document index.
  42. */
  43. public function getIndex(): ?string
  44. {
  45. return $this->index;
  46. }
  47. /**
  48. * Gets a new instance with the given type.
  49. */
  50. public function withType(string $type): self
  51. {
  52. $metadata = clone $this;
  53. $metadata->type = $type;
  54. return $metadata;
  55. }
  56. /**
  57. * Gets the document type.
  58. */
  59. public function getType(): string
  60. {
  61. return $this->type;
  62. }
  63. }
  64. class_alias(DocumentMetadata::class, \ApiPlatform\Core\Bridge\Elasticsearch\Metadata\Document\DocumentMetadata::class);