1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Config;
13:
14: use Nette,
15: Nette\DI\ContainerBuilder;
16:
17:
18:
19: 20: 21: 22: 23: 24: 25:
26: abstract class CompilerExtension extends Nette\Object
27: {
28:
29: protected $compiler;
30:
31:
32: protected $name;
33:
34:
35:
36: public function setCompiler(Compiler $compiler, $name)
37: {
38: $this->compiler = $compiler;
39: $this->name = $name;
40: return $this;
41: }
42:
43:
44:
45: 46: 47: 48: 49: 50:
51: public function getConfig(array $defaults = NULL, $expand = TRUE)
52: {
53: $config = $this->compiler->getConfig();
54: $config = isset($config[$this->name]) ? $config[$this->name] : array();
55: unset($config['services'], $config['factories']);
56: $config = Helpers::merge($config, $defaults);
57: return $expand ? $this->compiler->getContainerBuilder()->expand($config) : $config;
58: }
59:
60:
61:
62: 63: 64:
65: public function getContainerBuilder()
66: {
67: return $this->compiler->getContainerBuilder();
68: }
69:
70:
71:
72: 73: 74: 75: 76:
77: public function loadFromFile($file)
78: {
79: $loader = new Loader;
80: $res = $loader->load($file);
81: $container = $this->compiler->getContainerBuilder();
82: foreach ($loader->getDependencies() as $file) {
83: $container->addDependency($file);
84: }
85: return $res;
86: }
87:
88:
89:
90: 91: 92: 93: 94:
95: public function prefix($id)
96: {
97: return substr_replace($id, $this->name . '.', substr($id, 0, 1) === '@' ? 1 : 0, 0);
98: }
99:
100:
101:
102: 103: 104: 105:
106: public function loadConfiguration()
107: {
108: }
109:
110:
111:
112: 113: 114: 115:
116: public function beforeCompile()
117: {
118: }
119:
120:
121:
122: 123: 124: 125:
126: public function afterCompile(Nette\Utils\PhpGenerator\ClassType $class)
127: {
128: }
129:
130: }
131: