1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12:
13:
14: 15: 16: 17: 18: 19: 20:
21: class DibiNetteExtension extends Nette\Config\CompilerExtension
22: {
23:
24: public function loadConfiguration()
25: {
26: $container = $this->getContainerBuilder();
27: $config = $this->getConfig();
28:
29: $useProfiler = isset($config['profiler'])
30: ? $config['profiler']
31: : !$container->parameters['productionMode'];
32:
33: unset($config['profiler']);
34:
35: if (isset($config['flags'])) {
36: $flags = 0;
37: foreach ((array) $config['flags'] as $flag) {
38: $flags |= constant($flag);
39: }
40: $config['flags'] = $flags;
41: }
42:
43: $connection = $container->addDefinition($this->prefix('connection'))
44: ->setClass('DibiConnection', array($config));
45:
46: if ($useProfiler) {
47: $panel = $container->addDefinition($this->prefix('panel'))
48: ->setClass('DibiNettePanel')
49: ->addSetup('Nette\Diagnostics\Debugger::$bar->addPanel(?)', array('@self'))
50: ->addSetup('Nette\Diagnostics\Debugger::$blueScreen->addPanel(?)', array(array('@self', 'renderException')));
51:
52: $connection->addSetup('$service->onEvent[] = ?', array(array($panel, 'logEvent')));
53: }
54: }
55:
56: }
57: