8000 Merge branch '3.2' · symfony/symfony@aa2a1eb · GitHub
[go: up one dir, main page]

Skip to content

Commit aa2a1eb

Browse files
Merge branch '3.2'
* 3.2: [Cache] Remove silenced warning tiggered by PhpArrayAdapter [Cache] Fix order of writes in ChainAdapter [Console] Fix return type in Terminal docblocks
2 parents f74d7fa + bfda99f commit aa2a1eb

File tree

3 files changed

+38
-36
lines changed

3 files changed

+38
-36
lines changed

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

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
class ChainAdapter implements AdapterInterface
2828
{
2929
private $adapters = array();
30+
private $adapterCount;
3031
private $saveUp;
3132

3233
/**
@@ -50,6 +51,7 @@ public function __construct(array $adapters, $maxLifetime = 0)
5051
$this->adapters[] = new ProxyAdapter($adapter);
5152
}
5253
}
54+
$this->adapterCount = count($this->adapters);
5355

5456
$this->saveUp = \Closure::bind(
5557
function ($adapter, $item) use ($maxLifetime) {
@@ -146,9 +148,10 @@ public function hasItem($key)
146148
public function clear()
147149
{
148150
$cleared = true;
151+
$i = $this->adapterCount;
149152

150-
foreach ($this->adapters as $adapter) {
151-
$cleared = $adapter->clear() && $cleared;
153+
while ($i--) {
154+
$cleared = $this->adapters[$i]->clear() && $cleared;
152155
}
153156

154157
return $cleared;
@@ -160,9 +163,10 @@ public function clear()
160163
public function deleteItem($key)
161164
{
162165
$deleted = true;
166+
$i = $this->adapterCount;
163167

164-
foreach ($this->adapters as $adapter) {
165-
$deleted = $adapter->deleteItem($key) && $deleted;
168+
while ($i--) {
169+
$deleted = $this->adapters[$i]->deleteItem($key) && $deleted;
166170
}
167171

168172
return $deleted;
@@ -174,9 +178,10 @@ public function deleteItem($key)
174178
public function deleteItems(array $keys)
175179
{
176180
$deleted = true;
181+
$i = $this->adapterCount;
177182

178-
foreach ($this->adapters as $adapter) {
179-
$deleted = $adapter->deleteItems($keys) && $deleted;
183+
while ($i--) {
184+
$deleted = $this->adapters[$i]->deleteItems($keys) && $deleted;
180185
}
181186

182187
return $deleted;
@@ -188,9 +193,10 @@ public function deleteItems(array $keys)
188193
public function save(CacheItemInterface $item)
189194
{
190195
$saved = true;
196+
$i = $this->adapterCount;
191197

192-
foreach ($this->adapters as $adapter) {
193-
$saved = $adapter->save($item) && $saved;
198+
while ($i--) {
199+
$saved = $this->adapters[$i]->save($item) && $saved;
194200
}
195201

196202
return $saved;
@@ -202,9 +208,10 @@ public function save(CacheItemInterface $item)
202208
public function saveDeferred(CacheItemInterface $item)
203209
{
204210
$saved = true;
211+
$i = $this->adapterCount;
205212

206-
foreach ($this->adapters as $adapter) {
207-
$saved = $adapter->saveDeferred($item) && $saved;
213+
while ($i--) {
214+
$saved = $this->adapters[$i]->saveDeferred($item) && $saved;
208215
}
209216

210217
return $saved;
@@ -216,9 +223,10 @@ public function saveDeferred(CacheItemInterface $item)
216223
public function commit()
217224
{
218225
$committed = true;
226+
$i = $this->adapterCount;
219227

220-
foreach ($this->adapters as $adapter) {
221-
$committed = $adapter->commit() && $committed;
228+
while ($i--) {
229+
$committed = $this->adapters[$i]->commit() && $committed;
222230
}
223231

224232
return $committed;

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,12 @@ public function warmUp(array $values)
163163
*/
164164
public function getItem($key)
165165
{
166-
if (null === $this->values) {
167-
$this->initialize();
168-
}
169-
170166
if (!is_string($key)) {
171167
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
172168
}
173-
169+
if (null === $this->values) {
170+
$this->initialize();
171+
}
174172
if (!isset($this->values[$key])) {
175173
return $this->fallbackPool->getItem($key);
176174
}
@@ -203,15 +201,14 @@ public function getItem($key)
203201
*/
204202
public function getItems(array $keys = array())
205203
{
206-
if (null === $this->values) {
207-
$this->initialize();
208-
}
209-
210204
foreach ($keys as $key) {
211205
if (!is_string($key)) {
212206
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
213207
}
214208
}
209+
if (null === $this->values) {
210+
$this->initialize();
211+
}
215212

216213
return $this->generateItems($keys);
217214
}
@@ -221,13 +218,12 @@ public function getItems(array $keys = array())
221218
*/
222219
public function hasItem($key)
223220
{
224-
if (null === $this->values) {
225-
$this->initialize();
226-
}
227-
228221
if (!is_string($key)) {
229222
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
230223
}
224+
if (null === $this->values) {
225+
$this->initialize();
226+
}
231227

232228
return isset($this->values[$key]) || $this->fallbackPool->hasItem($key);
233229
}
@@ -249,13 +245,12 @@ public function clear()
249245
*/
250246
public function deleteItem($key)
251247
{
252-
if (null === $this->values) {
253-
$this->initialize();
254-
}
255-
256248
if (!is_string($key)) {
257249
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given.', is_object($key) ? get_class($key) : gettype($key)));
258250
}
251+
if (null === $this->values) {
252+
$this->initialize();
253+
}
259254

260255
return !isset($this->values[$key]) && $this->fallbackPool->deleteItem($key);
261256
}
@@ -265,10 +260,6 @@ public function deleteItem($key)
265260
*/
266261
public function deleteItems(array $keys)
267262
{
268-
if (null === $this->values) {
269-
$this->initialize();
270-
}
271-
272263
$deleted = true;
273264
$fallbackKeys = array();
274265

@@ -283,6 +274,9 @@ public function deleteItems(array $keys)
283274
$fallbackKeys[] = $key;
284275
}
285276
}
277+
if (null === $this->values) {
278+
$this->initialize();
279+
}
286280

287281
if ($fallbackKeys) {
288282
$deleted = $this->fallbackPool->deleteItems($fallbackKeys) && $deleted;
@@ -328,7 +322,7 @@ public function commit()
328322
*/
329323
private function initialize()
330324
{
331-
$this->values = @(include $this->file) ?: array();
325+
$this->values = file_exists($this->file) ? (include $this->file ?: array()) : array();
332326
}
333327

334328
/**

src/Symfony/Component/Console/Terminal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Terminal
1919
/**
2020
* Gets the terminal width.
2121
*
22-
* @return int|null
22+
* @return int
2323
*/
2424
public function getWidth()
2525
{
@@ -37,7 +37,7 @@ public function getWidth()
3737
/**
3838
* Gets the terminal height.
3939
*
40-
* @return int|null
40+
* @return int
4141
*/
4242
public function getHeight()
4343
{

0 commit comments

Comments
 (0)
0