|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Spiral Framework. |
|
4
|
|
|
* |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* @author Anton Titov (Wolfy-J) |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Spiral\ORM\Entities; |
|
9
|
|
|
|
|
10
|
|
|
use Spiral\Database\Entities\Database; |
|
11
|
|
|
use Spiral\Database\Entities\Table; |
|
12
|
|
|
use Spiral\ORM\ORMInterface; |
|
13
|
|
|
|
|
14
|
|
|
class RecordMapper |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Related ODM model. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
private $class = ''; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var ORMInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $orm = null; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $class |
|
30
|
|
|
* @param ORMInterface $orm |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct($class, ORMInterface $orm) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->class = $class; |
|
35
|
|
|
$this->orm = $orm; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return string |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getTable() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->orm->schema($this->class, ORMInterface::M_TABLE); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getDatabase() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->orm->schema($this->class, ORMInterface::M_DB); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Insert new row into dbal table. |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $data |
|
58
|
|
|
* @return bool|\MongoId|null Null if failure. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function insert(array $data) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
//todo: implement |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Update row in related table. |
|
67
|
|
|
* |
|
68
|
|
|
* @param array $criteria Search criteria (usually id => value) |
|
69
|
|
|
* @param array $updates DBAL updates, must be provided in a form of column => value and can |
|
70
|
|
|
* include expressions. |
|
71
|
|
|
* @return bool |
|
72
|
|
|
*/ |
|
73
|
|
|
public function update(array $criteria, array $updates) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
//todo: implement |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Delete document from related collection. |
|
80
|
|
|
* |
|
81
|
|
|
* @param array $criteria Search criteria (usually id => value) |
|
82
|
|
|
* @return array|bool |
|
83
|
|
|
*/ |
|
84
|
|
|
public function delete(array $criteria) |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
//todo: implement |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return Table |
|
91
|
|
|
*/ |
|
92
|
|
|
private function dbalTable() |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
return $this->dbalDatabase()->table($this->getTable()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return Database |
|
99
|
|
|
*/ |
|
100
|
|
|
private function dbalDatabase() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->orm->database($this->getDatabase()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.