1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebStream\Database; |
4
|
|
|
|
5
|
|
|
use WebStream\DI\Injector; |
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* EntityManager |
9
|
|
|
* @author Ryuichi TANAKA. |
10
|
|
|
* @since 2015/01/11 |
11
|
|
|
* @version 0.7 |
12
|
|
|
*/ |
13
|
|
|
class EntityManager |
14
|
|
|
{ |
15
|
|
|
use Injector; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string エンティティクラスパス |
19
|
|
|
*/ |
20
|
|
|
private $classpath; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array<string> カラムメタ情報 |
24
|
|
|
*/ |
25
|
|
|
private $columnMeta; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* コンストラクタ |
29
|
|
|
* @param string エンティティクラスパス |
|
|
|
|
30
|
|
|
*/ |
31
|
16 |
|
public function __construct($classpath) |
32
|
|
|
{ |
33
|
16 |
|
$this->classpath = $classpath; |
34
|
16 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* カラムメタ情報を設定する |
38
|
|
|
* @param string カラムメタ情報 |
|
|
|
|
39
|
|
|
*/ |
40
|
16 |
|
public function setColumnMeta(array $columnMeta) |
41
|
|
|
{ |
42
|
16 |
|
$this->columnMeta = $columnMeta; |
43
|
16 |
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* 列データをエンティティに変換して返却する |
47
|
|
|
* @param array<string> 列データ |
|
|
|
|
48
|
|
|
* @return object 列データエンティティ |
49
|
|
|
*/ |
50
|
16 |
|
public function getEntity($row) |
51
|
|
|
{ |
52
|
16 |
|
$instance = new $this->classpath(); |
53
|
16 |
|
$propertyMap = null; |
54
|
|
|
|
55
|
|
|
// EntityPropertyを使っている場合はリフレクションを使用しない |
56
|
|
|
if (!array_key_exists(EntityProperty::class, class_uses($instance))) { |
57
|
8 |
|
$propertyMap = []; |
58
|
8 |
|
$refClass = new \ReflectionClass($instance); |
59
|
8 |
|
$properties = $refClass->getProperties(); |
60
|
8 |
|
foreach ($properties as $property) { |
61
|
8 |
|
if ($property->isPrivate() || $property->isProtected()) { |
62
|
8 |
|
$property->setAccessible(true); |
63
|
|
|
} |
64
|
8 |
|
$propertyMap[strtolower($property->getName())] = $property; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
16 |
|
foreach ($row as $col => $value) { |
69
|
16 |
|
switch ($this->columnMeta[$col]) { |
70
|
16 |
|
case 'LONG': // mysql:int |
71
|
16 |
|
case 'SHORT': // mysql:smallint |
72
|
16 |
|
case 'int4': // postgres:int |
73
|
16 |
|
case 'int2': // postgres:smallint |
74
|
16 |
|
case 'integer': // sqlite:int |
75
|
16 |
|
case 'smallint': // sqlite:smallint |
76
|
16 |
|
$value = intval($value); |
77
|
16 |
|
break; |
78
|
16 |
|
case 'LONGLONG': // mysql:bigint |
79
|
16 |
|
case 'int8': // postgres:bigint |
80
|
16 |
|
case 'bigint': // sqlite:bigint |
81
|
|
|
$value = doubleval($value); |
82
|
|
|
break; |
83
|
16 |
|
case 'DATETIME': // mysql:datetime |
84
|
16 |
|
case 'DATE': // mysql:date |
85
|
16 |
|
case 'timestamp': // postgres:timestamp, sqlite:timestamp |
86
|
16 |
|
case 'date': // postgres:date, sqlite:date |
87
|
|
|
$value = new \DateTime($value); |
88
|
|
|
break; |
89
|
|
|
default: // string |
90
|
16 |
|
break; |
91
|
|
|
} |
92
|
|
|
|
93
|
16 |
|
$col = strtolower(preg_replace_callback('/_([a-zA-Z])/', function ($matches) { |
94
|
|
|
return ucfirst($matches[1]); |
95
|
16 |
|
}, $col)); |
96
|
|
|
|
97
|
16 |
|
if ($propertyMap === null) { |
98
|
8 |
|
$instance->{$col} = $value; |
99
|
|
|
} else { |
100
|
8 |
|
if (array_key_exists($col, $propertyMap)) { |
101
|
8 |
|
$propertyMap[$col]->setValue($instance, $value); |
102
|
|
|
} else { |
103
|
|
|
$this->logger->error("Column '$col' is failed mapping in " . $this->classpath); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
16 |
|
return $instance; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths