Skip to content

Commit 3d063c9

Browse files
committed
OutputHelper: added rollback()
1 parent a82655d commit 3d063c9

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Caching/OutputHelper.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,14 @@ public function end(array $dependencies = []): void
4848
$this->cache->save($this->key, ob_get_flush(), $dependencies + $this->dependencies);
4949
$this->cache = null;
5050
}
51+
52+
53+
/**
54+
* Stops and throws away the output.
55+
*/
56+
public function rollback(): void
57+
{
58+
ob_end_flush();
59+
$this->cache = null;
60+
}
5161
}

tests/Storages/FileStorage.start.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,14 @@ Assert::same('Hello', $cache->load('key'));
3131
ob_start();
3232
Assert::null($cache->start('key'));
3333
Assert::same('Hello', ob_get_clean());
34+
35+
36+
37+
ob_start();
38+
$block = $cache->start('key2');
39+
Assert::type(Nette\Caching\OutputHelper::class, $block);
40+
echo 'Hello';
41+
$block->rollback();
42+
Assert::same('Hello', ob_get_clean());
43+
44+
Assert::same(null, $cache->load('key2'));

0 commit comments

Comments
 (0)