@@ -15,15 +15,15 @@ class Sql
1515
1616 protected TableIdentifier |string |array |null $ table ;
1717
18- protected Platform \Platform $ sqlPlatform ;
18+ protected Platform \PlatformDecoratorInterface $ sqlPlatform ;
1919
2020 public function __construct (
2121 AdapterInterface $ adapter ,
2222 array |string |TableIdentifier |null $ table = null
2323 ) {
24- $ this ->adapter = $ adapter ;
2524 $ this ->table = $ table ;
26- $ this ->sqlPlatform = new Platform \Platform ($ adapter ->getPlatform ());
25+ $ this ->adapter = $ adapter ;
26+ $ this ->sqlPlatform = $ adapter ->getPlatform ()->getSqlPlatformDecorator ();
2727 }
2828
2929 public function getAdapter (): ?AdapterInterface
@@ -51,7 +51,7 @@ public function getTable(): array|string|TableIdentifier|null
5151 return $ this ->table ;
5252 }
5353
54- public function getSqlPlatform (): ?Platform \Platform
54+ public function getSqlPlatform (): ?Platform \PlatformDecoratorInterface
5555 {
5656 return $ this ->sqlPlatform ;
5757 }
@@ -109,10 +109,17 @@ public function prepareStatementForSqlObject(
109109 ?StatementInterface $ statement = null ,
110110 ?AdapterInterface $ adapter = null
111111 ): StatementInterface {
112+ if (! $ this ->sqlPlatform instanceof PreparableSqlInterface) {
113+ throw new Exception \RuntimeException (
114+ 'The subject does not implement PreparableSqlInterface '
115+ );
116+ }
117+
112118 $ adapter ??= $ this ->adapter ;
113119 $ statement ??= $ adapter ->getDriver ()->createStatement ();
114120
115- $ this ->sqlPlatform ->setSubject ($ sqlObject )->prepareStatement ($ adapter , $ statement );
121+ $ this ->sqlPlatform ->setSubject ($ sqlObject );
122+ $ this ->sqlPlatform ->prepareStatement ($ adapter , $ statement );
116123
117124 return $ statement ;
118125 }
@@ -122,11 +129,16 @@ public function prepareStatementForSqlObject(
122129 */
123130 public function buildSqlString (SqlInterface $ sqlObject , ?AdapterInterface $ adapter = null ): string
124131 {
125- return $ this
126- ->sqlPlatform
127- ->setSubject ($ sqlObject )
128- ->getSqlString (
129- $ adapter instanceof AdapterInterface ? $ adapter ->getPlatform () : $ this ->adapter ->getPlatform ()
132+ if (! $ this ->sqlPlatform instanceof SqlInterface) {
133+ throw new Exception \RuntimeException (
134+ 'The subject does not implement SqlInterface '
130135 );
136+ }
137+
138+ $ this ->sqlPlatform ->setSubject ($ sqlObject );
139+
140+ return $ this ->sqlPlatform ->getSqlString (
141+ $ adapter instanceof AdapterInterface ? $ adapter ->getPlatform () : $ this ->adapter ->getPlatform ()
142+ );
131143 }
132144}
0 commit comments