Skip to content

Commit ef19a03

Browse files
Merge branch '5.1'
* 5.1: [Cache] Use the default expiry when saving (not when creating) items Fix typo Fix DBAL deprecation [Form] Fix ChoiceType translation domain Add Tagalog translations for new form messages [Form] Add missing vietnamese translations sync translations from master [OptionsResolver] Fix force prepend normalizer add vietnamese translation for html5 color validation
2 parents 63f8827 + c87847c commit ef19a03

File tree

19 files changed

+436
-46
lines changed

19 files changed

+436
-46
lines changed

src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ public function deleteTokenBySeries(string $series)
7474
$sql = 'DELETE FROM rememberme_token WHERE series=:series';
7575
$paramValues = ['series' => $series];
7676
$paramTypes = ['series' => \PDO::PARAM_STR];
77-
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
77+
if (method_exists($this->conn, 'executeStatement')) {
78+
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
79+
} else {
80+
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
81+
}
7882
}
7983

8084
/**
@@ -94,7 +98,11 @@ public function updateToken(string $series, string $tokenValue, \DateTime $lastU
9498
'lastUsed' => Types::DATETIME_MUTABLE,
9599
'series' => \PDO::PARAM_STR,
96100
];
97-
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
101+
if (method_exists($this->conn, 'executeStatement')) {
102+
$updated = $this->conn->executeStatement($sql, $paramValues, $paramTypes);
103+
} else {
104+
$updated = $this->conn->executeUpdate($sql, $paramValues, $paramTypes);
105+
}
98106
if ($updated < 1) {
99107
throw new TokenNotFoundException('No token found.');
100108
}
@@ -122,6 +130,10 @@ public function createNewToken(PersistentTokenInterface $token)
122130
'value' => \PDO::PARAM_STR,
123131
'lastUsed' => Types::DATETIME_MUTABLE,
124132
];
125-
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
133+
if (method_exists($this->conn, 'executeStatement')) {
134+
$this->conn->executeStatement($sql, $paramValues, $paramTypes);
135+
} else {
136+
$this->conn->executeUpdate($sql, $paramValues, $paramTypes);
137+
}
126138
}
127139
}

src/Symfony/Bridge/Doctrine/Tests/Security/RememberMe/DoctrineTokenProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private function bootstrapProvider()
7272
'driver' => 'pdo_sqlite',
7373
'url' => 'sqlite:///:memory:',
7474
]);
75-
$connection->executeUpdate(<<< 'SQL'
75+
$connection->{method_exists($connection, 'executeStatement') ? 'executeStatement' : 'executeUpdate'}(<<< 'SQL'
7676
CREATE TABLE rememberme_token (
7777
series char(88) UNIQUE PRIMARY KEY NOT NULL,
7878
value char(88) NOT NULL,

src/Symfony/Component/Cache/Adapter/AbstractAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@ protected function __construct(string $namespace = '', int $defaultLifetime = 0)
4343
throw new InvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s").', $this->maxIdLength - 24, \strlen($namespace), $namespace));
4444
}
4545
$this->createCacheItem = \Closure::bind(
46-
static function ($key, $value, $isHit) use ($defaultLifetime) {
46+
static function ($key, $value, $isHit) {
4747
$item = new CacheItem();
4848
$item->key = $key;
4949
$item->value = $v = $value;
5050
$item->isHit = $isHit;
51-
$item->defaultLifetime = $defaultLifetime;
5251
// Detect wrapped values that encode for their expiry and creation duration
5352
// For compactness, these values are packed in the key of an array using
5453
// magic numbers in the form 9D-..-..-..-..-00-..-..-..-5F
@@ -66,15 +65,17 @@ static function ($key, $value, $isHit) use ($defaultLifetime) {
6665
);
6766
$getId = \Closure::fromCallable([$this, 'getId']);
6867
$this->mergeByLifetime = \Closure::bind(
69-
static function ($deferred, $namespace, &$expiredIds) use ($getId) {
68+
static function ($deferred, $namespace, &$expiredIds) use ($getId, $defaultLifetime) {
7069
$byLifetime = [];
7170
$now = microtime(true);
7271
$expiredIds = [];
7372

7473
foreach ($deferred as $key => $item) {
7574
$key = (string) $key;
7675
if (null === $item->expiry) {
77-
$ttl = 0 < $item->defaultLifetime ? $item->defaultLifetime : 0;
76+
$ttl = 0 < $defaultLifetime ? $defaultLifetime : 0;
77+
} elseif (0 === $item->expiry) {
78+
$ttl = 0;
7879
} elseif (0 >= $ttl = (int) (0.1 + $item->expiry - $now)) {
7980
$expiredIds[] = $getId($key);
8081
continue;

src/Symfony/Component/Cache/Adapter/AbstractTagAwareAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ protected function __construct(string $namespace = '', int $defaultLifetime = 0)
4444
throw new InvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s").', $this->maxIdLength - 24, \strlen($namespace), $namespace));
4545
}
4646
$this->createCacheItem = \Closure::bind(
47-
static function ($key, $value, $isHit) use ($defaultLifetime) {
47+
static function ($key, $value, $isHit) {
4848
$item = new CacheItem();
4949
$item->key = $key;
50-
$item->defaultLifetime = $defaultLifetime;
5150
$item->isTaggable = true;
5251
// If structure does not match what we expect return item as is (no value and not a hit)
5352
if (!\is_array($value) || !\array_key_exists('value', $value)) {
@@ -72,15 +71,17 @@ static function ($key, $value, $isHit) use ($defaultLifetime) {
7271
$getId = \Closure::fromCallable([$this, 'getId']);
7372
$tagPrefix = self::TAGS_PREFIX;
7473
$this->mergeByLifetime = \Closure::bind(
75-
static function ($deferred, &$expiredIds) use ($getId, $tagPrefix) {
74+
static function ($deferred, &$expiredIds) use ($getId, $tagPrefix, $defaultLifetime) {
7675
$byLifetime = [];
7776
$now = microtime(true);
7877
$expiredIds = [];
7978

8079
foreach ($deferred as $key => $item) {
8180
$key = (string) $key;
8281
if (null === $item->expiry) {
83-
$ttl = 0 < $item->defaultLifetime ? $item->defaultLifetime : 0;
82+
$ttl = 0 < $defaultLifetime ? $defaultLifetime : 0;
83+
} elseif (0 === $item->expiry) {
84+
$ttl = 0;
8485
} elseif (0 >= $ttl = (int) (0.1 + $item->expiry - $now)) {
8586
$expiredIds[] = $getId($key);
8687
continue;

src/Symfony/Component/Cache/Adapter/ArrayAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ArrayAdapter implements AdapterInterface, CacheInterface, LoggerAwareInter
3434
private $values = [];
3535
private $expiries = [];
3636
private $createCacheItem;
37+
private $defaultLifetime;
3738
private $maxLifetime;
3839
private $maxItems;
3940

@@ -50,16 +51,16 @@ public function __construct(int $defaultLifetime = 0, bool $storeSerialized = tr
5051
throw new InvalidArgumentException(sprintf('Argument $maxItems must be a positive integer, %d passed.', $maxItems));
5152
}
5253

54+
$this->defaultLifetime = $defaultLifetime;
5355
$this->storeSerialized = $storeSerialized;
5456
$this->maxLifetime = $maxLifetime;
5557
$this->maxItems = $maxItems;
5658
$this->createCacheItem = \Closure::bind(
57-
static function ($key, $value, $isHit) use ($defaultLifetime) {
59+
static function ($key, $value, $isHit) {
5860
$item = new CacheItem();
5961
$item->key = $key;
6062
$item->value = $value;
6163
$item->isHit = $isHit;
62-
$item->defaultLifetime = $defaultLifetime;
6364

6465
return $item;
6566
},
@@ -203,8 +204,8 @@ public function save(CacheItemInterface $item)
203204
if ($this->storeSerialized && null === $value = $this->freeze($value, $key)) {
204205
return false;
205206
}
206-
if (null === $expiry && 0 < $item["\0*\0defaultLifetime"]) {
207-
$expiry = $item["\0*\0defaultLifetime"];
207+
if (null === $expiry && 0 < $this->defaultLifetime) {
208+
$expiry = microtime(true) + $this->defaultLifetime;
208209
$expiry = $now + ($expiry > ($this->maxLifetime ?: $expiry) ? $this->maxLifetime : $expiry);
209210
} elseif ($this->maxLifetime && (null === $expiry || $expiry > $now + $this->maxLifetime)) {
210211
$expiry = $now + $this->maxLifetime;

src/Symfony/Component/Cache/Adapter/ChainAdapter.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,11 @@ static function ($sourceItem, $item, $sourceMetadata = null) use ($defaultLifeti
7070
unset($sourceMetadata[CacheItem::METADATA_TAGS]);
7171

7272
$item->value = $sourceItem->value;
73-
$item->expiry = $sourceMetadata[CacheItem::METADATA_EXPIRY] ?? $sourceItem->expiry;
7473
$item->isHit = $sourceItem->isHit;
7574
$item->metadata = $item->newMetadata = $sourceItem->metadata = $sourceMetadata;
7675

77-
if (0 < $sourceItem->defaultLifetime && $sourceItem->defaultLifetime < $defaultLifetime) {
78-
$defaultLifetime = $sourceItem->defaultLifetime;
79-
}
80-
if (0 < $defaultLifetime && ($item->defaultLifetime <= 0 || $defaultLifetime < $item->defaultLifetime)) {
81-
$item->defaultLifetime = $defaultLifetime;
76+
if (0 < $defaultLifetime) {
77+
$item->expiresAfter($defaultLifetime);
8278
}
8379

8480
return $item;

src/Symfony/Component/Cache/Adapter/PdoAdapter.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ public function createTable()
121121
$this->addTableToSchema($schema);
122122

123123
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
124-
$conn->exec($sql);
124+
if (method_exists($conn, 'executeStatement')) {
125+
$conn->executeStatement($sql);
126+
} else {
127+
$conn->exec($sql);
128+
}
125129
}
126130

127131
return;
@@ -152,7 +156,11 @@ public function createTable()
152156
throw new \DomainException(sprintf('Creating the cache table is currently not implemented for PDO driver "%s".', $this->driver));
153157
}
154158

155-
$conn->exec($sql);
159+
if (method_exists($conn, 'executeStatement')) {
160+
$conn->executeStatement($sql);
161+
} else {
162+
$conn->exec($sql);
163+
}
156164
}
157165

158166
/**
@@ -281,7 +289,11 @@ protected function doClear(string $namespace)
281289
}
282290

283291
try {
284-
$conn->exec($sql);
292+
if (method_exists($conn, 'executeStatement')) {
293+
$conn->executeStatement($sql);
294+
} else {
295+
$conn->exec($sql);
296+
}
285297
} catch (TableNotFoundException $e) {
286298
} catch (\PDOException $e) {
287299
}

src/Symfony/Component/Cache/Adapter/ProxyAdapter.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
3333
private $createCacheItem;
3434
private $setInnerItem;
3535
private $poolHash;
36+
private $defaultLifetime;
3637

3738
public function __construct(CacheItemPoolInterface $pool, string $namespace = '', int $defaultLifetime = 0)
3839
{
3940
$this->pool = $pool;
4041
$this->poolHash = $poolHash = spl_object_hash($pool);
4142
$this->namespace = '' === $namespace ? '' : CacheItem::validateKey($namespace);
4243
$this->namespaceLen = \strlen($namespace);
44+
$this->defaultLifetime = $defaultLifetime;
4345
$this->createCacheItem = \Closure::bind(
44-
static function ($key, $innerItem) use ($defaultLifetime, $poolHash) {
46+
static function ($key, $innerItem) use ($poolHash) {
4547
$item = new CacheItem();
4648
$item->key = $key;
4749

@@ -52,7 +54,6 @@ static function ($key, $innerItem) use ($defaultLifetime, $poolHash) {
5254
$item->value = $v = $innerItem->get();
5355
$item->isHit = $innerItem->isHit();
5456
$item->innerItem = $innerItem;
55-
$item->defaultLifetime = $defaultLifetime;
5657
$item->poolHash = $poolHash;
5758

5859
// Detect wrapped values that encode for their expiry and creation duration
@@ -223,8 +224,8 @@ private function doSave(CacheItemInterface $item, string $method)
223224
return false;
224225
}
225226
$item = (array) $item;
226-
if (null === $item["\0*\0expiry"] && 0 < $item["\0*\0defaultLifetime"]) {
227-
$item["\0*\0expiry"] = microtime(true) + $item["\0*\0defaultLifetime"];
227+
if (null === $item["\0*\0expiry"] && 0 < $this->defaultLifetime) {
228+
$item["\0*\0expiry"] = microtime(true) + $this->defaultLifetime;
228229
}
229230

230231
if ($item["\0*\0poolHash"] === $this->poolHash && $item["\0*\0innerItem"]) {

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static function ($key, $value, CacheItem $protoItem) {
4949
$item = new CacheItem();
5050
$item->key = $key;
5151
$item->value = $value;
52-
$item->defaultLifetime = $protoItem->defaultLifetime;
5352
$item->expiry = $protoItem->expiry;
5453
$item->poolHash = $protoItem->poolHash;
5554

@@ -94,8 +93,7 @@ static function ($deferred) {
9493
$this->invalidateTags = \Closure::bind(
9594
static function (AdapterInterface $tagsAdapter, array $tags) {
9695
foreach ($tags as $v) {
97-
$v->defaultLifetime = 0;
98-
$v->expiry = null;
96+
$v->expiry = 0;
9997
$tagsAdapter->saveDeferred($v);
10098
}
10199

src/Symfony/Component/Cache/CacheItem.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ final class CacheItem implements ItemInterface
2727
protected $value;
2828
protected $isHit = false;
2929
protected $expiry;
30-
protected $defaultLifetime;
3130
protected $metadata = [];
3231
protected $newMetadata = [];
3332
protected $innerItem;
@@ -78,7 +77,7 @@ public function set($value): self
7877
public function expiresAt($expiration): self
7978
{
8079
if (null === $expiration) {
81-
$this->expiry = $this->defaultLifetime > 0 ? microtime(true) + $this->defaultLifetime : null;
80+
$this->expiry = null;
8281
} elseif ($expiration instanceof \DateTimeInterface) {
8382
$this->expiry = (float) $expiration->format('U.u');
8483
} else {
@@ -96,7 +95,7 @@ public function expiresAt($expiration): self
9695
public function expiresAfter($time): self
9796
{
9897
if (null === $time) {
99-
$this->expiry = $this->defaultLifetime > 0 ? microtime(true) + $this->defaultLifetime : null;
98+
$this->expiry = null;
10099
} elseif ($time instanceof \DateInterval) {
101100
$this->expiry = microtime(true) + \DateTime::createFromFormat('U', 0)->add($time)->format('U.u');
102101
} elseif (\is_int($time)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy