1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6: */
7:
8: namespace Nette\Caching;
9:
10: use Nette;
11:
12:
13: /**
14: * Output caching helper.
15: */
16: class OutputHelper
17: {
18: use Nette\SmartObject;
19:
20: /** @var array */
21: public $dependencies;
22:
23: /** @var Cache|null */
24: private $cache;
25:
26: /** @var string */
27: private $key;
28:
29:
30: public function __construct(Cache $cache, $key)
31: {
32: $this->cache = $cache;
33: $this->key = $key;
34: ob_start();
35: }
36:
37:
38: /**
39: * Stops and saves the cache.
40: * @return void
41: */
42: public function end(array $dependencies = null)
43: {
44: if ($this->cache === null) {
45: throw new Nette\InvalidStateException('Output cache has already been saved.');
46: }
47: $this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
48: $this->cache = null;
49: }
50: }
51: