Source for file Manager.php
Documentation is available at Manager.php
* $Id: Manager.php 2290 2007-08-29 21:57:46Z zYne $
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
* Doctrine_Manager is the base component of all doctrine based projects.
* It opens and keeps track of all connections (database connections).
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @version $Revision: 2290 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @var array $connections an array containing all the opened connections
* @var array $bound an array containing all components that have a bound connection
* @var integer $index the incremented index
* @var integer $currIndex the current connection index
* @var string $root root directory
* @var array $_integrityActions an array containing all registered integrity actions
* used when emulating these actions
protected static $driverMap =
array('oci' =>
'oracle');
* this is private constructor (use getInstance to get an instance of this class)
public function addDeleteAction($componentName, $foreignComponent, $action)
public function addUpdateAction($componentName, $foreignComponent, $action)
* sets default attributes
Doctrine::ATTR_CACHE =>
null,
Doctrine::ATTR_LOAD_REFERENCES =>
true,
Doctrine::ATTR_LISTENER =>
new Doctrine_EventListener(),
Doctrine::ATTR_RECORD_LISTENER =>
new Doctrine_Record_Listener(),
Doctrine::ATTR_THROW_EXCEPTIONS =>
true,
Doctrine::ATTR_LOCKMODE =>
1,
Doctrine::ATTR_VLD =>
false,
Doctrine::ATTR_AUTO_LENGTH_VLD =>
true,
Doctrine::ATTR_AUTO_TYPE_VLD =>
true,
Doctrine::ATTR_QUERY_LIMIT =>
Doctrine::LIMIT_RECORDS,
Doctrine::ATTR_IDXNAME_FORMAT =>
"%s_idx",
Doctrine::ATTR_SEQNAME_FORMAT =>
"%s_seq",
Doctrine::ATTR_QUOTE_IDENTIFIER =>
false,
Doctrine::ATTR_SEQCOL_NAME =>
'id',
Doctrine::ATTR_PORTABILITY =>
Doctrine::PORTABILITY_ALL,
Doctrine::ATTR_EXPORT =>
Doctrine::EXPORT_ALL,
Doctrine::ATTR_DECIMAL_PLACES =>
2,
foreach ($attributes as $attribute =>
$value) {
* returns the root directory of Doctrine
* returns an instance of this class
* (this class uses the singleton pattern)
* @return Doctrine_Manager
if ( ! isset
($instance)) {
* if the adapter parameter is set this method acts as
* a short cut for Doctrine_Manager::getInstance()->openConnection($adapter, $name);
* if the adapter paramater is not set this method acts as
* a short cut for Doctrine_Manager::getInstance()->getCurrentConnection()
* @param PDO|Doctrine_Adapter_Interface$adapter database driver
* @param string $name name of the connection, if empty numeric key is used
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @return Doctrine_Connection
public static function connection($adapter =
null, $name =
null)
* opens a new connection and saves it to Doctrine_Manager->connections
* @param PDO|Doctrine_Adapter_Interface$adapter database driver
* @param string $name name of the connection, if empty numeric key is used
* @throws Doctrine_Manager_Exception if trying to bind a connection with an existing name
* @throws Doctrine_Manager_Exception if trying to open connection for unknown driver
* @return Doctrine_Connection
public function openConnection($adapter, $name =
null, $setCurrent =
true)
if ( ! isset
($adapter[0])) {
$parts['dsn'] =
$adapter[0];
$parts['scheme'] =
$e[0];
$parts['user'] =
(isset
($adapter[1])) ?
$adapter[1] :
null;
$parts['pass'] =
(isset
($adapter[2])) ?
$adapter[2] :
null;
$driverName =
$parts['scheme'];
// initialize the default attributes
$drivers =
array('mysql' =>
'Doctrine_Connection_Mysql',
'sqlite' =>
'Doctrine_Connection_Sqlite',
'pgsql' =>
'Doctrine_Connection_Pgsql',
'oci' =>
'Doctrine_Connection_Oracle',
'oci8' =>
'Doctrine_Connection_Oracle',
'oracle' =>
'Doctrine_Connection_Oracle',
'mssql' =>
'Doctrine_Connection_Mssql',
'dblib' =>
'Doctrine_Connection_Mssql',
'firebird' =>
'Doctrine_Connection_Firebird',
'informix' =>
'Doctrine_Connection_Informix',
'mock' =>
'Doctrine_Connection_Mock');
if ( ! isset
($drivers[$driverName])) {
$className =
$drivers[$driverName];
$conn =
new $className($this, $adapter);
* @return array Parsed contents of DSN
$names =
array('dsn', 'scheme', 'host', 'port', 'user', 'pass', 'path', 'query', 'fragment');
foreach ($names as $name) {
if ( ! isset
($parts[$name])) {
if (count($parts) ==
0 ||
! isset
($parts['scheme'])) {
switch ($parts['scheme']) {
if (isset
($parts['host']) &&
$parts['host'] ==
':memory') {
$parts['database'] =
':memory:';
$parts['dsn'] =
'sqlite::memory:';
$parts['database'] =
$parts['path'];
$parts['dsn'] =
$parts['scheme'] .
':' .
$parts['path'];
if ( ! isset
($parts['path']) ||
$parts['path'] ==
'/') {
if (isset
($parts['path'])) {
$parts['database'] =
substr($parts['path'], 1);
if ( ! isset
($parts['host'])) {
if (isset
(self::$driverMap[$parts['scheme']])) {
$parts['scheme'] =
self::$driverMap[$parts['scheme']];
$parts['dsn'] =
$parts['scheme'] .
':host='
.
$parts['host'] .
';dbname='
if (isset
($parts['port'])) {
// append port to dsn if supplied
$parts['dsn'] .=
';port=' .
$parts['port'];
throw
new Doctrine_Manager_Exception('Unknown driver '.
$parts['scheme']);
* @return object Doctrine_Connection
* @throws Doctrine_Manager_Exception if trying to get a non-existent connection
* retrieves the alias for given component name
* if the alias couldn't be found, this method returns the given
* @param string $componentName
* @return string the component alias
if (isset
($this->componentAliases[$componentName])) {
return $this->componentAliases[$componentName];
* sets an alias for given component name
* very useful when building a large framework with a possibility
* to override any given class
* @param string $componentName the name of the component
* @return Doctrine_Manager
$this->componentAliases[$componentName] =
$alias;
* @param Doctrine_Connection $conn connection object to be searched for
* @return string the name of the connection
* binds given component to given connection
* this means that when ever the given component uses a connection
* it will be using the bound connection instead of the current connection
* @param string $componentName
* @param string $connectionName
$this->_bound[$componentName] =
$connectionName;
* getConnectionForComponent
* @param string $componentName
* @return Doctrine_Connection
if (isset
($this->_bound[$componentName])) {
* this is the same as Doctrine_Connection::getTable() except
* that it works seamlessly in multi-server/connection environment
* @see Doctrine_Connection::getTable()
* @param string $componentName
public function getTable($componentName)
* this is the same as Doctrine_Connection::getTable() except
* that it works seamlessly in multi-server/connection environment
* @see Doctrine_Connection::getTable()
* @param string $componentName
public static function table($componentName)
* @param Doctrine_Connection $connection
* returns all opened connections
* sets the current connection to $key
* @param mixed $key the connection key
* @throws InvalidKeyException
throw
new InvalidKeyException();
* whether or not the manager contains specified connection
* @param mixed $key the connection key
* returns the number of opened connections
* returns an ArrayIterator that iterates through all connections
* returns the current connection
* @throws Doctrine_Connection_Exception if there are no open connections
* @return Doctrine_Connection
* returns a string representation of this object
$r[] =
"Doctrine_Manager";