Skip to content

Commit 5b979a1

Browse files
authored
doctrine/dbal:3 compatibility (#69)
- adds doctrine/dbal:3 compatibility
1 parent a7aad04 commit 5b979a1

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"composer-plugin-api": "^2.0",
1010
"ext-bcmath": "*",
1111
"ext-json": "*",
12-
"doctrine/annotations": "~1.2",
12+
"doctrine/annotations": "^1.11.1",
1313
"doctrine/collections": "^1.6",
14-
"doctrine/dbal": "^2.0",
14+
"doctrine/dbal": "^2.13.2||^3.0.0",
1515
"doctrine/inflector": "^1.4.4|^2.0",
1616
"doctrine/orm": "~2.4",
1717
"symfony/filesystem": "^4.4||^5.0",
18-
"twig/twig": "^2.7.1||^3.0"
18+
"twig/twig": "^2.14.1||^3.0"
1919
},
2020
"require-dev": {
2121
"composer/composer": "^2.0.0",

src/AnnotationProcessor/DoctrineAnnotationProcessor.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Hostnet\Component\AccessorGenerator\AnnotationProcessor;
88

9-
use Doctrine\DBAL\Types\Type;
9+
use Doctrine\DBAL\Types\Types;
1010
use Doctrine\ORM\Mapping\Column;
1111
use Doctrine\ORM\Mapping\GeneratedValue;
1212
use Doctrine\ORM\Mapping\JoinColumn;
@@ -27,7 +27,11 @@ class DoctrineAnnotationProcessor implements AnnotationProcessorInterface
2727
private const ZEROED_DATE_TIME = 'zeroeddatetime';
2828
private const ZEROED_DATE = 'zeroeddate';
2929
private const YAML_ARRAY = 'yaml_array';
30-
private const NULLABLE_TYPES = [self::ZEROED_DATE, self::ZEROED_DATE_TIME];
30+
/**
31+
* @deprecated since doctrine/dbal:2.6
32+
*/
33+
private const JSON_ARRAY = 'json_array';
34+
private const NULLABLE_TYPES = [self::ZEROED_DATE, self::ZEROED_DATE_TIME];
3135

3236
/**
3337
* Process annotations of type:
@@ -156,7 +160,7 @@ private function processBidirectional($annotation, PropertyInformation $informat
156160
protected function processColumn(Column $column, PropertyInformation $information): void
157161
{
158162
$information->setType($this->transformType($column->type));
159-
$information->setFixedPointNumber(strtolower($column->type) === Type::DECIMAL);
163+
$information->setFixedPointNumber(strtolower($column->type) === Types::DECIMAL);
160164
$information->setLength($column->length ?: 0);
161165
$information->setPrecision($column->precision);
162166
$information->setScale($column->scale);
@@ -214,43 +218,50 @@ private function processJoinColumn(JoinColumn $join_column, PropertyInformation
214218
*/
215219
private function transformType($type)
216220
{
217-
if ($type === Type::BOOLEAN) {
221+
if ($type === Types::BOOLEAN) {
218222
return 'boolean';
219223
}
220224

221-
if ($type === Type::SMALLINT || $type === Type::BIGINT || $type === Type::INTEGER) {
225+
if ($type === Types::SMALLINT || $type === Types::BIGINT || $type === Types::INTEGER) {
222226
return 'integer';
223227
}
224228

225-
if ($type === Type::FLOAT) {
229+
if ($type === Types::FLOAT) {
226230
return 'float';
227231
}
228232

229-
if ($type === Type::TEXT || $type === Type::GUID || $type === Type::STRING || $type === Type::DECIMAL) {
233+
if ($type === Types::TEXT || $type === Types::GUID || $type === Types::STRING || $type === Types::DECIMAL) {
230234
return 'string';
231235
}
232236

233-
if ($type === Type::BLOB /* binary will be added in doctrine 2.5 */) {
237+
if ($type === Types::BLOB /* binary will be added in doctrine 2.5 */) {
234238
return 'resource';
235239
}
236240

237241
if (\in_array(
238242
$type,
239-
[Type::DATETIME, Type::DATETIMETZ, Type::DATE, Type::TIME, self::ZEROED_DATE_TIME, self::ZEROED_DATE],
243+
[
244+
Types::DATETIME_MUTABLE,
245+
Types::DATETIMETZ_MUTABLE,
246+
Types::DATE_MUTABLE,
247+
Types::TIME_MUTABLE,
248+
self::ZEROED_DATE_TIME,
249+
self::ZEROED_DATE,
250+
],
240251
true
241252
)) {
242253
return '\\' . \DateTime::class;
243254
}
244255

245256
if (\in_array(
246257
$type,
247-
[Type::SIMPLE_ARRAY, Type::JSON_ARRAY, Type::JSON, Type::TARRAY, self::YAML_ARRAY],
258+
[Types::SIMPLE_ARRAY, self::JSON_ARRAY, Types::JSON, Types::ARRAY, self::YAML_ARRAY],
248259
true
249260
)) {
250261
return 'array';
251262
}
252263

253-
if ($type === Type::OBJECT) {
264+
if ($type === Types::OBJECT) {
254265
return 'object';
255266
}
256267

test/AnnotationProcessor/DoctrineAnnotationProcessorTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Hostnet\Component\AccessorGenerator\AnnotationProcessor;
88

9-
use Doctrine\DBAL\Types\Type;
9+
use Doctrine\DBAL\Types\Types;
1010
use Doctrine\ORM\Mapping\Column;
1111
use Doctrine\ORM\Mapping\GeneratedValue;
1212
use Doctrine\ORM\Mapping\JoinColumn;
@@ -75,14 +75,14 @@ public function processColumnAnnotationProvider(): iterable
7575
$explicit->scale = 9;
7676
$explicit_info->setScale(9);
7777

78-
$explicit->type = Type::BIGINT;
78+
$explicit->type = Types::BIGINT;
7979
$explicit_info->setType('integer');
8080
$explicit_info->setIntegerSize(64);
8181

8282
$explicit->unique = true;
8383
$explicit_info->setUnique(true);
8484

85-
$faulty->type = Type::DECIMAL;
85+
$faulty->type = Types::DECIMAL;
8686

8787
return [
8888
[$implicit, $implicit_info, null],

0 commit comments

Comments
 (0)