|
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 http://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Mangan\Interfaces\ActiveRecordInterface; |
|
17
|
|
|
use Maslosoft\Mangan\Meta\ManganMeta; |
|
18
|
|
|
use Maslosoft\Mangan\Sanitizers\MongoObjectId; |
|
19
|
|
|
use MongoDB; |
|
20
|
|
|
use MongoId; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Document |
|
24
|
|
|
* |
|
25
|
|
|
* @author Ianaré Sévi |
|
26
|
|
|
* @author Dariusz Górecki <[email protected]> |
|
27
|
|
|
* @author Invenzzia Group, open-source division of CleverIT company http://www.invenzzia.org |
|
28
|
|
|
* @copyright 2011 CleverIT http://www.cleverit.com.pl |
|
29
|
|
|
* @property-read MongoDB $db |
|
30
|
|
|
* @since v1.0 |
|
31
|
|
|
*/ |
|
32
|
|
|
abstract class Document extends EmbeddedDocument implements ActiveRecordInterface |
|
33
|
|
|
{ |
|
34
|
|
|
|
|
35
|
|
|
use \Maslosoft\Mangan\Traits\EntityManagerTrait, |
|
36
|
|
|
\Maslosoft\Mangan\Traits\FinderTrait, |
|
37
|
|
|
\Maslosoft\Mangan\Traits\CollectionNameTrait, |
|
38
|
|
|
\Maslosoft\Mangan\Traits\WithCriteriaTrait; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Mongo id field |
|
42
|
|
|
* @Label('Database ID') |
|
43
|
|
|
* @Sanitizer(MongoObjectId) |
|
44
|
|
|
* @see MongoObjectId |
|
45
|
|
|
* @var MongoId|null |
|
46
|
|
|
*/ |
|
47
|
|
|
public $_id = null; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Alias to _id |
|
51
|
|
|
* @Label('Database ID') |
|
52
|
|
|
* @Persistent(false) |
|
53
|
|
|
* @Alias('_id') |
|
54
|
|
|
* @see https://github.com/Maslosoft/Mangan/issues/40 |
|
55
|
|
|
* @var string|null |
|
56
|
|
|
*/ |
|
57
|
|
|
public $id = null; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Constructor |
|
61
|
|
|
* @see ScenarioManager |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $scenario |
|
64
|
|
|
* @param string $lang Language code |
|
65
|
|
|
* @since v1.0 |
|
66
|
|
|
*/ |
|
67
|
51 |
|
public function __construct($scenario = 'insert', $lang = '') |
|
68
|
|
|
{ |
|
69
|
51 |
|
$this->_key = (string) new MongoId(); |
|
70
|
51 |
|
$this->_class = get_class($this); |
|
71
|
51 |
|
$this->setLang($lang); |
|
72
|
|
|
|
|
73
|
51 |
|
$this->setScenario($scenario); |
|
74
|
51 |
|
$this->init(); |
|
|
|
|
|
|
75
|
51 |
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Returns the empty model of the specified Document class. |
|
79
|
|
|
* It is provided for invoking class-level methods, espacially userfull for finders. |
|
80
|
|
|
* |
|
81
|
|
|
* Example usage: |
|
82
|
|
|
* ```php |
|
83
|
|
|
* $user = User::model()->findByPk('5612470866a19540308b4568'); |
|
84
|
|
|
* ``` |
|
85
|
|
|
* @param string $lang |
|
86
|
|
|
* @return Document model instance. |
|
87
|
|
|
*/ |
|
88
|
|
|
public static function model($lang = null) |
|
89
|
|
|
{ |
|
90
|
|
|
return new static(null, $lang); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.