|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
|
5
|
|
|
* |
|
6
|
|
|
* @package maslosoft/mangan |
|
7
|
|
|
* @licence AGPL or Commercial |
|
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) Maslosoft |
|
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
|
11
|
|
|
* @link https://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Annotations; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Mangan\Decorators\DbRefArrayDecorator; |
|
17
|
|
|
use Maslosoft\Mangan\Decorators\EmbedRefArrayDecorator; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DB reference array annotation is used to create reference to other |
|
21
|
|
|
* or same collection items. |
|
22
|
|
|
* |
|
23
|
|
|
* All parameters are optional. However it is recommended to set |
|
24
|
|
|
* first parameter - default class for referenced objects. |
|
25
|
|
|
* |
|
26
|
|
|
* It takes first parameter as class name or class literal, and |
|
27
|
|
|
* second parameter to indicate if it should be updated along with |
|
28
|
|
|
* parent model. |
|
29
|
|
|
* |
|
30
|
|
|
* Most simple example - will allow many of any object types to be referenced: |
|
31
|
|
|
* ``` |
|
32
|
|
|
* @DbRefArray |
|
33
|
|
|
* ``` |
|
34
|
|
|
* |
|
35
|
|
|
* Example of updatable DB reference: |
|
36
|
|
|
* ``` |
|
37
|
|
|
* @DbRefArray(ClassLiteral, true) |
|
38
|
|
|
* ``` |
|
39
|
|
|
* |
|
40
|
|
|
* @template DbRefArray(${class}, ${updatable}) |
|
41
|
|
|
* |
|
42
|
|
|
* @Conflicts('Embedded') |
|
43
|
|
|
* @Conflicts('EmbeddedArray') |
|
44
|
|
|
* @Conflicts('DbRef') |
|
45
|
|
|
* @Conflicts('Related') |
|
46
|
|
|
* @Conflicts('RelatedArray') |
|
47
|
|
|
* |
|
48
|
|
|
* @Target('property') |
|
49
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
50
|
|
|
*/ |
|
51
|
|
|
class DbRefArrayAnnotation extends DbRefAnnotation |
|
52
|
|
|
{ |
|
53
|
|
|
|
|
54
|
|
|
public $value = []; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Comparing key. This is used to update db ref instances from external sources. |
|
58
|
|
|
* @var string|array |
|
59
|
|
|
*/ |
|
60
|
|
|
public $key = null; |
|
61
|
|
|
|
|
62
|
7 |
|
public function init() |
|
63
|
|
|
{ |
|
64
|
7 |
|
$refMeta = $this->getDbRefMeta(); |
|
65
|
7 |
|
$refMeta->key = $this->key; |
|
66
|
7 |
|
$refMeta->single = false; |
|
67
|
7 |
|
$refMeta->isArray = true; |
|
68
|
7 |
|
$this->getEntity()->dbRef = $refMeta; |
|
69
|
7 |
|
$this->getEntity()->propagateEvents = true; |
|
70
|
7 |
|
$this->getEntity()->owned = true; |
|
71
|
7 |
|
$this->getEntity()->decorators[] = DbRefArrayDecorator::class; |
|
72
|
7 |
|
$this->getEntity()->decorators[] = EmbedRefArrayDecorator::class; |
|
73
|
|
|
// Do not call parent init |
|
74
|
7 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|