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