class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate (View source)

Doctrine_Manager is the base component of all doctrine based projects.

It opens and keeps track of all connections (database connections).

Properties

protected Doctrine_Locator $_locator from Doctrine_Locator_Injectable
protected array $_resources from Doctrine_Locator_Injectable
static protected Doctrine_Null $_null from Doctrine_Locator_Injectable
protected array $attributes from Doctrine_Configurable
protected Doctrine_Configurable $parent from Doctrine_Configurable
protected array $_impl from Doctrine_Configurable
protected array $_params from Doctrine_Configurable
protected array $_connections
protected array $_bound
protected integer $_index
protected integer $_currIndex
protected Doctrine_Query_Registry $_queryRegistry
protected array $_validators
protected array $_hydrators
protected $_connectionDrivers
protected $_extensions
protected boolean $_loadedValidatorsFromDisk
static protected $_instance

Methods

setLocator(Doctrine_Locator $locator)

setLocator this method can be used for setting the locator object locally

getLocator()

getLocator returns the locator associated with this object

mixed
locate(string $name)

locate locates a resource by given name and returns it

bind($name, $resource)

bind binds a resource to a name

static void
initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

static Doctrine_Null
getNullObject()

getNullObject returns the null object associated with this object

void
setAttribute(mixed $attribute, mixed $value)

setAttribute sets a given attribute

getParams($namespace = null)

No description

getParamNamespaces()

No description

setParam($name, $value, $namespace = null)

No description

getParam($name, $namespace = null)

No description

setImpl(string $template, string $class)

setImpl binds given class to given template name

string
getImpl($template)

getImpl returns the implementation for given class

hasImpl($template)

No description

void
setEventListener(Doctrine_EventListener $listener)

No description

addRecordListener($listener, $name = null)

addRecordListener

addListener($listener, $name = null)

addListener

mixed
getAttribute(integer $attribute)

returns the value of an attribute

void
unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

array
getAttributes()

getAttributes returns all attributes as an array

setCharset(string $charset)

Set the charset

mixed
getCharset()

Get the charset

setCollate(string $collate)

Set the collate

mixed
getCollate()

Get the collate

void
setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

getParent()

getParent returns the parent of this component

boolean
setDefaultAttributes()

Sets default attributes values.

getInstance()

Returns an instance of this class (this class uses the singleton pattern)

static void
resetInstance()

Reset the internal static instance

void
reset()

Reset this instance of the manager

getQueryRegistry()

Lazy-initializes the query registry object and returns it

setQueryRegistry(Doctrine_Query_Registry $registry)

Sets the query registry

connection(PDO|Doctrine_Adapter_Interface $adapter = null, string $name = null)

Open a new connection. If the adapter parameter is set this method acts as a short cut for Doctrine_Manager::getInstance()->openConnection($adapter, $name);

openConnection($adapter, $name = null, $setCurrent = true)

Opens a new connection and saves it to Doctrine_Manager->connections

array
parsePdoDsn(array $dsn)

Parse a pdo style dsn in to an array of parts

array
_buildDsnPartsArray(string $dsn)

Build the blank dsn parts array used with parseDsn()

array
parseDsn(string $dsn)

Parse a Doctrine style dsn string in to an array of parts

getConnection(string $name)

Get the connection instance for the passed name

string
getConnectionName(Doctrine_Connection $conn)

Get the name of the passed connection instance

boolean
bindComponent(string $componentName, string $connectionName)

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

getConnectionForComponent(string $componentName)

Get the connection instance for the specified component

boolean
hasConnectionForComponent(string $componentName = null)

Check if a component is bound to a connection

void
closeConnection(Doctrine_Connection $connection)

Closes the specified connection

array
getConnections()

Returns all opened connections

void
setCurrentConnection(mixed $key)

Sets the current connection to $key

boolean
contains(mixed $key)

Whether or not the manager contains specified connection

integer
count()

Returns the number of opened connections

getIterator()

Returns an ArrayIterator that iterates through all connections

getCurrentConnection()

Get the current connection instance

void
createDatabases(string $specifiedConnections = array())

Creates databases for all existing connections

void
dropDatabases(string $specifiedConnections = array())

Drops databases for all existing connections

string
__toString()

Returns a string representation of this object

array
getValidators()

Get available doctrine validators

void
registerValidators(mixed $validators)

Register validators so that Doctrine is aware of them

void
registerHydrator($name, $class)

Register a new driver for hydration

array
getHydrators()

Get all registered hydrators

void
registerConnectionDriver($name, $class)

Register a custom connection driver

array
getConnectionDrivers()

Get all the available connection drivers

void
registerExtension(string $name, string $path = null)

Register a Doctrine extension for extensionsAutoload() method

$extensions
getExtensions()

Get all registered Doctrine extensions

Details

Doctrine_Locator_Injectable setLocator(Doctrine_Locator $locator)

setLocator this method can be used for setting the locator object locally

Parameters

Doctrine_Locator $locator the locator object

Return Value

Doctrine_Locator_Injectable this instance

Doctrine_Locator getLocator()

getLocator returns the locator associated with this object

if there are no locator locally associated then this method tries to fetch the current global locator

Return Value

Doctrine_Locator

mixed locate(string $name)

locate locates a resource by given name and returns it

if the resource cannot be found locally this method tries to use the global locator for finding the resource

Parameters

string $name the name of the resource

Return Value

mixed the located resource

Exceptions

Doctrine_Locator_Exception if the resource could not be found

See also

Doctrine_Locator::locate

Doctrine_Locator bind($name, $resource)

bind binds a resource to a name

Parameters

$name
$resource

Return Value

Doctrine_Locator this object

static void initNullObject(Doctrine_Null $null)

initNullObject initializes the null object

Parameters

Doctrine_Null $null

Return Value

void

static Doctrine_Null getNullObject()

getNullObject returns the null object associated with this object

Return Value

Doctrine_Null

void setAttribute(mixed $attribute, mixed $value)

setAttribute sets a given attribute

$manager->setAttribute(Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_ALL);

Parameters

mixed $attribute either a Doctrine_Core::ATTR_* integer constant or a string corresponding to a constant
mixed $value the value of the attribute

Return Value

void

Exceptions

Doctrine_Exception if the value is invalid

See also

Doctrine_Core::ATTR_* constants

getParams($namespace = null)

Parameters

$namespace

getParamNamespaces()

setParam($name, $value, $namespace = null)

Parameters

$name
$value
$namespace

getParam($name, $namespace = null)

Parameters

$name
$namespace

Doctrine_Configurable setImpl(string $template, string $class)

setImpl binds given class to given template name

this method is the base of Doctrine dependency injection

Parameters

string $template name of the class template
string $class name of the class to be bound

Return Value

Doctrine_Configurable this object

string getImpl($template)

getImpl returns the implementation for given class

Parameters

$template

Return Value

string name of the concrete implementation

hasImpl($template)

Parameters

$template

void setEventListener(Doctrine_EventListener $listener)

Parameters

Doctrine_EventListener $listener

Return Value

void

Doctrine_Configurable addRecordListener($listener, $name = null)

addRecordListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

Doctrine_Configurable addListener($listener, $name = null)

addListener

Parameters

$listener
$name

Return Value

Doctrine_Configurable this object

mixed getAttribute(integer $attribute)

returns the value of an attribute

Parameters

integer $attribute

Return Value

mixed

void unsetAttribute(integer $attribute)

Unset an attribute from this levels attributes

Parameters

integer $attribute

Return Value

void

array getAttributes()

getAttributes returns all attributes as an array

Return Value

array

setCharset(string $charset)

Set the charset

Parameters

string $charset

mixed getCharset()

Get the charset

Return Value

mixed

setCollate(string $collate)

Set the collate

Parameters

string $collate

mixed getCollate()

Get the collate

Return Value

mixed $collate

void setParent(Doctrine_Configurable $component)

sets a parent for this configurable component the parent must be configurable component itself

Parameters

Doctrine_Configurable $component

Return Value

void

Doctrine_Configurable getParent()

getParent returns the parent of this component

Return Value

Doctrine_Configurable

boolean setDefaultAttributes()

Sets default attributes values.

This method sets default values for all null attributes of this instance. It is idempotent and can only be called one time. Subsequent calls does not alter the attribute values.

Return Value

boolean true if inizialization was executed

static Doctrine_Manager getInstance()

Returns an instance of this class (this class uses the singleton pattern)

Return Value

Doctrine_Manager

static void resetInstance()

Reset the internal static instance

Return Value

void

void reset()

Reset this instance of the manager

Return Value

void

Doctrine_Query_Registry getQueryRegistry()

Lazy-initializes the query registry object and returns it

Doctrine_Manager setQueryRegistry(Doctrine_Query_Registry $registry)

Sets the query registry

Parameters

Doctrine_Query_Registry $registry

Return Value

Doctrine_Manager this object

static Doctrine_Connection connection(PDO|Doctrine_Adapter_Interface $adapter = null, string $name = null)

Open a new connection. 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()

Parameters

PDO|Doctrine_Adapter_Interface $adapter database driver
string $name name of the connection, if empty numeric key is used

Return Value

Doctrine_Connection

Exceptions

Doctrine_Manager_Exception if trying to bind a connection with an existing name

Doctrine_Connection openConnection($adapter, $name = null, $setCurrent = true)

Opens a new connection and saves it to Doctrine_Manager->connections

Parameters

$adapter
$name
$setCurrent

Return Value

Doctrine_Connection

Exceptions

Doctrine_Manager_Exception if trying to bind a connection with an existing name
Doctrine_Manager_Exception if trying to open connection for unknown driver

array parsePdoDsn(array $dsn)

Parse a pdo style dsn in to an array of parts

Parameters

array $dsn An array of dsn information

Return Value

array The array parsed

protected array _buildDsnPartsArray(string $dsn)

Build the blank dsn parts array used with parseDsn()

Parameters

string $dsn

Return Value

array $parts

See also

parseDsn()

array parseDsn(string $dsn)

Parse a Doctrine style dsn string in to an array of parts

Parameters

string $dsn

Return Value

array Parsed contents of DSN

Doctrine_Connection getConnection(string $name)

Get the connection instance for the passed name

Parameters

string $name name of the connection, if empty numeric key is used

Return Value

Doctrine_Connection

Exceptions

Doctrine_Manager_Exception if trying to get a non-existent connection

string getConnectionName(Doctrine_Connection $conn)

Get the name of the passed connection instance

Parameters

Doctrine_Connection $conn connection object to be searched for

Return Value

string the name of the connection

boolean bindComponent(string $componentName, string $connectionName)

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

Parameters

string $componentName
string $connectionName

Return Value

boolean

Doctrine_Connection getConnectionForComponent(string $componentName)

Get the connection instance for the specified component

Parameters

string $componentName

Return Value

Doctrine_Connection

boolean hasConnectionForComponent(string $componentName = null)

Check if a component is bound to a connection

Parameters

string $componentName

Return Value

boolean

void closeConnection(Doctrine_Connection $connection)

Closes the specified connection

Parameters

Doctrine_Connection $connection

Return Value

void

array getConnections()

Returns all opened connections

Return Value

array

void setCurrentConnection(mixed $key)

Sets the current connection to $key

Parameters

mixed $key the connection key

Return Value

void

Exceptions

InvalidKeyException

boolean contains(mixed $key)

Whether or not the manager contains specified connection

Parameters

mixed $key the connection key

Return Value

boolean

integer count()

Returns the number of opened connections

Return Value

integer

ArrayIterator getIterator()

Returns an ArrayIterator that iterates through all connections

Return Value

ArrayIterator

Doctrine_Connection getCurrentConnection()

Get the current connection instance

Return Value

Doctrine_Connection

Exceptions

Doctrine_Connection_Exception if there are no open connections

void createDatabases(string $specifiedConnections = array())

Creates databases for all existing connections

Parameters

string $specifiedConnections Array of connections you wish to create the database for

Return Value

void

void dropDatabases(string $specifiedConnections = array())

Drops databases for all existing connections

Parameters

string $specifiedConnections Array of connections you wish to drop the database for

Return Value

void

string __toString()

Returns a string representation of this object

Return Value

string

array getValidators()

Get available doctrine validators

Return Value

array $validators

void registerValidators(mixed $validators)

Register validators so that Doctrine is aware of them

Parameters

mixed $validators Name of validator or array of validators

Return Value

void

void registerHydrator($name, $class)

Register a new driver for hydration

Parameters

$name
$class

Return Value

void

array getHydrators()

Get all registered hydrators

Return Value

array $hydrators

void registerConnectionDriver($name, $class)

Register a custom connection driver

Parameters

$name
$class

Return Value

void

array getConnectionDrivers()

Get all the available connection drivers

Return Value

array $connectionDrivers

void registerExtension(string $name, string $path = null)

Register a Doctrine extension for extensionsAutoload() method

Parameters

string $name
string $path

Return Value

void

$extensions getExtensions()

Get all registered Doctrine extensions

Return Value

$extensions