1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (https://nette.org)
5: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
6: */
7:
8: namespace Nette\Caching;
9:
10: use Nette;
11:
12:
13: /**
14: * Output caching helper.
15: *
16: * @author David Grudl
17: */
18: class OutputHelper extends Nette\Object
19: {
20: /** @var array */
21: public $dependencies;
22:
23: /** @var Cache */
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: * @param array dependencies
41: * @return void
42: */
43: public function end(array $dependencies = NULL)
44: {
45: if ($this->cache === NULL) {
46: throw new Nette\InvalidStateException('Output cache has already been saved.');
47: }
48: $this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
49: $this->cache = NULL;
50: }
51:
52: }
53: