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