1
|
|
|
<?php |
2
|
|
|
namespace Agavi\Database; |
3
|
|
|
|
4
|
|
|
// +---------------------------------------------------------------------------+ |
5
|
|
|
// | This file is part of the Agavi package. | |
6
|
|
|
// | Copyright (c) 2005-2011 the Agavi Project. | |
7
|
|
|
// | | |
8
|
|
|
// | For the full copyright and license information, please view the LICENSE | |
9
|
|
|
// | file that was distributed with this source code. You can also view the | |
10
|
|
|
// | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
11
|
|
|
// | vi: set noexpandtab: | |
12
|
|
|
// | Local Variables: | |
13
|
|
|
// | indent-tabs-mode: t | |
14
|
|
|
// | End: | |
15
|
|
|
// +---------------------------------------------------------------------------+ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* An abstract database adapter for the Doctrine2 DBAL and ORM. |
19
|
|
|
* |
20
|
|
|
* @package agavi |
21
|
|
|
* @subpackage database |
22
|
|
|
* |
23
|
|
|
* @author David Zülke <[email protected]> |
24
|
|
|
* @copyright Authors |
25
|
|
|
* @copyright The Agavi Project |
26
|
|
|
* |
27
|
|
|
* @since 1.0.6 |
28
|
|
|
* |
29
|
|
|
* @version $Id$ |
30
|
|
|
*/ |
31
|
|
|
abstract class Doctrine2Database extends Database |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Prepare the configuration for this connection. |
35
|
|
|
* |
36
|
|
|
* @param Doctrine\DBAL\Configuration The configuration object. |
37
|
|
|
* |
38
|
|
|
* @author David Zülke <[email protected]> |
39
|
|
|
* @since 1.0.6 |
40
|
|
|
*/ |
41
|
|
|
protected function prepareConfiguration(\Doctrine\DBAL\Configuration $config) |
42
|
|
|
{ |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Prepare the event manager for this connection. |
47
|
|
|
* |
48
|
|
|
* @param Doctrine\Common\EventManager The event manager object. |
49
|
|
|
* |
50
|
|
|
* @author David Zülke <[email protected]> |
51
|
|
|
* @since 1.0.6 |
52
|
|
|
*/ |
53
|
|
|
protected function prepareEventManager(\Doctrine\Common\EventManager $eventManager) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Initialize the Doctrine2 ORM. |
59
|
|
|
* |
60
|
|
|
* @param DatabaseManager $databaseManager The database manager of this instance. |
61
|
|
|
* @param array $parameters An assoc array of initialization params. |
62
|
|
|
* |
63
|
|
|
* @author David Zülke <[email protected]> |
64
|
|
|
* @since 1.0.6 |
65
|
|
|
*/ |
66
|
|
|
public function initialize(DatabaseManager $databaseManager, array $parameters = array()) |
67
|
|
|
{ |
68
|
|
|
parent::initialize($databaseManager, $parameters); |
69
|
|
|
|
70
|
|
|
if (!class_exists('Doctrine\Common\ClassLoader')) { |
71
|
|
|
// no soup for you! |
72
|
|
|
require('Doctrine/Common/ClassLoader.php'); // let's assume Doctrine2 is on ze include path... |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// iterate over all declared class loaders and register them if necessary (checks performed to avoid duplicates for Doctrine's own namespaces) |
76
|
|
|
// by default, we assume an install via PEAR, with all of Doctrine in one folder and on the include path |
77
|
|
|
// if people want to do the smart thing and ship a Doctrine release with their app, they just need to point the entire "Doctrine" namespace to the path |
78
|
|
|
// for bleeding edge git stuff or similar, the paths for the namespaces can be given individually, see the Doctrine manual for examples |
79
|
|
|
foreach ((array)$this->getParameter('class_loaders', array('Doctrine' => null)) as $namespace => $includePath) { |
80
|
|
|
if ($namespace == 'Doctrine' && class_exists('Doctrine\ORM\Version')) { |
81
|
|
|
// the ORM namespace's Version class exists or could be autloaded; let's assume that the class loader for any Doctrine stuff won't need registration then |
82
|
|
|
continue; |
83
|
|
|
} |
84
|
|
|
if (strpos($namespace, 'Doctrine\\') === 0 && class_exists($namespace . '\Version')) { |
85
|
|
|
// it is a Doctrine namespace, and the namespace's Version class exists or could be autloaded; let's assume that the class loader won't need registration then |
86
|
|
|
continue; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// register the class loader for this namespace without further checks (there's unlikely to be further duplicates) |
90
|
|
|
$cl = new \Doctrine\Common\ClassLoader($namespace, $includePath); |
91
|
|
|
$cl->register(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Execute the shutdown procedure. |
97
|
|
|
* |
98
|
|
|
* @author David Zülke <[email protected]> |
99
|
|
|
* @since 1.0.6 |
100
|
|
|
*/ |
101
|
|
|
public function shutdown() |
102
|
|
|
{ |
103
|
|
|
$this->connection = $this->resource = null; |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.