1: <?php
2:
3: namespace Mockery\Generator;
4:
5: class CachingGenerator implements Generator
6: {
7: protected $generator;
8: protected $cache = array();
9:
10: public function __construct(Generator $generator)
11: {
12: $this->generator = $generator;
13: }
14:
15: public function generate(MockConfiguration $config)
16: {
17: $hash = $config->getHash();
18: if (isset($this->cache[$hash])) {
19: return $this->cache[$hash];
20: }
21:
22: $definition = $this->generator->generate($config);
23: $this->cache[$hash] = $definition;
24:
25: return $definition;
26: }
27: }
28: