1: <?php
2:
3: namespace PHPixie\Template;
4:
5: class Builder
6: {
7: protected $slice;
8: protected $filesystemLocator;
9: protected $configData;
10: protected $filesystemRoot;
11: protected $externalExtensions;
12: protected $externalFormats;
13:
14: protected $instances = array();
15:
16: public function __construct(
17: $slice,
18: $filesystemLocator,
19: $configData,
20: $filesystemRoot,
21: $externalExtensions,
22: $externalFormats
23: )
24: {
25: $this->slice = $slice;
26: $this->filesystemLocator = $filesystemLocator;
27: $this->configData = $configData;
28: $this->filesystemRoot = $filesystemRoot;
29: $this->externalExtensions = $externalExtensions;
30: $this->externalFormats = $externalFormats;
31: }
32:
33: public function extensions()
34: {
35: return $this->instance('extensions');
36: }
37:
38: public function formats()
39: {
40: return $this->instance('formats');
41: }
42:
43: public function compiler()
44: {
45: return $this->instance('compiler');
46: }
47:
48: public function renderer()
49: {
50: return $this->instance('renderer');
51: }
52:
53: public function resolver()
54: {
55: return $this->instance('resolver');
56: }
57:
58: public function container($name, $data = array())
59: {
60: $data = $this->slice->editableArrayData($data);
61: return new Container(
62: $this->renderer(),
63: $name,
64: $data
65: );
66: }
67:
68: protected function instance($name)
69: {
70: if(!array_key_exists($name, $this->instances)) {
71: $method = 'build'.ucfirst($name);
72: $this->instances[$name] = $this->$method();
73: }
74:
75: return $this->instances[$name];
76: }
77:
78: protected function buildExtensions()
79: {
80: return new Extensions(
81: $this->configData->slice('extensions'),
82: $this->externalExtensions
83: );
84: }
85:
86: protected function buildFormats()
87: {
88: return new Formats($this->externalFormats);
89: }
90:
91: protected function buildCompiler()
92: {
93: return new Compiler(
94: $this->filesystemRoot,
95: $this->formats(),
96: $this->configData->slice('compiler')
97: );
98: }
99:
100: protected function buildResolver()
101: {
102: return new Resolver(
103: $this->compiler(),
104: $this->filesystemLocator,
105: $this->configData->slice('resolver')
106: );
107: }
108:
109: protected function buildRenderer()
110: {
111: return new Renderer(
112: $this,
113: $this->slice
114: );
115: }
116:
117: }