@@ -92,7 +92,7 @@ public function save(Key $key): void
9292 try {
9393 $ stmt = $ conn ->prepare ($ sql );
9494 } catch (\PDOException $ e ) {
95- if ($ this ->isTableMissing ($ e ) && (!$ conn ->inTransaction () || \in_array ($ this ->driver , ['pgsql ' , 'sqlite ' , 'sqlsrv ' ], true ))) {
95+ if ($ this ->isTableMissing ($ e ) && (!$ conn ->inTransaction () || \in_array ($ this ->getDriver () , ['pgsql ' , 'sqlite ' , 'sqlsrv ' ], true ))) {
9696 $ this ->createTable ();
9797 }
9898 $ stmt = $ conn ->prepare ($ sql );
@@ -104,12 +104,12 @@ public function save(Key $key): void
104104 try {
105105 $ stmt ->execute ();
106106 } catch (\PDOException $ e ) {
107- if ($ this ->isTableMissing ($ e ) && (!$ conn ->inTransaction () || \in_array ($ this ->driver , ['pgsql ' , 'sqlite ' , 'sqlsrv ' ], true ))) {
107+ if ($ this ->isTableMissing ($ e ) && (!$ conn ->inTransaction () || \in_array ($ this ->getDriver () , ['pgsql ' , 'sqlite ' , 'sqlsrv ' ], true ))) {
108108 $ this ->createTable ();
109109
110110 try {
111111 $ stmt ->execute ();
112- } catch (\PDOException $ e ) {
112+ } catch (\PDOException ) {
113113 $ this ->putOffExpiration ($ key , $ this ->initialTtl );
114114 }
115115 } else {
@@ -187,11 +187,7 @@ private function getConnection(): \PDO
187187 */
188188 public function createTable (): void
189189 {
190- // connect if we are not yet
191- $ conn = $ this ->getConnection ();
192- $ driver = $ this ->getDriver ();
193-
194- $ sql = match ($ driver ) {
190+ $ sql = match ($ driver = $ this ->getDriver ()) {
195191 'mysql ' => "CREATE TABLE $ this ->table ( $ this ->idCol VARCHAR(64) NOT NULL PRIMARY KEY, $ this ->tokenCol VARCHAR(44) NOT NULL, $ this ->expirationCol INTEGER UNSIGNED NOT NULL) COLLATE utf8mb4_bin, ENGINE = InnoDB " ,
196192 'sqlite ' => "CREATE TABLE $ this ->table ( $ this ->idCol TEXT NOT NULL PRIMARY KEY, $ this ->tokenCol TEXT NOT NULL, $ this ->expirationCol INTEGER) " ,
197193 'pgsql ' => "CREATE TABLE $ this ->table ( $ this ->idCol VARCHAR(64) NOT NULL PRIMARY KEY, $ this ->tokenCol VARCHAR(64) NOT NULL, $ this ->expirationCol INTEGER) " ,
@@ -200,7 +196,7 @@ public function createTable(): void
200196 default => throw new \DomainException (sprintf ('Creating the lock table is currently not implemented for platform "%s". ' , $ driver )),
201197 };
202198
203- $ conn ->exec ($ sql );
199+ $ this -> getConnection () ->exec ($ sql );
204200 }
205201
206202 /**
@@ -215,14 +211,7 @@ private function prune(): void
215211
216212 private function getDriver (): string
217213 {
218- if (isset ($ this ->driver )) {
219- return $ this ->driver ;
220- }
221-
222- $ conn = $ this ->getConnection ();
223- $ this ->driver = $ conn ->getAttribute (\PDO ::ATTR_DRIVER_NAME );
224-
225- return $ this ->driver ;
214+ return $ this ->driver ??= $ this ->getConnection ()->getAttribute (\PDO ::ATTR_DRIVER_NAME );
226215 }
227216
228217 /**
@@ -245,15 +234,13 @@ private function isTableMissing(\PDOException $exception): bool
245234 $ driver = $ this ->getDriver ();
246235 $ code = $ exception ->getCode ();
247236
248- switch (true ) {
249- case 'pgsql ' === $ driver && '42P01 ' === $ code :
250- case 'sqlite ' === $ driver && str_contains ($ exception ->getMessage (), 'no such table: ' ):
251- case 'oci ' === $ driver && 942 === $ code :
252- case 'sqlsrv ' === $ driver && 208 === $ code :
253- case 'mysql ' === $ driver && 1146 === $ code :
254- return true ;
255- default :
256- return false ;
257- }
237+ return match ($ driver ) {
238+ 'pgsql ' => '42P01 ' === $ code ,
239+ 'sqlite ' => str_contains ($ exception ->getMessage (), 'no such table: ' ),
240+ 'oci ' => 942 === $ code ,
241+ 'sqlsrv ' => 208 === $ code ,
242+ 'mysql ' => 1146 === $ code ,
243+ default => false ,
244+ };
258245 }
259246}
0 commit comments