@@ -23,6 +23,40 @@ class ImageType extends StringType
2323
2424 private string $ name = 'image ' ;
2525
26+ /**
27+ * @param class-string<PersistentImage> $className
28+ */
29+ public static function register (Connection $ connection , string $ name = 'image ' , string $ dbName = 'db_image ' , string $ className = PersistentImage::class): void
30+ {
31+ if (!$ connection ->getDatabasePlatform ()->hasDoctrineTypeMappingFor ($ dbName )) {
32+ self ::registerType ($ name , $ className );
33+
34+ $ connection ->getDatabasePlatform ()->registerDoctrineTypeMapping ($ dbName , $ name );
35+ }
36+ }
37+
38+ /**
39+ * @param class-string<PersistentImage> $className
40+ */
41+ public static function registerType (string $ name = 'image ' , string $ className = PersistentImage::class): void
42+ {
43+ if (Type ::hasType ($ name )) {
44+ $ class = Type ::getTypesMap ()[$ name ];
45+
46+ if ($ class !== static ::class) {
47+ throw new LogicException (
48+ sprintf ('Doctrine type %s is already registered for class %s ' , $ name , $ class )
49+ );
50+ }
51+ } else {
52+ $ self = new self ();
53+ $ self ->name = $ name ;
54+ $ self ->className = $ className ;
55+
56+ self ::getTypeRegistry ()->register ($ name , $ self );
57+ }
58+ }
59+
2660 public function getDatabaseConverter (): DatabaseConverterInterface
2761 {
2862 if (!isset ($ this ->databaseConverter )) {
@@ -81,38 +115,4 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
81115 return true ;
82116 }
83117
84- /**
85- * @param class-string<PersistentImage> $className
86- */
87- public static function register (Connection $ connection , string $ name = 'image ' , string $ dbName = 'db_image ' , string $ className = PersistentImage::class): void
88- {
89- if (!$ connection ->getDatabasePlatform ()->hasDoctrineTypeMappingFor ($ dbName )) {
90- self ::registerType ($ name , $ className );
91-
92- $ connection ->getDatabasePlatform ()->registerDoctrineTypeMapping ($ dbName , $ name );
93- }
94- }
95-
96- /**
97- * @param class-string<PersistentImage> $className
98- */
99- public static function registerType (string $ name = 'image ' , string $ className = PersistentImage::class): void
100- {
101- if (Type ::hasType ($ name )) {
102- $ class = Type ::getTypesMap ()[$ name ];
103-
104- if ($ class !== static ::class) {
105- throw new LogicException (
106- sprintf ('Doctrine type %s is already registered for class %s ' , $ name , $ class )
107- );
108- }
109- } else {
110- $ self = new self ();
111- $ self ->name = $ name ;
112- $ self ->className = $ className ;
113-
114- self ::getTypeRegistry ()->register ($ name , $ self );
115- }
116- }
117-
118118}
0 commit comments