1: <?php
2:
3: /**
4: * This file is part of the Nette Framework (http://nette.org)
5: *
6: * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
7: *
8: * For the full copyright and license information, please view
9: * the file license.txt that was distributed with this source code.
10: */
11:
12: namespace Nette\Caching;
13:
14: use Nette;
15:
16:
17:
18: /**
19: * Output caching helper.
20: *
21: * @author David Grudl
22: */
23: class OutputHelper extends Nette\Object
24: {
25: /** @var array */
26: public $dependencies;
27:
28: /** @var Cache */
29: private $cache;
30:
31: /** @var string */
32: private $key;
33:
34:
35:
36: public function __construct(Cache $cache, $key)
37: {
38: $this->cache = $cache;
39: $this->key = $key;
40: ob_start();
41: }
42:
43:
44:
45: /**
46: * Stops and saves the cache.
47: * @param array dependencies
48: * @return void
49: */
50: public function end(array $dependencies = NULL)
51: {
52: if ($this->cache === NULL) {
53: throw new Nette\InvalidStateException('Output cache has already been saved.');
54: }
55: $this->cache->save($this->key, ob_get_flush(), (array) $dependencies + (array) $this->dependencies);
56: $this->cache = NULL;
57: }
58:
59: }
60: