-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInsert.php
More file actions
44 lines (33 loc) · 1.08 KB
/
Insert.php
File metadata and controls
44 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace UniMapper\Query;
use UniMapper\Entity\Reflection;
class Insert extends \UniMapper\Query
{
/** @var \UniMapper\Entity */
protected $entity;
public function __construct(
Reflection $reflection,
array $data
) {
parent::__construct($reflection);
$this->entity = $reflection->createEntity($data);
}
protected function onExecute(\UniMapper\Connection $connection)
{
$adapter = $connection->getAdapter($this->reflection->getAdapterName());
$mapper = $connection->getMapper();
$query = $adapter->createInsert(
$this->reflection->getAdapterResource(),
$mapper->unmapEntity($this->entity),
$this->reflection->hasPrimary() ? $this->reflection->getPrimaryProperty()->getUnmapped() : null
);
$primaryValue = $adapter->execute($query);
if ($this->reflection->hasPrimary()) {
$t = $mapper->mapValue(
$this->reflection->getPrimaryProperty(),
$primaryValue
);
return $t;
}
}
}