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; |
15
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Collections\Meta; |
17
|
|
|
use Maslosoft\Mangan\Interfaces\ActiveDocumentInterface; |
18
|
|
|
use Maslosoft\Mangan\Sanitizers\MongoObjectId; |
19
|
|
|
use Maslosoft\Mangan\Traits\I18NAbleTrait; |
20
|
|
|
use Maslosoft\Mangan\Traits\OwneredTrait; |
21
|
|
|
use Maslosoft\Mangan\Traits\ScenariosTrait; |
22
|
|
|
use Maslosoft\Mangan\Traits\ValidatableTrait; |
23
|
|
|
use MongoId; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* EmbeddedDocument |
27
|
|
|
* |
28
|
|
|
* @author Ianaré Sévi |
29
|
|
|
* @author Dariusz Górecki <[email protected]> |
30
|
|
|
* @author Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org |
31
|
|
|
* @author Piotr Maselkowski, Maslosoft |
32
|
|
|
* @copyright 2011 CleverIT http://www.cleverit.com.pl |
33
|
|
|
* @copyright 2013 Maslosoft http://maslosoft.com |
34
|
|
|
* @since v1.0.8 |
35
|
|
|
* @property Meta $meta Model metadata |
36
|
|
|
*/ |
37
|
|
|
abstract class EmbeddedDocument implements ActiveDocumentInterface |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
use I18NAbleTrait, |
41
|
|
|
OwneredTrait, |
42
|
|
|
ScenariosTrait, |
43
|
|
|
ValidatableTrait; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Mongo id field |
47
|
|
|
* NOTE: This is usefull for embedded documents too, as it is used for keeping order |
48
|
|
|
* @Label('Database ID') |
49
|
|
|
* @Sanitizer(MongoObjectId) |
50
|
|
|
* @see MongoObjectId |
51
|
|
|
* @var MongoId|null |
52
|
|
|
*/ |
53
|
|
|
public $_id = null; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* This holds type of this embedded document. |
57
|
|
|
* While this field is not required, it is usefull in some scenarios, |
58
|
|
|
* for example to generate JavaScript model classes from PHP classes. |
59
|
|
|
* @SafeValidator |
60
|
|
|
* @var string |
61
|
|
|
*/ |
62
|
|
|
public $_class = ''; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Constructor. |
66
|
|
|
* @param string $scenario name of the scenario that this model is used in. |
67
|
|
|
* See {@link Model::scenario} on how scenario is used by models. |
68
|
|
|
* @see getScenario |
69
|
|
|
* @since v1.0.8 |
70
|
|
|
*/ |
71
|
9 |
|
public function __construct($scenario = 'insert', $lang = '') |
72
|
|
|
{ |
73
|
9 |
|
$this->_id = new MongoId; |
74
|
|
|
|
75
|
9 |
|
$this->_class = static::class; |
76
|
|
|
|
77
|
9 |
|
$this->setLang($lang); |
78
|
9 |
|
$this->setScenario($scenario); |
79
|
9 |
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|