Changeset 4470 for trunk/lib/Doctrine
- Timestamp:
- 06/05/08 20:01:58 (7 months ago)
- Location:
- trunk/lib/Doctrine
- Files:
-
- 6 added
- 24 modified
-
AuditLog.php (modified) (2 diffs)
-
Collection.php (modified) (2 diffs)
-
Compiler.php (modified) (1 diff)
-
Configuration.php (added)
-
Connection.php (modified) (7 diffs)
-
Connection/Common.php (modified) (1 diff)
-
Connection/Mock.php (modified) (1 diff)
-
Connection/Mysql.php (modified) (3 diffs)
-
Connection/Pgsql.php (modified) (1 diff)
-
Connection/UnitOfWork.php (modified) (1 diff)
-
ConnectionFactory (added)
-
ConnectionFactory.php (added)
-
ConnectionFactory/Exception.php (added)
-
Entity.php (modified) (5 diffs)
-
EntityManager.php (modified) (6 diffs)
-
EntityManager/Exception.php (modified) (2 diffs)
-
EntityManagerFactory.php (added)
-
Event.php (modified) (1 diff)
-
EventListener.php (modified) (1 diff)
-
EventManager.php (added)
-
Manager.php (modified) (2 diffs)
-
Query/Parser.php (modified) (1 diff)
-
Query/Production.php (modified) (1 diff)
-
Query/Production/PathExpression.php (modified) (1 diff)
-
Query/Production/PathExpressionEndingWithAsterisk.php (modified) (1 diff)
-
Query/Production/RangeVariableDeclaration.php (modified) (2 diffs)
-
Query/Production/SelectExpression.php (modified) (1 diff)
-
Query/Production/UpdateClause.php (modified) (1 diff)
-
Query/Production/VariableDeclaration.php (modified) (2 diffs)
-
Relation.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Doctrine/AuditLog.php
r4364 r4470 20 20 */ 21 21 22 #namespace Doctrine::Behaviors::AuditLog; 23 22 24 /** 23 25 * Doctrine_AuditLog … … 30 32 * @version $Revision$ 31 33 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 34 * @todo Move to "Doctrine Behaviors" package. Separate download. 32 35 */ 33 36 class Doctrine_AuditLog extends Doctrine_Record_Generator -
trunk/lib/Doctrine/Collection.php
r4456 r4470 111 111 if (is_string($entityBaseType)) { 112 112 $this->_entityBaseType = $entityBaseType; 113 $mapper = Doctrine_EntityManager::getManager($entityBaseType)->getEntityPersister($entityBaseType); 113 $mapper = Doctrine_EntityManagerFactory::getManager($entityBaseType) 114 ->getEntityPersister($entityBaseType); 114 115 } 115 116 $this->_mapper = $mapper; … … 211 212 public function unserialize($serialized) 212 213 { 213 $manager = Doctrine_EntityManager ::getManager();214 $manager = Doctrine_EntityManagerFactory::getManager(); 214 215 $connection = $manager->getConnection(); 215 216 -
trunk/lib/Doctrine/Compiler.php
r3570 r4470 19 19 * <http://www.phpdoctrine.org>. 20 20 */ 21 22 #namespace Doctrine::ORM::Tools; 21 23 22 24 /** -
trunk/lib/Doctrine/Connection.php
r4456 r4470 56 56 * @author Lukas Smith <smith@pooteeweet.org> (MDB2 library) 57 57 * @author Roman Borschel <roman@code-factory.org> 58 * @todo Split up into Doctrine::DBAL::Connection & Doctrine::ORM::EntityManager. 59 * Doctrine::DBAL::Connection must have no dependencies on ORM components since 60 * it sits one layer below. 61 * Right now, this is the unification of these two classes. 58 * @todo 59 * 1) REPLICATION SUPPORT 60 * Replication support should be tackled at this layer (DBAL). 61 * There can be options that look like: 62 * 'slaves' => array( 63 * 'slave1' => array( 64 * user, pass etc. 65 * ), 66 * 'slave2' => array( 67 * user, pass etc. 68 * )), 69 * 'slaveConnectionResolver' => new MySlaveConnectionResolver(), 70 * 'masters' => array(...), 71 * 'masterConnectionResolver' => new MyMasterConnectionResolver() 72 * 73 * Doctrine::DBAL could ship with a simple standard resolver that uses a primitive 74 * round-robin approach to distribution. User can provide its own resolvers. 62 75 */ 63 76 abstract class Doctrine_Connection implements Doctrine_Configurable, Countable … … 66 79 * The PDO database handle. 67 80 * 68 * @var PDO 81 * @var PDO 82 * @todo Rename to $pdo. 69 83 */ 70 84 protected $dbh; 71 85 72 86 /** 87 * The Configuration. 88 * 89 * @var Configuration 90 */ 91 protected $_config; 92 93 /** 94 * The EventManager. 95 * 96 * @var EventManager 97 */ 98 protected $_eventManager; 99 100 /** 73 101 * The attributes. 74 102 * … … 78 106 79 107 /** 80 * $_name81 *82 108 * Name of the connection 83 109 * … … 129 155 130 156 /** 131 * 132 */ 133 protected $ options = array();157 * The parameters used during creation of the Connection. 158 */ 159 protected $_params = array(); 134 160 135 161 /** … … 197 223 * @param Doctrine_Manager $manager the manager object 198 224 * @param PDO|Doctrine_Adapter_Interface $adapter database driver 199 * @todo Remove the dependency on the Manager for DBAL/ORM separation. 200 */ 201 public function __construct($adapter, $user = null, $pass = null) 202 { 203 if (is_object($adapter)) { 204 if ( ! $adapter instanceof PDO) { 205 throw new Doctrine_Connection_Exception( 206 'First argument should be an instance of PDO or implement Doctrine_Adapter_Interface'); 207 } 208 $this->dbh = $adapter; 225 */ 226 public function __construct(array $params) 227 { 228 if (isset($params['pdo'])) { 229 $this->dbh = $pdo; 209 230 $this->isConnected = true; 210 } else if (is_array($adapter)) { 211 $this->pendingAttributes[Doctrine::ATTR_DRIVER_NAME] = $adapter['scheme']; 212 213 $this->options['dsn'] = $adapter['dsn']; 214 $this->options['username'] = $adapter['user']; 215 $this->options['password'] = $adapter['pass']; 216 217 $this->options['other'] = array(); 218 if (isset($adapter['other'])) { 219 $this->options['other'] = array(Doctrine::ATTR_PERSISTENT => $adapter['persistent']); 220 } 221 } 231 } 232 $this->_params = $params; 233 } 234 235 /** 236 * Sets the Configuration used by the Connection. 237 * 238 * @param Doctrine_Configuration $config 239 */ 240 public function setConfiguration(Doctrine_Configuration $config) 241 { 242 $this->_config = $config; 243 } 244 245 /** 246 * Gets the Configuration used by the Connection. 247 * 248 * @return Configuration 249 */ 250 public function getConfiguration() 251 { 252 if ( ! $this->_config) { 253 $this->_config = new Doctrine_Configuration(); 254 } 255 return $this->_config; 256 } 257 258 /** 259 * Sets the EventManager used by the Connection. 260 * 261 * @param Doctrine_EventManager $eventManager 262 */ 263 public function setEventManager(Doctrine_EventManager $eventManager) 264 { 265 $this->_eventManager = $eventManager; 266 } 267 268 /** 269 * Gets the EventManager used by the Connection. 270 * 271 * @return EventManager 272 */ 273 public function getEventManager() 274 { 275 if ( ! $this->_eventManager) { 276 $this->_eventManager = new Doctrine_EventManager(); 277 } 278 return $this->_eventManager; 222 279 } 223 280 … … 318 375 //$this->getListener()->postConnect($event); 319 376 return true; 377 } 378 379 /** 380 * Constructs the PDO DSN for use in the PDO constructor. 381 * Concrete connection implementations override this implementation to 382 * create the proper DSN. 383 * 384 * @return string 385 * @todo make abstract, implement in subclasses. 386 */ 387 protected function _constructPdoDsn() 388 { 389 320 390 } 321 391 … … 1075 1145 } 1076 1146 1077 1078 1079 /*1080 * ----------- EntityManager methods ---------------1081 */1082 1083 1147 /* 1084 1148 * ----------- Mixed methods (need to figure out where they go) --------------- -
trunk/lib/Doctrine/Connection/Common.php
r4328 r4470 30 30 * @version $Revision$ 31 31 * @author Konsta Vesterinen <kvesteri@cc.hut.fi> 32 * @TODO Remove this class and move the modifyLimitQuery implementation to Connection. 32 33 */ 33 34 class Doctrine_Connection_Common extends Doctrine_Connection -
trunk/lib/Doctrine/Connection/Mock.php
r4425 r4470 19 19 * <http://www.phpdoctrine.org>. 20 20 */ 21 Doctrine::autoload('Doctrine_Connection_Common'); 21 22 #namespace Doctrine::DBAL::Connections; 23 22 24 /** 23 25 * Doctrine_Connection_Mysql -
trunk/lib/Doctrine/Connection/Mysql.php
r4463 r4470 19 19 * <http://www.phpdoctrine.org>. 20 20 */ 21 Doctrine::autoload('Doctrine_Connection_Common'); 21 22 #namespace Doctrine::DBAL::Connections; 23 22 24 /** 23 25 * Doctrine_Connection_Mysql … … 51 53 52 54 $this->supported = array( 53 'sequences' => 'emulated', 54 'indexes' => true, 55 'affected_rows' => true, 56 'transactions' => true, 57 'savepoints' => false, 58 'summary_functions' => true, 59 'order_by_text' => true, 60 'current_id' => 'emulated', 61 'limit_queries' => true, 62 'LOBs' => true, 63 'replace' => true, 64 'sub_selects' => true, 65 'auto_increment' => true, 66 'primary_key' => true, 67 'result_introspection' => true, 68 'prepared_statements' => 'emulated', 69 'identifier_quoting' => true, 70 'pattern_escaping' => true 71 ); 72 73 $this->properties['string_quoting'] = array('start' => "'", 74 'end' => "'", 75 'escape' => '\\', 76 'escape_pattern' => '\\'); 77 78 $this->properties['identifier_quoting'] = array('start' => '`', 79 'end' => '`', 80 'escape' => '`'); 55 'sequences' => 'emulated', 56 'indexes' => true, 57 'affected_rows' => true, 58 'transactions' => true, 59 'savepoints' => false, 60 'summary_functions' => true, 61 'order_by_text' => true, 62 'current_id' => 'emulated', 63 'limit_queries' => true, 64 'LOBs' => true, 65 'replace' => true, 66 'sub_selects' => true, 67 'auto_increment' => true, 68 'primary_key' => true, 69 'result_introspection' => true, 70 'prepared_statements' => 'emulated', 71 'identifier_quoting' => true, 72 'pattern_escaping' => true 73 ); 74 75 $this->properties['string_quoting'] = array( 76 'start' => "'", 77 'end' => "'", 78 'escape' => '\\', 79 'escape_pattern' => '\\'); 80 81 $this->properties['identifier_quoting'] = array( 82 'start' => '`', 83 'end' => '`', 84 'escape' => '`'); 81 85 82 86 $this->properties['sql_comments'] = array( 83 array('start' => '-- ', 'end' => "\n", 'escape' => false),84 array('start' => '#', 'end' => "\n", 'escape' => false),85 array('start' => '/*', 'end' => '*/', 'escape' => false),86 );87 array('start' => '-- ', 'end' => "\n", 'escape' => false), 88 array('start' => '#', 'end' => "\n", 'escape' => false), 89 array('start' => '/*', 'end' => '*/', 'escape' => false), 90 ); 87 91 88 92 $this->properties['varchar_max_length'] = 255; … … 98 102 public function setCharset($charset) 99 103 { 100 $query = 'SET NAMES ' . $this->quote($charset); 101 102 $this->exec($query); 104 $this->exec('SET NAMES ' . $this->quote($charset)); 103 105 } 104 106 -
trunk/lib/Doctrine/Connection/Pgsql.php
r4422 r4470 19 19 * <http://www.phpdoctrine.org>. 20 20 */ 21 Doctrine::autoload("Doctrine_Connection_Common"); 21 22 #namespace Doctrine::DBAL::Connections; 23 22 24 /** 23 * Doctrine_Connection_Pgsql25 * PgsqlConnection 24 26 * 25 27 * @package Doctrine -
trunk/lib/Doctrine/Connection/UnitOfWork.php
r4456 r4470 96 96 97 97 /** 98 * The dbal connection used by the unit of work. 99 * 100 * @var Doctrine_Connection 101 * @todo Not needed in the future. Remove. 102 */ 103 protected $_conn; 98 * The calculator used to calculate the order in which changes to 99 * entities need to be written to the database. 100 * 101 * @var unknown_type 102 * @todo Implementation. Replace buildFlushTree(). 103 */ 104 protected $_commitOrderCalculator; 104 105 105 106 /** -
trunk/lib/Doctrine/Entity.php
r4464 r4470 219 219 { 220 220 $this->_entityName = get_class($this); 221 $this->_em = Doctrine_EntityManager ::getManager($this->_entityName);221 $this->_em = Doctrine_EntityManagerFactory::getManager($this->_entityName); 222 222 $this->_class = $this->_em->getClassMetadata($this->_entityName); 223 223 $this->_oid = self::$_index++; … … 592 592 public function serialize() 593 593 { 594 $event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE);595 $this->preSerialize($event);594 //$event = new Doctrine_Event($this, Doctrine_Event::RECORD_SERIALIZE); 595 //$this->preSerialize($event); 596 596 597 597 $vars = get_object_vars($this); … … 630 630 $str = serialize($vars); 631 631 632 $this->postSerialize($event);632 //$this->postSerialize($event); 633 633 634 634 return $str; … … 645 645 public function unserialize($serialized) 646 646 { 647 $event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE); 648 649 $this->preUnserialize($event); 647 //$event = new Doctrine_Event($this, Doctrine_Event::RECORD_UNSERIALIZE); 648 //$this->preUnserialize($event); 650 649 651 650 $this->_entityName = get_class($this); 652 $manager = Doctrine_EntityManager ::getManager($this->_entityName);651 $manager = Doctrine_EntityManagerFactory::getManager($this->_entityName); 653 652 $connection = $manager->getConnection(); 654 653 … … 685 684 $this->_extractIdentifier($this->exists()); 686 685 687 $this->postUnserialize($event);686 //$this->postUnserialize($event); 688 687 } 689 688 -
trunk/lib/Doctrine/EntityManager.php
r4466 r4470 20 20 */ 21 21 22 #namespace org::phpdoctrine::orm; 22 #namespace Doctrine::ORM; 23 24 #use Doctrine::Common::Configuration; 25 #use Doctrine::Common::EventManager; 26 #use Doctrine::Common::NullObject; 27 #use Doctrine::DBAL::Connections::Connection; 28 #use Doctrine::ORM::Exceptions::EntityManagerException; 29 #use Doctrine::ORM::Internal::UnitOfWork; 30 #use Doctrine::ORM::Mapping::ClassMetadata; 31 23 32 24 33 /** … … 34 43 * @todo package:orm 35 44 */ 36 class Doctrine_EntityManager 45 class Doctrine_EntityManager implements Doctrine_Configurable 37 46 { 38 47 /** … … 43 52 */ 44 53 private $_name; 54 55 /** 56 * The used Configuration. 57 * 58 * @var Configuration 59 */ 60 private $_configuration; 61 62 63 // -- configuration stuff to be removed. replaced by Configuration. 64 private $_nullObject; 65 /** 66 * The attributes. 67 * 68 * @var array 69 */ 70 private $_attributes = array( 71 'quoteIdentifier' => false, 72 'indexNameFormat' => '%s_idx', 73 'sequenceNameFormat' => '%s_seq', 74 'tableNameFormat' => '%s', 75 'resultCache' => null, 76 'resultCacheLifeSpan' => null, 77 'queryCache' => null, 78 'queryCacheLifeSpan' => null, 79 'metadataCache' => null, 80 'metadataCacheLifeSpan' => null 81 ); 45 82 46 83 /** … … 94 131 95 132 /** 96 * Map of all EntityManagers, keys are the names.97 *98 * @var array99 */100 private static $_ems = array();101 102 /**103 * EntityManager to Entity bindings.104 *105 * @var array106 */107 private static $_emBindings = array();108 109 /**110 133 * The unit of work. 111 134 * … … 141 164 $this, new Doctrine_ClassMetadata_CodeDriver()); 142 165 $this->_unitOfWork = new Doctrine_Connection_UnitOfWork($conn); 143 //$this->_eventManager = new Doctrine_EventManager(); 144 145 if ($name !== null) { 146 self::$_ems[$name] = $this; 147 } else { 148 self::$_ems[] = $this; 149 } 150 } 151 152 /** 153 * Gets the EntityManager that is responsible for the Entity. 154 * 155 * @param string $entityName 156 * @return EntityManager 157 * @throws Doctrine_EntityManager_Exception If a suitable manager can not be found. 158 */ 159 public static function getManager($entityName = null) 160 { 161 if ( ! is_null($entityName) && isset(self::$_emBindings[$entityName])) { 162 $emName = self::$_emBindings[$entityName]; 163 if (isset(self::$_ems[$emName])) { 164 return self::$_ems[$emName]; 165 } else { 166 throw Doctrine_EntityManager_Exception::noManagerWithName($emName); 166 $this->_nullObject = Doctrine_Null::$INSTANCE; 167 $this->_initAttributes(); 168 } 169 170 private function _initAttributes() 171 { 172 // Change null default values to references to the Null object to allow 173 // fast isset() checks instead of array_key_exists(). 174 foreach ($this->_attributes as $key => $value) { 175 if ($value === null) { 176 $this->_attributes[$key] = $this->_nullObject; 167 177 } 168 } else if (self::$_ems) { 169 return current(self::$_ems); 170 } else { 171 throw Doctrine_EntityManager_Exception::noEntityManagerAvailable(); 172 } 173 } 174 175 /** 176 * Binds an Entity to a specific EntityManager. 177 * 178 * @param string $entityName 179 * @param string $emName 180 */ 181 public static function bindEntityToManager($entityName, $emName) 182 { 183 if (isset(self::$_emBindings[$entityName])) { 184 throw Doctrine_EntityManager_Exception::entityAlreadyBound($entityName); 185 } 186 self::$_emBindings[$entityName] = $emName; 187 } 188 189 /** 190 * Clears all bindings between Entities and EntityManagers. 191 */ 192 public static function unbindAllManagers() 193 { 194 self::$_emBindings = array(); 195 } 196 197 /** 198 * Releases all EntityManagers. 199 * 200 */ 201 public static function releaseAllManagers() 202 { 203 self::$_ems = array(); 178 } 204 179 } 205 180 … … 573 548 return $this->_eventManager; 574 549 } 550 551 /** 552 * Sets the EventManager used by the EntityManager. 553 * 554 * @param Doctrine_EventManager $eventManager 555 */ 556 public function setEventManager(Doctrine_EventManager $eventManager)