ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Definition.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 
26 {
27  private Ignore $ignore;
28 
32  public function __construct(private array $associations, ?Ignore $ignore = null)
33  {
34  $this->ignore = $ignore ?? new Ignore();
35  $this->validate();
36  }
37 
38  private function validate(): void
39  {
40  if ($this->associations === []) {
41  throw new InvalidArgumentException('Associations must not be empty.');
42  }
43 
44  array_walk($this->associations, static function ($association): void {
45  if (!$association instanceof Association) {
46  throw new InvalidArgumentException(
47  'Associations must be of type ' . Association::class . '.'
48  );
49  }
50  });
51 
52  $first = $this->associations[0];
53 
54  foreach ($this->associations as $association) {
55  if ($association->field()->tableName() !== $first->field()->tableName() ||
56  $association->referenceField()->tableName() !== $first->referenceField()->tableName()
57  ) {
58  throw new InvalidArgumentException('All fields must have the same table');
59  }
60  }
61  }
62 
63  public function tableName(): string
64  {
65  return $this->associations[0]->field()->tableName();
66  }
67 
71  public function associations(): array
72  {
73  return $this->associations;
74  }
75 
79  public function ignoreValues(): array
80  {
81  return $this->ignore->values();
82  }
83 
84  public function referenceTableName(): string
85  {
86  return $this->associations[0]->referenceField()->tableName();
87  }
88 }
__construct(private array $associations, ?Ignore $ignore=null)
Definition: Definition.php:32