Skip to content

Commit 8bec295

Browse files
committed
cs whitespace
1 parent 2ecfece commit 8bec295

File tree

8 files changed

+44
-0
lines changed

8 files changed

+44
-0
lines changed

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function loadConfiguration()
5151
if (extension_loaded('pdo_sqlite')) {
5252
$builder->addAlias('nette.cacheJournal', $this->prefix('journal'));
5353
}
54+
5455
$builder->addAlias('cacheStorage', $this->prefix('storage'));
5556
}
5657
}

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function nodeOpened(Latte\MacroNode $node)
5656
if ($node->modifiers) {
5757
throw new Latte\CompileException('Modifiers are not allowed in ' . $node->getNotation());
5858
}
59+
5960
$this->used = true;
6061
$node->empty = false;
6162
$node->openingCode = Latte\PhpWriter::using($node)
@@ -113,8 +114,10 @@ public static function createCache(
113114
if (array_key_exists('if', $args) && !$args['if']) {
114115
return $parents[] = new \stdClass;
115116
}
117+
116118
$key = array_merge([$key], array_intersect_key($args, range(0, count($args))));
117119
}
120+
118121
if ($parents) {
119122
end($parents)->dependencies[Cache::ITEMS][] = $key;
120123
}
@@ -123,6 +126,7 @@ public static function createCache(
123126
if ($helper = $cache->start($key)) {
124127
$parents[] = $helper;
125128
}
129+
126130
return $helper;
127131
}
128132

@@ -141,9 +145,11 @@ public static function endCache(array &$parents, array $args = null): void
141145
if (isset($args['dependencies'])) {
142146
$args += $args['dependencies']();
143147
}
148+
144149
if (isset($args['expire'])) {
145150
$args['expiration'] = $args['expire']; // back compatibility
146151
}
152+
147153
$helper->dependencies[Cache::TAGS] = $args['tags'] ?? null;
148154
$helper->dependencies[Cache::EXPIRATION] = $args['expiration'] ?? '+ 7 days';
149155
$helper->end();

src/Caching/Cache.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ public function load($key, callable $generator = null)
9595
$this->storage->remove($storageKey);
9696
throw $e;
9797
}
98+
9899
$this->save($key, $data, $dependencies);
99100
}
101+
100102
return $data;
101103
}
102104

@@ -109,6 +111,7 @@ public function bulkLoad(array $keys, callable $generator = null): array
109111
if (count($keys) === 0) {
110112
return [];
111113
}
114+
112115
foreach ($keys as $key) {
113116
if (!is_scalar($key)) {
114117
throw new Nette\InvalidArgumentException('Only scalar keys are allowed in bulkLoad()');
@@ -127,6 +130,7 @@ public function bulkLoad(array $keys, callable $generator = null): array
127130
: null
128131
);
129132
}
133+
130134
return $result;
131135
}
132136

@@ -144,6 +148,7 @@ public function bulkLoad(array $keys, callable $generator = null): array
144148
$result[$key] = null;
145149
}
146150
}
151+
147152
return $result;
148153
}
149154

@@ -187,6 +192,7 @@ public function save($key, $data, array $dependencies = null)
187192
} else {
188193
$this->storage->write($key, $data, $dependencies);
189194
}
195+
190196
return $data;
191197
}
192198
}
@@ -214,6 +220,7 @@ private function completeDependencies(?array $dp): array
214220
foreach (array_unique((array) $dp[self::FILES]) as $item) {
215221
$dp[self::CALLBACKS][] = [[self::class, 'checkFile'], $item, @filemtime($item) ?: null]; // @ - stat may fail
216222
}
223+
217224
unset($dp[self::FILES]);
218225
}
219226

@@ -227,12 +234,14 @@ private function completeDependencies(?array $dp): array
227234
foreach (array_unique((array) $dp[self::CONSTS]) as $item) {
228235
$dp[self::CALLBACKS][] = [[self::class, 'checkConst'], $item, constant($item)];
229236
}
237+
230238
unset($dp[self::CONSTS]);
231239
}
232240

233241
if (!is_array($dp)) {
234242
$dp = [];
235243
}
244+
236245
return $dp;
237246
}
238247

@@ -260,6 +269,7 @@ public function clean(array $conditions = null): void
260269
if (isset($conditions[self::TAGS])) {
261270
$conditions[self::TAGS] = array_values((array) $conditions[self::TAGS]);
262271
}
272+
263273
$this->storage->clean($conditions);
264274
}
265275

@@ -274,6 +284,7 @@ public function call(callable $function)
274284
if (is_array($function) && is_object($function[0])) {
275285
$key[0][0] = get_class($function[0]);
276286
}
287+
277288
return $this->load($key, function () use ($function, $key) {
278289
return $function(...array_slice($key, 1));
279290
});
@@ -290,6 +301,7 @@ public function wrap(callable $function, array $dependencies = null): \Closure
290301
if (is_array($function) && is_object($function[0])) {
291302
$key[0][0] = get_class($function[0]);
292303
}
304+
293305
return $this->load($key, function (&$deps) use ($function, $args, $dependencies) {
294306
$deps = $dependencies;
295307
return $function(...$args);
@@ -308,6 +320,7 @@ public function capture($key): ?OutputHelper
308320
if ($data === null) {
309321
return new OutputHelper($this, $key);
310322
}
323+
311324
echo $data;
312325
return null;
313326
}
@@ -344,6 +357,7 @@ public static function checkCallbacks(array $callbacks): bool
344357
return false;
345358
}
346359
}
360+
347361
return true;
348362
}
349363

src/Caching/OutputHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function end(array $dependencies = []): void
4545
if ($this->cache === null) {
4646
throw new Nette\InvalidStateException('Output cache has already been saved.');
4747
}
48+
4849
$this->cache->save($this->key, ob_get_flush(), $dependencies + $this->dependencies);
4950
$this->cache = null;
5051
}

src/Caching/Storages/FileStorage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private function verify(array $meta): bool
9898
if (filemtime($meta[self::FILE]) + $meta[self::META_DELTA] < time()) {
9999
break;
100100
}
101+
101102
touch($meta[self::FILE]);
102103

103104
} elseif (!empty($meta[self::META_EXPIRE]) && $meta[self::META_EXPIRE] < time()) {
@@ -131,6 +132,7 @@ public function lock(string $key): void
131132
if (!is_dir($dir = dirname($cacheFile))) {
132133
@mkdir($dir); // @ - directory may already exist
133134
}
135+
134136
$handle = fopen($cacheFile, 'c+b');
135137
if (!$handle) {
136138
return;
@@ -174,6 +176,7 @@ public function write(string $key, $data, array $dp): void
174176
return;
175177
}
176178
}
179+
177180
$handle = $this->locks[$key];
178181
unset($this->locks[$key]);
179182

@@ -183,6 +186,7 @@ public function write(string $key, $data, array $dp): void
183186
if (!$this->journal) {
184187
throw new Nette\InvalidStateException('CacheJournal has not been provided.');
185188
}
189+
186190
$this->journal->write($cacheFile, $dp);
187191
}
188192

@@ -242,6 +246,7 @@ public function clean(array $conditions): void
242246
@rmdir($path); // @ - removing dirs is not necessary
243247
continue;
244248
}
249+
245250
if ($all) {
246251
$this->delete($path);
247252

@@ -266,6 +271,7 @@ public function clean(array $conditions): void
266271
if ($this->journal) {
267272
$this->journal->clean($conditions);
268273
}
274+
269275
return;
270276

271277
} elseif ($namespaces) {
@@ -278,6 +284,7 @@ public function clean(array $conditions): void
278284
foreach (Nette\Utils\Finder::findFiles('_*')->in($dir) as $entry) {
279285
$this->delete((string) $entry);
280286
}
287+
281288
@rmdir($dir); // may already contain new files
282289
}
283290
}
@@ -341,6 +348,7 @@ protected function getCacheFile(string $key): string
341348
if ($a = strrpos($file, '%00')) { // %00 = urlencode(Nette\Caching\Cache::NAMESPACE_SEPARATOR)
342349
$file = substr_replace($file, '/_', $a, 3);
343350
}
351+
344352
return $this->dir . '/_' . $file;
345353
}
346354

@@ -356,12 +364,14 @@ private static function delete(string $file, $handle = null): void
356364
flock($handle, LOCK_UN);
357365
fclose($handle);
358366
}
367+
359368
return;
360369
}
361370

362371
if (!$handle) {
363372
$handle = @fopen($file, 'r+'); // @ - file may not exist
364373
}
374+
365375
if (!$handle) {
366376
return;
367377
}

src/Caching/Storages/MemcachedStorage.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function bulkRead(array $keys): array
128128
$this->memcached->replace($prefixedKey, $meta, $meta[self::META_DELTA] + time());
129129
}
130130
}
131+
131132
if (!empty($deleteKeys)) {
132133
$this->memcached->deleteMulti($deleteKeys, 0);
133134
}
@@ -168,6 +169,7 @@ public function write(string $key, $data, array $dp): void
168169
if (!$this->journal) {
169170
throw new Nette\InvalidStateException('CacheJournal has not been provided.');
170171
}
172+
171173
$this->journal->write($key, $dp);
172174
}
173175

src/Caching/Storages/SQLiteJournal.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function __construct(string $path)
3232
if (!extension_loaded('pdo_sqlite')) {
3333
throw new Nette\NotSupportedException('SQLiteJournal requires PHP extension pdo_sqlite which is not loaded.');
3434
}
35+
3536
$this->path = $path;
3637
}
3738

@@ -68,6 +69,7 @@ public function write(string $key, array $dependencies): void
6869
if (!$this->pdo) {
6970
$this->open();
7071
}
72+
7173
$this->pdo->exec('BEGIN');
7274

7375
if (!empty($dependencies[Cache::TAGS])) {
@@ -77,6 +79,7 @@ public function write(string $key, array $dependencies): void
7779
$arr[] = $key;
7880
$arr[] = $tag;
7981
}
82+
8083
$this->pdo->prepare('INSERT INTO tags (key, tag) SELECT ?, ?' . str_repeat('UNION SELECT ?, ?', count($arr) / 2 - 1))
8184
->execute($arr);
8285
}
@@ -95,6 +98,7 @@ public function clean(array $conditions): ?array
9598
if (!$this->pdo) {
9699
$this->open();
97100
}
101+
98102
if (!empty($conditions[Cache::ALL])) {
99103
$this->pdo->exec('
100104
BEGIN;

src/Caching/Storages/SQLiteStorage.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function read(string $key)
6363
if ($row['slide'] !== null) {
6464
$this->pdo->prepare('UPDATE cache SET expire = ? + slide WHERE key=?')->execute([time(), $key]);
6565
}
66+
6667
return unserialize($row['data']);
6768
}
6869

@@ -77,12 +78,15 @@ public function bulkRead(array $keys): array
7778
if ($row['slide'] !== null) {
7879
$updateSlide[] = $row['key'];
7980
}
81+
8082
$result[$row['key']] = unserialize($row['data']);
8183
}
84+
8285
if (!empty($updateSlide)) {
8386
$stmt = $this->pdo->prepare('UPDATE cache SET expire = ? + slide WHERE key IN(?' . str_repeat(',?', count($updateSlide) - 1) . ')');
8487
$stmt->execute(array_merge([time()], $updateSlide));
8588
}
89+
8690
return $result;
8791
}
8892

@@ -110,9 +114,11 @@ public function write(string $key, $data, array $dependencies): void
110114
$arr[] = $key;
111115
$arr[] = $tag;
112116
}
117+
113118
$this->pdo->prepare('INSERT INTO tags (key, tag) SELECT ?, ?' . str_repeat('UNION SELECT ?, ?', count($arr) / 2 - 1))
114119
->execute($arr);
115120
}
121+
116122
$this->pdo->exec('COMMIT');
117123
}
118124

0 commit comments

Comments
 (0)