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