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 extends Nette\Object
17: {
18: /** @var array */
19: public $dependencies;
20:
21: /** @var Cache */
22: private $cache;
23:
24: /** @var string */
25: private $key;
26:
27:
28: public function __construct(Cache $cache, $key)
29: {
30: $this->cache = $cache;
31: $this->key = $key;
32: ob_start();
33: }
34:
35:
36: /**
37: * Stops and saves the cache.
38: * @param array dependencies
39: * @return void
40: */
41: public function end(array $dependencies = NULL)
42: {
43: if ($this->cache === NULL) {
44: throw new Nette\InvalidStateException('Output cache has already been saved.');
45: }
46: $this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
47: $this->cache = NULL;
48: }
49:
50: }
51: