1 | <?php |
||
13 | abstract class AbstractType implements IType |
||
14 | { |
||
15 | /** |
||
16 | * Include generics interpolation functionality |
||
17 | */ |
||
18 | use \Generics\Util\Interpolator; |
||
19 | |||
20 | /** |
||
21 | * Interpolate a string |
||
22 | * |
||
23 | * @param string $string |
||
24 | * The string to interpolate |
||
25 | * @param array $context |
||
26 | * The context variables and values to replace |
||
27 | * |
||
28 | * @return string The interpolated string |
||
29 | */ |
||
30 | 13 | protected function interp(string $string, array $context): string |
|
34 | |||
35 | /** |
||
36 | * Retrieve primary key column for given table |
||
37 | * |
||
38 | * @param Orm $orm |
||
39 | * The Orm instance |
||
40 | * @param string $table |
||
41 | * The name of tablee |
||
42 | * @param string $query |
||
43 | * The sql query which retrieves the column name |
||
44 | * |
||
45 | * @return string The column name |
||
46 | * |
||
47 | * @throws \Nkey\Caribu\Orm\OrmException |
||
48 | */ |
||
49 | 2 | protected function getPrimaryColumnViaSql(\Nkey\Caribu\Orm\Orm $orm, string $table, string $query): string |
|
78 | |||
79 | /** |
||
80 | * Change the locks on table or row via sql |
||
81 | * |
||
82 | * @param Orm $orm |
||
83 | * The Orm instance |
||
84 | * @param string $table |
||
85 | * The table name |
||
86 | * @param string $sql |
||
87 | * The sql to execute for changing the lock level |
||
88 | * |
||
89 | * @throws \Nkey\Caribu\Orm\OrmException |
||
90 | */ |
||
91 | 8 | protected function changeLockViaSql(\Nkey\Caribu\Orm\Orm $orm, string $table, string $sql) |
|
92 | { |
||
93 | 8 | $connection = $orm->getConnection(); |
|
94 | |||
95 | try { |
||
96 | 8 | if ($connection->exec($sql) === false) { |
|
97 | throw new \Nkey\Caribu\Orm\OrmException("Could not change lock type table {table}", array( |
||
98 | 8 | 'table' => $table |
|
99 | )); |
||
100 | } |
||
101 | } catch (\PDOException $exception) { |
||
102 | throw \Nkey\Caribu\Orm\OrmException::fromPrevious($exception, "Could not change lock type of table"); |
||
103 | } |
||
104 | 8 | } |
|
105 | |||
106 | /** |
||
107 | * Map the type result from statement into an orm type |
||
108 | * |
||
109 | * @param array $result |
||
110 | * |
||
111 | * @return int The orm type mapped |
||
112 | */ |
||
113 | abstract protected function mapType(array $result): int; |
||
114 | |||
115 | /** |
||
116 | * Retrieve query which is results a mapable type from database |
||
117 | * |
||
118 | * @return string The query |
||
119 | */ |
||
120 | abstract protected function getTypeQuery(): string; |
||
121 | |||
122 | /** |
||
123 | * (non-PHPdoc) |
||
124 | * |
||
125 | * @see \Nkey\Caribu\Type\IType::getColumnType() |
||
126 | */ |
||
127 | 6 | public function getColumnType(string $table, string $columnName, \Nkey\Caribu\Orm\Orm $orm): int |
|
156 | |||
157 | /** |
||
158 | * Handle empty result while query table column |
||
159 | * |
||
160 | * @param string $table |
||
161 | * The name of table |
||
162 | * @param string $columnName |
||
163 | * The name of column |
||
164 | * @param Orm $orm |
||
165 | * The orm instance |
||
166 | * @param \PDOStatement $stmt |
||
167 | * The prepared statement |
||
168 | * @param array $result |
||
169 | * The result either filled or empty |
||
170 | * |
||
171 | * @throws \Nkey\Caribu\Orm\OrmException |
||
172 | */ |
||
173 | 6 | protected function handleNoColumn(string $table, string $columnName, \Nkey\Caribu\Orm\Orm $orm, \PDOStatement $stmt, array $result) |
|
184 | } |
||
185 |