IndexMetadata.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Michel\PaperORM\Metadata;
  3. use Michel\PaperORM\Mapping\Column\JoinColumn;
  4. final class IndexMetadata
  5. {
  6. private string $tableName;
  7. private ?string $name;
  8. private array $columns;
  9. private bool $unique;
  10. public function __construct(string $tableName, ?string $name, array $columns, bool $unique = false)
  11. {
  12. $this->tableName = $tableName;
  13. $this->name = strtoupper($name);
  14. $this->columns = $columns;
  15. $this->unique = $unique;
  16. }
  17. public function getTableName(): string
  18. {
  19. return $this->tableName;
  20. }
  21. public function getName(): ?string
  22. {
  23. return $this->name;
  24. }
  25. public function getColumns(): array
  26. {
  27. return $this->columns;
  28. }
  29. public function isUnique(): bool
  30. {
  31. return $this->unique;
  32. }
  33. public static function fromArray(array $data): self
  34. {
  35. return new self(
  36. $data['tableName'],
  37. $data['name'],
  38. $data['columns'],
  39. $data['unique']
  40. );
  41. }
  42. public function toArray(): array
  43. {
  44. return [
  45. 'tableName' => $this->getTableName(),
  46. 'name' => $this->getName(),
  47. 'columns' => $this->getColumns(),
  48. 'unique' => $this->isUnique()
  49. ];
  50. }
  51. }