16
16
use Doctrine \DBAL \Schema \Schema ;
17
17
use Symfony \Component \Lock \Exception \InvalidArgumentException ;
18
18
use Symfony \Component \Lock \Exception \LockConflictedException ;
19
- use Symfony \Component \Lock \Exception \LockExpiredException ;
20
19
use Symfony \Component \Lock \Exception \NotSupportedException ;
21
20
use Symfony \Component \Lock \Key ;
22
21
use Symfony \Component \Lock \StoreInterface ;
36
35
*/
37
36
class PdoStore implements StoreInterface
38
37
{
38
+ use ExpiringStoreTrait;
39
+
39
40
private $ conn ;
40
41
private $ dsn ;
41
42
private $ driver ;
@@ -123,11 +124,6 @@ public function save(Key $key)
123
124
124
125
try {
125
126
$ stmt ->execute ();
126
- if ($ key ->isExpired ()) {
127
- throw new LockExpiredException (sprintf ('Failed to put off the expiration of the "%s" lock within the specified time. ' , $ key ));
128
- }
129
-
130
- return ;
131
127
} catch (DBALException $ e ) {
132
128
// the lock is already acquired. It could be us. Let's try to put off.
133
129
$ this ->putOffExpiration ($ key , $ this ->initialTtl );
@@ -136,13 +132,11 @@ public function save(Key $key)
136
132
$ this ->putOffExpiration ($ key , $ this ->initialTtl );
137
133
}
138
134
139
- if ($ key ->isExpired ()) {
140
- throw new LockExpiredException (sprintf ('Failed to store the "%s" lock. ' , $ key ));
141
- }
142
-
143
135
if ($ this ->gcProbability > 0 && (1.0 === $ this ->gcProbability || (random_int (0 , PHP_INT_MAX ) / PHP_INT_MAX ) <= $ this ->gcProbability )) {
144
136
$ this ->prune ();
145
137
}
138
+
139
+ $ this ->checkNotExpired ($ key );
146
140
}
147
141
148
142
/**
@@ -178,9 +172,7 @@ public function putOffExpiration(Key $key, $ttl)
178
172
throw new LockConflictedException ();
179
173
}
180
174
181
- if ($ key ->isExpired ()) {
182
- throw new LockExpiredException (sprintf ('Failed to put off the expiration of the "%s" lock within the specified time. ' , $ key ));
183
- }
175
+ $ this ->checkNotExpired ($ key );
184
176
}
185
177
186
178
/**
@@ -294,7 +286,7 @@ public function createTable(): void
294
286
}
295
287
296
288
/**
297
- * Cleanups the table by removing all expired locks.
289
+ * Cleans up the table by removing all expired locks.
298
290
*/
299
291
private function prune (): void
300
292
{
0 commit comments