1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cycle\Annotated\Annotation\Relation\Morphed; |
6
|
|
|
|
7
|
|
|
use Cycle\Annotated\Annotation\Relation\Inverse; |
8
|
|
|
use Cycle\Annotated\Annotation\Relation\Relation; |
9
|
|
|
use Cycle\Annotated\Annotation\Relation\Traits\InverseTrait; |
10
|
|
|
use JetBrains\PhpStorm\ExpectedValues; |
11
|
|
|
use Spiral\Attributes\NamedArgumentConstructor; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @Annotation |
15
|
|
|
* @NamedArgumentConstructor |
16
|
|
|
* @Target("PROPERTY") |
17
|
|
|
*/ |
18
|
|
|
#[\Attribute(\Attribute::TARGET_PROPERTY), NamedArgumentConstructor] |
19
|
|
|
final class MorphedHasMany extends Relation |
20
|
|
|
{ |
21
|
|
|
use InverseTrait; |
22
|
|
|
|
23
|
|
|
protected const TYPE = 'morphedHasMany'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @param non-empty-string $target |
|
|
|
|
27
|
|
|
* @param bool $cascade Automatically save related data with parent entity. |
28
|
|
|
* @param bool $nullable Defines if the relation can be nullable (child can have no parent). |
29
|
|
|
* @param array|string|null $innerKey Inner key in parent entity. Defaults to the primary key. |
30
|
|
|
* @param array|string|null $outerKey Outer key name. Defaults to `{parentRole}_{innerKey}`. |
31
|
|
|
* @param string $morphKey Name of key to store related entity role. Defaults to `{relationName}_role`. |
32
|
|
|
* @param int $morphKeyLength The length of morph key. |
33
|
|
|
* @param array $where Additional where condition to be applied for the relation. |
34
|
|
|
* @param bool $indexCreate Create an index on morphKey and innerKey. |
35
|
|
|
* @param string|null $collection Collection that will contain loaded entities. |
36
|
|
|
* @param non-empty-string $load Relation load approach. |
37
|
|
|
* @param Inverse|null $inverse |
38
|
|
|
*/ |
39
|
496 |
|
public function __construct( |
40
|
|
|
string $target, |
41
|
|
|
protected bool $cascade = true, |
42
|
|
|
protected bool $nullable = false, |
43
|
|
|
protected array|string|null $innerKey = null, |
44
|
|
|
protected array|string|null $outerKey = null, |
45
|
|
|
protected ?string $morphKey = null, |
46
|
|
|
protected int $morphKeyLength = 32, |
47
|
|
|
protected array $where = [], |
48
|
|
|
protected bool $indexCreate = true, |
49
|
|
|
protected ?string $collection = null, |
50
|
|
|
#[ExpectedValues(values: ['lazy', 'eager'])] |
51
|
|
|
string $load = 'lazy', |
52
|
|
|
?Inverse $inverse = null, |
53
|
|
|
) { |
54
|
496 |
|
$this->inverse = $inverse; |
55
|
|
|
|
56
|
496 |
|
parent::__construct($target, $load); |
57
|
496 |
|
} |
58
|
|
|
} |
59
|
|
|
|