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