mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 14:16:39 +02:00
added extension for Nette Framework 2.1 (and examples) [Closes #93]
This commit is contained in:
56
dibi/bridges/Nette/DibiNette21Extension.php
Normal file
56
dibi/bridges/Nette/DibiNette21Extension.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the "dibi" - smart database abstraction layer.
|
||||
*
|
||||
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the file license.txt that was distributed with this source code.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Dibi extension for Nette Framework 2.1. Creates 'connection' service.
|
||||
*
|
||||
* @author David Grudl
|
||||
* @package dibi\nette
|
||||
* @phpversion 5.3
|
||||
*/
|
||||
class DibiNette21Extension extends Nette\DI\CompilerExtension
|
||||
{
|
||||
|
||||
public function loadConfiguration()
|
||||
{
|
||||
$container = $this->getContainerBuilder();
|
||||
$config = $this->getConfig();
|
||||
|
||||
$useProfiler = isset($config['profiler'])
|
||||
? $config['profiler']
|
||||
: !$container->parameters['productionMode'];
|
||||
|
||||
unset($config['profiler']);
|
||||
|
||||
if (isset($config['flags'])) {
|
||||
$flags = 0;
|
||||
foreach ((array) $config['flags'] as $flag) {
|
||||
$flags |= constant($flag);
|
||||
}
|
||||
$config['flags'] = $flags;
|
||||
}
|
||||
|
||||
$connection = $container->addDefinition($this->prefix('connection'))
|
||||
->setClass('DibiConnection', array($config));
|
||||
|
||||
if ($useProfiler) {
|
||||
$panel = $container->addDefinition($this->prefix('panel'))
|
||||
->setClass('DibiNettePanel')
|
||||
->addSetup('Nette\Diagnostics\Debugger::getBar()->addPanel(?)', array('@self'))
|
||||
->addSetup('Nette\Diagnostics\Debugger::getBlueScreen()->addPanel(?)', array(array('@self', 'renderException')));
|
||||
|
||||
$connection->addSetup('$service->onEvent[] = ?', array(array($panel, 'logEvent')));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
17
dibi/bridges/Nette/examples/config.nette-2.0.neon
Normal file
17
dibi/bridges/Nette/examples/config.nette-2.0.neon
Normal file
@@ -0,0 +1,17 @@
|
||||
# Requires Nette Framework 2.0 for PHP 5.3
|
||||
#
|
||||
# In bootstrap.php append these lines after line $configurator = new Nette\Config\Configurator;
|
||||
#
|
||||
# $configurator->onCompile[] = function($configurator, $compiler) {
|
||||
# $compiler->addExtension('dibi', new DibiNette20Extension);
|
||||
# };
|
||||
#
|
||||
# This will create service named 'dibi.connection'.
|
||||
|
||||
common:
|
||||
dibi:
|
||||
host: localhost
|
||||
username: root
|
||||
password: ***
|
||||
database: foo
|
||||
lazy: TRUE
|
12
dibi/bridges/Nette/examples/config.nette-2.1.neon
Normal file
12
dibi/bridges/Nette/examples/config.nette-2.1.neon
Normal file
@@ -0,0 +1,12 @@
|
||||
# This will create service named 'dibi.connection'.
|
||||
# Requires Nette Framework 2.1
|
||||
|
||||
extensions:
|
||||
dibi: DibiNette21Extension
|
||||
|
||||
dibi:
|
||||
host: localhost
|
||||
username: root
|
||||
password: ***
|
||||
database: foo
|
||||
lazy: TRUE
|
Reference in New Issue
Block a user