Commit ad244305 authored by romanb's avatar romanb

Refactorings and initial commit/draft of new event handling / configuration /...

Refactorings and initial commit/draft of new event handling / configuration / bootstrapping. Still need to remove all the static EntityManagerFactory::getManager lookup calls from the Production classes. The production classes need to have access to the EntityManager of the Query that constructed the Parser. It should be injected into the Parser during construction.
parent d8d761b5
......@@ -30,6 +30,8 @@
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision$
* @todo Remove all the constants, attributes to the new attribute system,
* All methods to separate classes.
*/
final class Doctrine
{
......@@ -183,7 +185,6 @@ final class Doctrine
const ATTR_EXPORT = 140; // manager/session attribute
const ATTR_DECIMAL_PLACES = 141; // manager/session attribute
const ATTR_PORTABILITY = 106; // manager/session attribute
const ATTR_VALIDATE = 107; // manager/session attribute
const ATTR_COLL_KEY = 108; // class attribute
const ATTR_QUERY_LIMIT = 109; // manager/session attribute
const ATTR_DEFAULT_TABLE_TYPE = 112; // manager/session attribute
......@@ -197,9 +198,7 @@ final class Doctrine
const ATTR_NAME_PREFIX = 121; // ??
const ATTR_CREATE_TABLES = 122; // manager/session attribute
const ATTR_COLL_LIMIT = 123; // manager/session attribute
const ATTR_CACHE = 150; // deprecated
const ATTR_RESULT_CACHE = 150; // manager/session attribute
const ATTR_CACHE_LIFESPAN = 151; // deprecated
const ATTR_RESULT_CACHE_LIFESPAN = 151; // manager/session attribute
const ATTR_LOAD_REFERENCES = 153; // class attribute
const ATTR_RECORD_LISTENER = 154;
......
......@@ -19,6 +19,8 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::Behaviors::AuditLog;
/**
* Doctrine_AuditLog
*
......@@ -29,6 +31,7 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo Move to "Doctrine Behaviors" package. Separate download.
*/
class Doctrine_AuditLog extends Doctrine_Record_Generator
{
......
......@@ -110,7 +110,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
{
if (is_string($entityBaseType)) {
$this->_entityBaseType = $entityBaseType;
$mapper = Doctrine_EntityManager::getManager($entityBaseType)->getEntityPersister($entityBaseType);
$mapper = Doctrine_EntityManagerFactory::getManager($entityBaseType)
->getEntityPersister($entityBaseType);
}
$this->_mapper = $mapper;
......@@ -210,7 +211,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
public function unserialize($serialized)
{
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$connection = $manager->getConnection();
$array = unserialize($serialized);
......
......@@ -19,6 +19,8 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::ORM::Tools;
/**
* Doctrine_Compiler
* This class can be used for compiling the entire Doctrine framework into a single file
......
<?php
#namespace Doctrine::Common;
#use Doctrine::Common::NullObject;
/**
* The Configuration is the container for all configuration options of Doctrine.
* It combines all configuration options from DBAL & ORM to make it easy for the
* user.
*
* @since 2.0
*/
class Doctrine_Configuration
{
private $_nullObject;
/**
* The attributes that are contained in the configuration.
*
* @var array
*/
private $_attributes = array(
'quoteIdentifier' => false,
'indexNameFormat' => '%s_idx',
'sequenceNameFormat' => '%s_seq',
'tableNameFormat' => '%s',
'resultCache' => null,
'resultCacheLifeSpan' => null,
'queryCache' => null,
'queryCacheLifeSpan' => null,
'metadataCache' => null,
'metadataCacheLifeSpan' => null
);
public function __construct()
{
$this->_nullObject = Doctrine_Null::$INSTANCE;
$this->_initAttributes();
}
private function _initAttributes()
{
// Change null default values to references to the Null object to allow
// fast isset() checks instead of array_key_exists().
foreach ($this->_attributes as $key => $value) {
if ($value === null) {
$this->_attributes[$key] = $this->_nullObject;
}
}
}
public function get($name)
{
if ( ! $this->hasAttribute($name)) {
throw Doctrine_Configuration_Exception::unknownAttribute($name);
}
if ($this->_attributes[$name] === $this->_nullObject) {
return null;
}
return $this->_attributes[$name];
}
public function set($name, $value)
{
if ( ! $this->hasAttribute($name)) {
throw Doctrine_Configuration_Exception::unknownAttribute($name);
}
// TODO: do some value checking depending on the attribute
$this->_attributes[$name] = $value;
}
public function has($name)
{
return isset($this->_attributes[$name]);
}
}
\ No newline at end of file
......@@ -55,10 +55,23 @@
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Lukas Smith <smith@pooteeweet.org> (MDB2 library)
* @author Roman Borschel <roman@code-factory.org>
* @todo Split up into Doctrine::DBAL::Connection & Doctrine::ORM::EntityManager.
* Doctrine::DBAL::Connection must have no dependencies on ORM components since
* it sits one layer below.
* Right now, this is the unification of these two classes.
* @todo
* 1) REPLICATION SUPPORT
* Replication support should be tackled at this layer (DBAL).
* There can be options that look like:
* 'slaves' => array(
* 'slave1' => array(
* user, pass etc.
* ),
* 'slave2' => array(
* user, pass etc.
* )),
* 'slaveConnectionResolver' => new MySlaveConnectionResolver(),
* 'masters' => array(...),
* 'masterConnectionResolver' => new MyMasterConnectionResolver()
*
* Doctrine::DBAL could ship with a simple standard resolver that uses a primitive
* round-robin approach to distribution. User can provide its own resolvers.
*/
abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
{
......@@ -66,9 +79,24 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
* The PDO database handle.
*
* @var PDO
* @todo Rename to $pdo.
*/
protected $dbh;
/**
* The Configuration.
*
* @var Configuration
*/
protected $_config;
/**
* The EventManager.
*
* @var EventManager
*/
protected $_eventManager;
/**
* The attributes.
*
......@@ -77,8 +105,6 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
protected $_attributes = array();
/**
* $_name
*
* Name of the connection
*
* @var string $_name
......@@ -128,9 +154,9 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
protected $serverInfo = array();
/**
*
* The parameters used during creation of the Connection.
*/
protected $options = array();
protected $_params = array();
/**
* List of all available drivers.
......@@ -196,29 +222,60 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
*
* @param Doctrine_Manager $manager the manager object
* @param PDO|Doctrine_Adapter_Interface $adapter database driver
* @todo Remove the dependency on the Manager for DBAL/ORM separation.
*/
public function __construct($adapter, $user = null, $pass = null)
public function __construct(array $params)
{
if (is_object($adapter)) {
if ( ! $adapter instanceof PDO) {
throw new Doctrine_Connection_Exception(
'First argument should be an instance of PDO or implement Doctrine_Adapter_Interface');
}
$this->dbh = $adapter;
if (isset($params['pdo'])) {
$this->dbh = $pdo;
$this->isConnected = true;
} else if (is_array($adapter)) {
$this->pendingAttributes[Doctrine::ATTR_DRIVER_NAME] = $adapter['scheme'];
}
$this->_params = $params;
}
$this->options['dsn'] = $adapter['dsn'];
$this->options['username'] = $adapter['user'];
$this->options['password'] = $adapter['pass'];
/**
* Sets the Configuration used by the Connection.
*
* @param Doctrine_Configuration $config
*/
public function setConfiguration(Doctrine_Configuration $config)
{
$this->_config = $config;
}
$this->options['other'] = array();
if (isset($adapter['other'])) {
$this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']);
/**
* Gets the Configuration used by the Connection.
*
* @return Configuration
*/
public function getConfiguration()
{
if ( ! $this->_config) {
$this->_config = new Doctrine_Configuration();
}
return $this->_config;
}
/**
* Sets the EventManager used by the Connection.
*
* @param Doctrine_EventManager $eventManager
*/
public function setEventManager(Doctrine_EventManager $eventManager)
{
$this->_eventManager = $eventManager;
}
/**
* Gets the EventManager used by the Connection.
*
* @return EventManager
*/
public function getEventManager()
{
if ( ! $this->_eventManager) {
$this->_eventManager = new Doctrine_EventManager();
}
return $this->_eventManager;
}
/**
......@@ -319,6 +376,19 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
return true;
}
/**
* Constructs the PDO DSN for use in the PDO constructor.
* Concrete connection implementations override this implementation to
* create the proper DSN.
*
* @return string
* @todo make abstract, implement in subclasses.
*/
protected function _constructPdoDsn()
{
}
/**
* @todo Remove. Breaks encapsulation.
*/
......@@ -1074,12 +1144,6 @@ abstract class Doctrine_Connection implements Doctrine_Configurable, Countable
return Doctrine_Lib::getConnectionAsString($this);
}
/*
* ----------- EntityManager methods ---------------
*/
/*
* ----------- Mixed methods (need to figure out where they go) ---------------
*/
......
......@@ -29,6 +29,7 @@
* @since 1.0
* @version $Revision$
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @TODO Remove this class and move the modifyLimitQuery implementation to Connection.
*/
class Doctrine_Connection_Common extends Doctrine_Connection
{
......
......@@ -18,7 +18,9 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Connection_Common');
#namespace Doctrine::DBAL::Connections;
/**
* Doctrine_Connection_Mysql
*
......
......@@ -18,7 +18,9 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_Connection_Common');
#namespace Doctrine::DBAL::Connections;
/**
* Doctrine_Connection_Mysql
*
......@@ -70,12 +72,14 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
'pattern_escaping' => true
);
$this->properties['string_quoting'] = array('start' => "'",
$this->properties['string_quoting'] = array(
'start' => "'",
'end' => "'",
'escape' => '\\',
'escape_pattern' => '\\');
$this->properties['identifier_quoting'] = array('start' => '`',
$this->properties['identifier_quoting'] = array(
'start' => '`',
'end' => '`',
'escape' => '`');
......@@ -97,9 +101,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common
*/
public function setCharset($charset)
{
$query = 'SET NAMES ' . $this->quote($charset);
$this->exec($query);
$this->exec('SET NAMES ' . $this->quote($charset));
}
/**
......
......@@ -18,9 +18,11 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload("Doctrine_Connection_Common");
#namespace Doctrine::DBAL::Connections;
/**
* Doctrine_Connection_Pgsql
* PgsqlConnection
*
* @package Doctrine
* @subpackage Connection
......
......@@ -95,12 +95,13 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
protected $_em;
/**
* The dbal connection used by the unit of work.
* The calculator used to calculate the order in which changes to
* entities need to be written to the database.
*
* @var Doctrine_Connection
* @todo Not needed in the future. Remove.
* @var unknown_type
* @todo Implementation. Replace buildFlushTree().
*/
protected $_conn;
protected $_commitOrderCalculator;
/**
* Commits the unit of work, executing all operations that have been postponed
......
<?php
#namespace Doctrine::DBAL;
class Doctrine_ConnectionFactory
{
private $_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');
public function __construct()
{
}
public function createConnection(array $params)
{
$this->_checkParams($params);
$className = $this->_drivers[$params['driver']];
return new $className($params);
}
private function _checkParams(array $params)
{
// check existance of mandatory parameters
// driver
if ( ! isset($params['driver'])) {
throw Doctrine_ConnectionFactory_Exception::driverRequired();
}
// user
if ( ! isset($params['user'])) {
throw Doctrine_ConnectionFactory_Exception::userRequired();
}
// password
if ( ! isset($params['password'])) {
throw Doctrine_ConnectionFactory_Exception::passwordRequired();
}
// check validity of parameters
// driver
if ( ! isset($this->_drivers[$params['driver']])) {
throw Doctrine_ConnectionFactory_Exception::unknownDriver($driverName);
}
// existing pdo object
if (isset($params['pdo']) && ! $params['pdo'] instanceof PDO) {
throw Doctrine_ConnectionFactory_Exception::invalidPDOInstance();
}
}
}
?>
\ No newline at end of file
<?php
/*
* $Id$
*
* 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.org>.
*/
/**
* Doctrine_ConnectionFactory_Exception
*
* @package Doctrine
* @subpackage Compiler
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ConnectionFactory_Exception extends Doctrine_Exception
{
public static function userRequired()
{
return new self("The 'user' option is mandatory.");
}
}
\ No newline at end of file
......@@ -218,7 +218,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite
public function __construct($isNewEntry = true, array $data = array())
{
$this->_entityName = get_class($this);
$this->_em = Doctrine_EntityManager::getManager($this->_entityName);
$this->_em = Doctrine_EntityManagerFactory::getManager($this->_entityName);
$this->_class = $this->_em->getClassMetadata($this->_entityName);
$this->_oid = self::$_index++;
......@@ -591,8 +591,8 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite
*/
public function serialize()
{
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE);
$this->preSerialize($event);
//$event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE);
//$this->preSerialize($event);
$vars = get_object_vars($this);
......@@ -629,7 +629,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite
$str = serialize($vars);
$this->postSerialize($event);
//$this->postSerialize($event);
return $str;
}
......@@ -644,12 +644,11 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite
*/
public function unserialize($serialized)
{
$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE);
$this->preUnserialize($event);
//$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE);
//$this->preUnserialize($event);
$this->_entityName = get_class($this);
$manager = Doctrine_EntityManager::getManager($this->_entityName);
$manager = Doctrine_EntityManagerFactory::getManager($this->_entityName);
$connection = $manager->getConnection();
$this->_oid = self::$_index;
......@@ -684,7 +683,7 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite
$this->cleanData($this->_data);
$this->_extractIdentifier($this->exists());
$this->postUnserialize($event);
//$this->postUnserialize($event);
}
/**
......
......@@ -19,7 +19,16 @@
* <http://www.phpdoctrine.org>.
*/
#namespace org::phpdoctrine::orm;
#namespace Doctrine::ORM;
#use Doctrine::Common::Configuration;
#use Doctrine::Common::EventManager;
#use Doctrine::Common::NullObject;
#use Doctrine::DBAL::Connections::Connection;
#use Doctrine::ORM::Exceptions::EntityManagerException;
#use Doctrine::ORM::Internal::UnitOfWork;
#use Doctrine::ORM::Mapping::ClassMetadata;
/**
* The EntityManager is a central access point to ORM functionality.
......@@ -33,7 +42,7 @@
* @author Roman Borschel <roman@code-factory.org>
* @todo package:orm
*/
class Doctrine_EntityManager
class Doctrine_EntityManager implements Doctrine_Configurable
{
/**
* The unique name of the EntityManager. The name is used to bind entity classes
......@@ -43,6 +52,34 @@ class Doctrine_EntityManager
*/
private $_name;
/**
* The used Configuration.
*
* @var Configuration
*/
private $_configuration;
// -- configuration stuff to be removed. replaced by Configuration.
private $_nullObject;
/**
* The attributes.
*
* @var array
*/
private $_attributes = array(
'quoteIdentifier' => false,
'indexNameFormat' => '%s_idx',
'sequenceNameFormat' => '%s_seq',
'tableNameFormat' => '%s',
'resultCache' => null,
'resultCacheLifeSpan' => null,
'queryCache' => null,
'queryCacheLifeSpan' => null,
'metadataCache' => null,
'metadataCacheLifeSpan' => null
);
/**
* The database connection used by the EntityManager.
*
......@@ -92,20 +129,6 @@ class Doctrine_EntityManager
*/
private $_flushMode = 'commit';
/**
* Map of all EntityManagers, keys are the names.
*
* @var array
*/
private static $_ems = array();
/**
* EntityManager to Entity bindings.
*
* @var array
*/
private static $_emBindings = array();
/**
* The unit of work.
*
......@@ -140,67 +163,19 @@ class Doctrine_EntityManager
$this->_metadataFactory = new Doctrine_ClassMetadata_Factory(
$this, new Doctrine_ClassMetadata_CodeDriver());
$this->_unitOfWork = new Doctrine_Connection_UnitOfWork($conn);
//$this->_eventManager = new Doctrine_EventManager();
if ($name !== null) {
self::$_ems[$name] = $this;
} else {
self::$_ems[] = $this;
}
}
/**
* Gets the EntityManager that is responsible for the Entity.
*
* @param string $entityName
* @return EntityManager
* @throws Doctrine_EntityManager_Exception If a suitable manager can not be found.
*/
public static function getManager($entityName = null)
{
if ( ! is_null($entityName) && isset(self::$_emBindings[$entityName])) {
$emName = self::$_emBindings[$entityName];
if (isset(self::$_ems[$emName])) {
return self::$_ems[$emName];
} else {
throw Doctrine_EntityManager_Exception::noManagerWithName($emName);
}
} else if (self::$_ems) {
return current(self::$_ems);
} else {
throw Doctrine_EntityManager_Exception::noEntityManagerAvailable();
}
$this->_nullObject = Doctrine_Null::$INSTANCE;
$this->_initAttributes();
}
/**
* Binds an Entity to a specific EntityManager.
*
* @param string $entityName
* @param string $emName
*/
public static function bindEntityToManager($entityName, $emName)
private function _initAttributes()
{
if (isset(self::$_emBindings[$entityName])) {
throw Doctrine_EntityManager_Exception::entityAlreadyBound($entityName);
// Change null default values to references to the Null object to allow
// fast isset() checks instead of array_key_exists().
foreach ($this->_attributes as $key => $value) {
if ($value === null) {
$this->_attributes[$key] = $this->_nullObject;
}
self::$_emBindings[$entityName] = $emName;
}
/**
* Clears all bindings between Entities and EntityManagers.
*/
public static function unbindAllManagers()
{
self::$_emBindings = array();
}
/**
* Releases all EntityManagers.
*
*/
public static function releaseAllManagers()
{
self::$_ems = array();
}
/**
......@@ -572,6 +547,53 @@ class Doctrine_EntityManager
{
return $this->_eventManager;
}
/**
* Sets the EventManager used by the EntityManager.
*
* @param Doctrine_EventManager $eventManager
*/
public function setEventManager(Doctrine_EventManager $eventManager)
{
$this->_eventManager = $eventManager;
}
/**
* Sets the Configuration used by the EntityManager.
*
* @param Doctrine_Configuration $config
*/
public function setConfiguration(Doctrine_Configuration $config)
{
$this->_configuration = $config;
}
/* Configurable implementation */
public function hasAttribute($name)
{
return isset($this->_attributes[$name]);
}
public function getAttribute($name)
{
if ( ! $this->hasAttribute($name)) {
throw Doctrine_EntityManager_Exception::unknownAttribute($name);
}
if ($this->_attributes[$name] === $this->_nullObject) {
return null;
}
return $this->_attributes[$name];
}
public function setAttribute($name, $value)
{
if ( ! $this->hasAttribute($name)) {
throw Doctrine_EntityManager_Exception::unknownAttribute($name);
}
// TODO: do some value checking depending on the attribute
$this->_attributes[$name] = $value;
}
}
?>
\ No newline at end of file
......@@ -19,13 +19,11 @@
* <http://www.phpdoctrine.org>.
*/
#namespace Doctrine::ORM;
#namespace Doctrine::ORM::Exceptions;
/**
* Doctrine_EntityManager_Exception
*
* @package Doctrine
* @subpackage Entity
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
......@@ -54,4 +52,9 @@ class Doctrine_EntityManager_Exception extends Doctrine_Exception
{
return new self("EntityManager named '$emName' not found.");
}
public static function unknownAttribute($name)
{
return new self("Unknown EntityManager attribute '$name'.");
}
}
\ No newline at end of file
<?php
#namespace Doctrine::ORM;
#use Doctrine::DBAL::ConnectionFactory;
#use Doctrine::Common::Configuration;
#use Doctrine::Common::EventManager;
/**
* The EntityManagerFactory is responsible for bootstrapping EntityManager
* instances as well as keeping track of all created EntityManagers and
* hard bindings to Entities.
*
* @since 2.0
*/
class Doctrine_EntityManagerFactory
{
/**
* Map of all created EntityManagers, keys are the names.
*
* @var array
*/
private static $_ems = array();
/**
* EntityManager to Entity bindings.
*
* @var array
*/
private static $_emBindings = array();
/**
* The ConnectionFactory used to create DBAL connections.
*
* @var unknown_type
*/
private $_connFactory;
/**
* The EventManager that is injected into all created Connections
* and EntityManagers.
*
* @var EventManager
*/
private $_eventManager;
/**
* The Configuration that is injected into all creatd Connections
* and EntityManagers.
*
* @var Configuration
*/
private $_config;
public function __construct()
{
$this->_connFactory = new Doctrine_ConnectionFactory();
}
public function setConfiguration(Doctrine_Configuration $config)
{
$this->_config = $config;
}
public function setEventManager(Doctrine_EventManager $eventManager)
{
$this->_eventManager = $eventManager;
}
public function createEntityManager($connParams, $name = null)
{
if ( ! $this->_config) {
$this->_config = new Doctrine_Configuration();
}
if ( ! $this->_eventManager) {
$this->_eventManager = new Doctrine_EventManager();
}
$conn = $this->_connFactory->createConnection($connParams);
$conn->setEventManager($this->_eventManager);
$conn->setConfiguration($this->_config);
$em = new Doctrine_EntityManager($conn);
$em->setEventManager($this->_eventManager);
$em->setConfiguration($this->_config);
if ($name !== null) {
self::$_ems[$name] = $em;
} else {
self::$_ems[] = $em;
}
return $em;
}
/**
* Gets the EntityManager that is responsible for the Entity.
* Static method, so that ActiveEntities can look up the right EntityManager
* without having a reference to the factory at hand.
*
* @param string $entityName
* @return EntityManager
* @throws Doctrine_EntityManager_Exception If a suitable manager can not be found.
*/
public static function getManager($entityName = null)
{
if ( ! is_null($entityName) && isset(self::$_emBindings[$entityName])) {
$emName = self::$_emBindings[$entityName];
if (isset(self::$_ems[$emName])) {
return self::$_ems[$emName];
} else {
throw Doctrine_EntityManagerFactory_Exception::noManagerWithName($emName);
}
} else if (self::$_ems) {
return current(self::$_ems);
} else {
throw Doctrine_EntityManagerFactory_Exception::noEntityManagerAvailable();
}
}
/**
* Gets the EntityManager that is responsible for the Entity.
*
* @param unknown_type $entityName
* @return unknown
*/
public function getEntityManager($entityName = null)
{
return self::getManager($entityName);
}
/**
* Binds an Entity to a specific EntityManager.
*
* @param string $entityName
* @param string $emName
*/
public function bindEntityToManager($entityName, $emName)
{
if (isset(self::$_emBindings[$entityName])) {
throw Doctrine_EntityManagerFactory_Exception::entityAlreadyBound($entityName);
}
self::$_emBindings[$entityName] = $emName;
}
/**
* Clears all bindings between Entities and EntityManagers.
*/
public function unbindAllManagers()
{
self::$_emBindings = array();
}
/**
* Releases all EntityManagers.
*
*/
public function releaseAllManagers()
{
self::unbindAllManagers();
self::$_ems = array();
}
public function releaseAllBindings()
{
self::$_emBindings = array();
}
public function releaseEntityManager($name)
{
if (isset(self::$_ems[$name])) {
unset(self::$_ems[$name]);
return true;
}
return false;
}
}
?>
\ No newline at end of file
......@@ -37,296 +37,42 @@ class Doctrine_Event
/* Event callback constants */
const preDelete = 'preDelete';
const postDelete = 'postDelete';
//...more
protected $_type;
protected $_target;
protected $_defaultPrevented;
/*
const CONN_QUERY = 1;
const CONN_EXEC = 2;
const CONN_PREPARE = 3;
const CONN_CONNECT = 4;
const CONN_CLOSE = 5;
const CONN_ERROR = 6;
const STMT_EXECUTE = 10;
const STMT_FETCH = 11;
const STMT_FETCHALL = 12;
const TX_BEGIN = 31;
const TX_COMMIT = 32;
const TX_ROLLBACK = 33;
const SAVEPOINT_CREATE = 34;
const SAVEPOINT_ROLLBACK = 35;
const SAVEPOINT_COMMIT = 36;
const HYDRATE = 40;
const RECORD_DELETE = 21;
const RECORD_SAVE = 22;
const RECORD_UPDATE = 23;
const RECORD_INSERT = 24;
const RECORD_SERIALIZE = 25;
const RECORD_UNSERIALIZE = 26;
*/
/**
* @var mixed $_invoker the handler which invoked this event
*/
//protected $_invoker;
/**
* @var string $_query the sql query associated with this event (if any)
*/
//protected $_query;
/**
* @var string $_params the parameters associated with the query (if any)
*/
//protected $_params;
/**
* @see Doctrine_Event constants
* @var integer $_code the event code
*/
//protected $_code;
/**
* @var integer $_startedMicrotime the time point in which this event was started
*/
//protected $_startedMicrotime;
/**
* @var integer $_endedMicrotime the time point in which this event was ended
*/
//protected $_endedMicrotime;
/**
* @var array $_options an array of options
*/
//protected $_options = array();
/**
* constructor
*
* @param Doctrine_Connection|Doctrine_Connection_Statement|
Doctrine_Connection_UnitOfWork|Doctrine_Transaction $invoker the handler which invoked this event
* @param integer $code the event code
* @param string $query the sql query associated with this event (if any)
*/
/*public function __construct($invoker, $code, $query = null, $params = array())
{
$this->_invoker = $invoker;
$this->_code = $code;
$this->_query = $query;
$this->_params = $params;
}*/
/**
* getQuery
*
* @return string returns the query associated with this event (if any)
*/
/*public function getQuery()
{
return $this->_query;
}*/
/**
* getName
* returns the name of this event
*
* @return string the name of this event
*/
/*public function getName()
{
switch ($this->_code) {
case self::CONN_QUERY:
return 'query';
case self::CONN_EXEC:
return 'exec';
case self::CONN_PREPARE:
return 'prepare';
case self::CONN_CONNECT:
return 'connect';
case self::CONN_CLOSE:
return 'close';
case self::CONN_ERROR:
return 'error';
case self::STMT_EXECUTE:
return 'execute';
case self::STMT_FETCH:
return 'fetch';
case self::STMT_FETCHALL:
return 'fetch all';
case self::TX_BEGIN:
return 'begin';
case self::TX_COMMIT:
return 'commit';
case self::TX_ROLLBACK:
return 'rollback';
case self::SAVEPOINT_CREATE:
return 'create savepoint';
case self::SAVEPOINT_ROLLBACK:
return 'rollback savepoint';
case self::SAVEPOINT_COMMIT:
return 'commit savepoint';
case self::RECORD_DELETE:
return 'delete record';
case self::RECORD_SAVE:
return 'save record';
case self::RECORD_UPDATE:
return 'update record';
case self::RECORD_INSERT:
return 'insert record';
case self::RECORD_SERIALIZE:
return 'serialize record';
case self::RECORD_UNSERIALIZE:
return 'unserialize record';
}
}
*/
/**
* getCode
*
* @return integer returns the code associated with this event
*/
/*public function getCode()
{
return $this->_code;
}*/
/**
* getOption
* returns the value of an option
*
* @param string $option the name of the option
* @return mixed
*/
/*public function __get($option)
public function __construct($type, $target = null)
{
if ( ! isset($this->_options[$option])) {
return null;
$this->_type = $type;
$this->_target = $target;
$this->_defaultPrevented = false;
}
return $this->_options[$option];
}*/
/**
* skipOperation
* skips the next operation
* an alias for __set('skipOperation', true)
*
* @return Doctrine_Event this object
*/
/*public function skipOperation()
public function getType()
{
$this->_options['skipOperation'] = true;
return $this;
}*/
/**
* setOption
* sets the value of an option
*
* @param string $option the name of the option
* @param mixed $value the value of the given option
* @return Doctrine_Event this object
*/
/*public function __set($option, $value)
{
$this->_options[$option] = $value;
return $this;
}*/
/**
* setOption
* sets the value of an option by reference
*
* @param string $option the name of the option
* @param mixed $value the value of the given option
* @return Doctrine_Event this object
*/
/*public function set($option, &$value)
{
$this->_options[$option] =& $value;
return $this;
}*/
/**
* start
* starts the internal timer of this event
*
* @return Doctrine_Event this object
*/
/*public function start()
{
$this->_startedMicrotime = microtime(true);
}*/
return $this->_type;
}
/**
* hasEnded
* whether or not this event has ended
*
* @return boolean
*/
/*public function hasEnded()
{
return ($this->_endedMicrotime != null);
}*/
/**
* end
* ends the internal timer of this event
*
* @return Doctrine_Event this object
*/
/*public function end()
public function preventDefault()
{
$this->_endedMicrotime = microtime(true);
$this->_defaultPrevented = true;
}
return $this;
}*/
/**
* getInvoker
* returns the handler that invoked this event
*
* @return Doctrine_Connection|Doctrine_Connection_Statement|
* Doctrine_Connection_UnitOfWork|Doctrine_Transaction the handler that invoked this event
*/
/*public function getInvoker()
public function getDefaultPrevented()
{
return $this->_invoker;
}*/
return $this->_defaultPrevented;
}
/**
* getParams
* returns the parameters of the query
*
* @return array parameters of the query
*/
/*public function getParams()
{
return $this->_params;
}*/
/**
* Get the elapsed time (in microseconds) that the event ran. If the event has
* not yet ended, return false.
*
* @return mixed
*/
/*public function getElapsedSecs()
public function getTarget()
{
if (is_null($this->_endedMicrotime)) {
return false;
return $this->_target;
}
return ($this->_endedMicrotime - $this->_startedMicrotime);
}*/
}
......@@ -18,7 +18,7 @@
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
*/
Doctrine::autoload('Doctrine_EventListener_Interface');
/**
* Doctrine_EventListener all event listeners extend this base class
* the empty methods allow child classes to only implement the methods they need to implement
......
<?php
#namespace Doctrine::Common;
class Doctrine_EventManager
{
private $_listeners = array();
public function dispatchEvent($event) {
$argIsCallback = is_string($event);
$callback = $argIsCallback ? $event : $event->getType();
if (isset($this->_listeners[$callback])) {
$event = $argIsCallback ? new Doctrine_Event($event) : $event;
foreach ($this->_listeners[$callback] as $listener) {
$listener->$callback($event);
}
}
return ! $event->getDefaultPrevented();
}
public function getListeners($callback = null) {
return $callback ? $this->_listeners[$callback] : $this->_listeners;
}
public function hasListeners($callback) {
return isset($this->_listeners[$callback]);
}
public function registerEventListener($listener, $callbacks) {
// TODO: maybe check for duplicate registrations?
if (is_array($callbacks)) {
foreach ($callbacks as $callback) {
$this->_listeners[$callback] = $listener;
}
} else {
$this->_listeners[$callbacks] = $listener;
}
}
}
?>
\ No newline at end of file
......@@ -92,14 +92,12 @@ class Doctrine_Manager implements Doctrine_Configurable, Countable, IteratorAggr
if ( ! $init) {
$init = true;
$attributes = array(
Doctrine::ATTR_CACHE => null,
Doctrine::ATTR_RESULT_CACHE => null,
Doctrine::ATTR_QUERY_CACHE => null,
Doctrine::ATTR_LOAD_REFERENCES => true,
Doctrine::ATTR_LISTENER => new Doctrine_EventListener(),
Doctrine::ATTR_RECORD_LISTENER => null,
Doctrine::ATTR_THROW_EXCEPTIONS => true,
Doctrine::ATTR_VALIDATE => Doctrine::VALIDATE_NONE,
Doctrine::ATTR_QUERY_LIMIT => Doctrine::LIMIT_RECORDS,
Doctrine::ATTR_IDXNAME_FORMAT => "%s_idx",
Doctrine::ATTR_SEQNAME_FORMAT => "%s_seq",
......
......@@ -31,7 +31,7 @@
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Parser
......
......@@ -30,7 +30,7 @@
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @since 2.0
* @version $Revision$
*/
abstract class Doctrine_Query_Production
......
......@@ -130,7 +130,7 @@ class Doctrine_Query_Production_PathExpression extends Doctrine_Query_Production
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$conn = $manager->getConnection();
// Looking for queryComponent to fetch
......
......@@ -119,7 +119,7 @@ class Doctrine_Query_Production_PathExpressionEndingWithAsterisk extends Doctrin
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$conn = $manager->getConnection();
// Looking for componentAlias to fetch
......
......@@ -116,7 +116,7 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_
// Get the connection for the component
$conn = $this->_parser->getSqlBuilder()->getConnection();
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$componentName = $this->_identifiers[0];
// Retrieving ClassMetadata and Mapper
......@@ -156,7 +156,7 @@ class Doctrine_Query_Production_RangeVariableDeclaration extends Doctrine_Query_
// Get the connection for the component
$conn = $this->_parser->getSqlBuilder()->getConnection();
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
// Retrieve the base component
try {
......
......@@ -134,7 +134,7 @@ class Doctrine_Query_Production_SelectExpression extends Doctrine_Query_Producti
$parserResult = $this->_parser->getParserResult();
// Retrieving connection
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$conn = $manager->getConnection();
switch (get_class($this->_leftExpression)) {
......
......@@ -28,7 +28,7 @@
* @author Janne Vanhala <jpvanhal@cc.hut.fi>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link http://www.phpdoctrine.org
* @since 1.0
* @since 2.0
* @version $Revision$
*/
class Doctrine_Query_Production_UpdateClause extends Doctrine_Query_Production
......
......@@ -84,7 +84,7 @@ class Doctrine_Query_Production_VariableDeclaration extends Doctrine_Query_Produ
// Get the connection for the component
$conn = $this->_parser->getSqlBuilder()->getConnection();
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
// Retrieving ClassMetadata and Mapper
try {
......@@ -124,7 +124,7 @@ class Doctrine_Query_Production_VariableDeclaration extends Doctrine_Query_Produ
$queryComponent = $parserResult->getQueryComponent($this->_componentAlias);
// Retrieving connection
$manager = Doctrine_EntityManager::getManager();
$manager = Doctrine_EntityManagerFactory::getManager();
$conn = $manager->getConnection();
return $conn->quoteIdentifier($queryComponent['metadata']->getTableName()) . ' '
......
......@@ -245,7 +245,7 @@ abstract class Doctrine_Relation implements ArrayAccess
*/
final public function getTable()
{
return Doctrine_EntityManager::getManager($this->definition['class'])
return Doctrine_EntityManagerFactory::getManager($this->definition['class'])
->getClassMetadata($this->definition['class']);
}
......@@ -269,7 +269,7 @@ abstract class Doctrine_Relation implements ArrayAccess
*/
final public function getClassMetadata()
{
return Doctrine_EntityManager::getManager($this->definition['class'])
return Doctrine_EntityManagerFactory::getManager($this->definition['class'])
->getClassMetadata($this->definition['class']);
}
......
......@@ -13,6 +13,7 @@ require_once 'Orm/Ticket/AllTests.php';
// Tests
require_once 'Orm/UnitOfWorkTestCase.php';
require_once 'Orm/EntityManagerFactoryTest.php';
class Orm_AllTests
{
......@@ -26,6 +27,7 @@ class Orm_AllTests
$suite = new Doctrine_OrmTestSuite('Doctrine Orm');
$suite->addTestSuite('Orm_UnitOfWorkTestCase');
$suite->addTestSuite('Orm_EntityManagerFactoryTest');
//$suite->addTestSuite('Orm_ConfigurableTestCase');
$suite->addTest(Orm_Component_AllTests::suite());
......
<?php
require_once 'lib/DoctrineTestInit.php';
#namespace Doctrine::Tests::ORM;
/**
* EntityManagerFactory tests.
*/
class Orm_EntityManagerFactoryTest extends Doctrine_OrmTestCase
{
private $_emf;
private $_mockOptions = array('driver' => 'mock', 'user' => '', 'password' => '');
protected function setUp() {
parent::setUp();
$this->_emf = $this->sharedFixture['emf'];
}
protected function tearDown() {
parent::tearDown();
}
private function _createNamedManager($name)
{
return $this->_emf->createEntityManager($this->_mockOptions, $name);
}
public function testBindingEntityToNamedManager()
{
$myEM = $this->_createNamedManager('myEM');
$this->_emf->bindEntityToManager('SomeEntity', 'myEM');
$this->assertSame($myEM, $this->_emf->getEntityManager('SomeEntity'));
$this->_emf->releaseEntityManager('myEM');
}
public function testStaticLookup()
{
$this->assertTrue(Doctrine_EntityManagerFactory::getManager() instanceof Doctrine_EntityManager);
}
}
\ No newline at end of file
<?php
require_once 'lib/DoctrineTestInit.php';
class Orm_EntityManagerTest extends Doctrine_OrmTestCase
{
protected function setUp() {
parent::setUp();
}
protected function tearDown() {
Doctrine_EntityManager::unbindAllManagers();
Doctrine_EntityManager::releaseAllManagers();
parent::tearDown();
}
public function testInstantiationRegistersInstanceInStaticMap()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testStaticGetManagerThrowsExceptionIfNoManagerAvailable()
{
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail("Expected exception not thrown.");
} catch (Doctrine_EntityManager_Exception $ex) {}
}
public function testBindingValidEntityToNamedManager()
{
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock(null), 'myEM');
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
$this->assertSame($em, Doctrine_EntityManager::getManager('SomeEntity'));
}
public function testBindingEntityToInvalidManagerThrowsExceptionOnRetrieval()
{
// will work. we don't check the existence of the EM during binding
Doctrine_EntityManager::bindEntityToManager('SomeEntity', 'myEM');
// exception on access
try {
Doctrine_EntityManager::getManager('SomeEntity');
$this->fail();
} catch (Doctrine_EntityManager_Exception $ex) {}
}
}
\ No newline at end of file
......@@ -7,12 +7,9 @@ require_once 'lib/mocks/Doctrine_HydratorMockStatement.php';
class Orm_Hydration_BasicHydrationTest extends Doctrine_OrmTestCase
{
private $_em;
protected function setUp()
{
parent::setUp();
$this->_em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
}
/** Getter for the hydration mode dataProvider */
......
......@@ -40,7 +40,7 @@ class Orm_Query_DeleteSqlGenerationTest extends Doctrine_OrmTestCase
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed)
{
try {
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery($dqlToBeTested);
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
......
......@@ -36,7 +36,7 @@ class Orm_Query_DqlGenerationTest extends Doctrine_OrmTestCase
{
protected function createQuery()
{
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
return $entityManager->createQuery();
}
......
......@@ -39,7 +39,7 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase
public function testSingleAliasDeclarationIsSupported()
{
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery('SELECT u.* FROM CmsUser u');
$parserResult = $query->parse();
......@@ -54,7 +54,7 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase
public function testSingleAliasDeclarationWithIndexByIsSupported()
{
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery('SELECT u.* FROM CmsUser u INDEX BY id');
$parserResult = $query->parse();
......@@ -69,7 +69,7 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase
public function testQueryParserSupportsMultipleAliasDeclarations()
{
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery('SELECT u.* FROM CmsUser u INDEX BY id LEFT JOIN u.phonenumbers p');
$parserResult = $query->parse();
......@@ -93,7 +93,7 @@ class Orm_Query_IdentifierRecognitionTest extends Doctrine_OrmTestCase
public function testQueryParserSupportsMultipleAliasDeclarationsWithIndexBy()
{
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery('SELECT u.* FROM CmsUser u INDEX BY id LEFT JOIN u.articles a INNER JOIN u.phonenumbers pn INDEX BY phonenumber');
$parserResult = $query->parse();
......
......@@ -41,7 +41,7 @@ class Orm_Query_LanguageRecognitionTest extends Doctrine_OrmTestCase
public function assertValidDql($dql)
{
try {
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery($dql);
$parserResult = $query->parse();
} catch (Doctrine_Exception $e) {
......@@ -52,7 +52,7 @@ class Orm_Query_LanguageRecognitionTest extends Doctrine_OrmTestCase
public function assertInvalidDql($dql)
{
try {
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery($dql);
$query->setDql($dql);
$parserResult = $query->parse();
......
......@@ -40,7 +40,7 @@ class Orm_Query_SelectSqlGenerationTest extends Doctrine_OrmTestCase
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed)
{
try {
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery($dqlToBeTested);
//echo print_r($query->parse()->getQueryFields(), true) . "\n";
......
......@@ -40,7 +40,7 @@ class Orm_Query_UpdateSqlGenerationTest extends Doctrine_OrmTestCase
public function assertSqlGeneration($dqlToBeTested, $sqlToBeConfirmed)
{
try {
$entityManager = Doctrine_EntityManager::getManager();
$entityManager = $this->sharedFixture['em'];
$query = $entityManager->createQuery($dqlToBeTested);
parent::assertEquals($sqlToBeConfirmed, $query->getSql());
......
......@@ -5,7 +5,9 @@
*/
class Doctrine_OrmTestCase extends Doctrine_TestCase
{
protected $_em;
protected function setUp() {
$em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
$this->_em = new Doctrine_EntityManager(new Doctrine_Connection_Mock());
}
}
......@@ -8,5 +8,21 @@
*/
class Doctrine_OrmTestSuite extends Doctrine_TestSuite
{
protected function setUp()
{
$emf = new Doctrine_EntityManagerFactory();
$emf->setConfiguration(new Doctrine_Configuration());
$emf->setEventManager(new Doctrine_EventManager());
$connectionOptions = array(
'driver' => 'mock',
'user' => 'john',
'password' => 'wayne'
);
$em = $emf->createEntityManager($connectionOptions, 'mockEM');
$this->sharedFixture['emf'] = $emf;
$this->sharedFixture['em'] = $em;
}
protected function tearDown()
{}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment