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