From ec5bb2ea3f0000650eab9f3f8bdbc2f0213ef840 Mon Sep 17 00:00:00 2001 From: romanb Date: Fri, 30 May 2008 12:09:24 +0000 Subject: [PATCH] some minor refactorings. started to make a draft of the new namespaced folder structure. --- lib/Doctrine/Access.php | 2 + lib/Doctrine/Cache.php | 2 +- lib/Doctrine/ClassMetadata.php | 28 +- lib/Doctrine/Collection.php | 2 + lib/Doctrine/Configurable.php | 427 +-------------------- lib/Doctrine/Connection.php | 62 ++- lib/Doctrine/Connection/UnitOfWork.php | 2 + lib/Doctrine/DataDict.php | 2 + lib/Doctrine/Entity.php | 3 +- lib/Doctrine/EntityManager.php | 36 +- lib/Doctrine/EntityRepository.php | 2 + lib/Doctrine/Event.php | 89 ++--- lib/Doctrine/Exception.php | 73 +--- lib/Doctrine/Export.php | 4 +- lib/Doctrine/Expression.php | 4 +- lib/Doctrine/Formatter.php | 4 +- lib/Doctrine/Hook.php | 3 +- lib/Doctrine/HydratorNew.php | 2 + lib/Doctrine/I18n.php | 5 +- lib/Doctrine/Import.php | 4 +- lib/Doctrine/Inflector.php | 2 + lib/Doctrine/Lib.php | 5 +- lib/Doctrine/Log.php | 1 + lib/Doctrine/Manager.php | 51 +-- lib/Doctrine/Migration.php | 3 + lib/Doctrine/Null.php | 2 + lib/Doctrine/Relation/ForeignKey.php | 2 +- lib/Doctrine/Search.php | 2 + lib/Doctrine/Transaction.php | 4 +- lib/Doctrine/Util.php | 5 +- lib/Doctrine/Validator.php | 2 + lib/Doctrine/View.php | 5 +- tests/Orm/Hydration/BasicHydrationTest.php | 3 + 33 files changed, 211 insertions(+), 632 deletions(-) diff --git a/lib/Doctrine/Access.php b/lib/Doctrine/Access.php index abebadb0b..89e4a4dca 100644 --- a/lib/Doctrine/Access.php +++ b/lib/Doctrine/Access.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM; /** * Doctrine_Access diff --git a/lib/Doctrine/Cache.php b/lib/Doctrine/Cache.php index 83f9a1c1c..17bf575dc 100644 --- a/lib/Doctrine/Cache.php +++ b/lib/Doctrine/Cache.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_EventListener'); + /** * Doctrine_Cache * diff --git a/lib/Doctrine/ClassMetadata.php b/lib/Doctrine/ClassMetadata.php index f66a7e15f..3e6a2d6e5 100644 --- a/lib/Doctrine/ClassMetadata.php +++ b/lib/Doctrine/ClassMetadata.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM::Mapping; + /** * A ClassMetadata instance holds all the information (metadata) of an entity and * it's associations and how they're mapped to the relational database. @@ -28,7 +30,7 @@ * @author Roman Borschel * @since 2.0 */ -class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializable +class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable { /** * The name of the entity class that is mapped to the database with this metadata. @@ -1970,19 +1972,19 @@ class Doctrine_ClassMetadata extends Doctrine_Configurable implements Serializab return $this; } - public function hasAttribute($key) + public function hasAttribute($name) { - switch ($key) { - case Doctrine::ATTR_SEQCOL_NAME: - case Doctrine::ATTR_COLL_KEY: - case Doctrine::ATTR_LOAD_REFERENCES: - case Doctrine::ATTR_EXPORT: - case Doctrine::ATTR_QUERY_LIMIT: - case Doctrine::ATTR_VALIDATE: - return true; - default: - return false; - } + return false; + } + + public function getAttribute($name) + { + return null; + } + + public function setAttribute($name, $value) + { + ; } diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 37a1e4e3a..88fa0c6a7 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM; + /** * A persistent collection of entities. * A collection object is strongly typed in the sense that it can only contain diff --git a/lib/Doctrine/Configurable.php b/lib/Doctrine/Configurable.php index ee9ffec6f..841781e88 100644 --- a/lib/Doctrine/Configurable.php +++ b/lib/Doctrine/Configurable.php @@ -1,4 +1,4 @@ -. */ +#namespace Doctrine::Core; + /** * Doctrine_Configurable * - * - * @package Doctrine - * @subpackage Configurable * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org - * @since 1.0 + * @since 2.0 * @version $Revision$ * @author Konsta Vesterinen + * @author Roman Borschel */ -abstract class Doctrine_Configurable +interface Doctrine_Configurable { - /** - * @var array $attributes an array of containing all attributes - */ - protected $_attributes = array(); - - /** - * @var Doctrine_Configurable $parent the parent of this component - */ - protected $parent; - - /** - * @var array $_impl an array containing concrete implementations for class templates - * keys as template names and values as names of the concrete - * implementation classes - */ - //protected $_impl = array(); - - /** - * @var array $_params an array of user defined parameters - */ - //protected $_params = array(); - - /** - * setAttribute - * sets a given attribute - * - * - * $manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL); - * - * // or - * - * $manager->setAttribute('portability', Doctrine::PORTABILITY_ALL); - * - * // or - * - * $manager->setAttribute('portability', 'all'); - * - * - * @param mixed $attribute either a Doctrine::ATTR_* integer constant or a string - * corresponding to a constant - * @param mixed $value the value of the attribute - * @see Doctrine::ATTR_* constants - * @throws Doctrine_Exception if the value is invalid - * @return void - */ - public function setAttribute($attribute, $value) - { - if (is_string($attribute)) { - $upper = strtoupper($attribute); - - $const = 'Doctrine::ATTR_' . $upper; - - if (defined($const)) { - $attribute = constant($const); - } else { - throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); - } - } - - if (is_string($value) && isset($upper)) { - $const = 'Doctrine::' . $upper . '_' . strtoupper($value); - - if (defined($const)) { - $value = constant($const); - } else { - throw new Doctrine_Exception('Unknown attribute value: "' . $value . '"'); - } - } - - switch ($attribute) { - case Doctrine::ATTR_FETCHMODE: // deprecated - throw new Doctrine_Exception('Deprecated attribute. See http://www.phpdoctrine.org/documentation/manual?chapter=configuration'); - case Doctrine::ATTR_LISTENER: - $this->setEventListener($value); - break; - case Doctrine::ATTR_COLL_KEY: // class attribute - if ( ! ($this instanceof Doctrine_ClassMetadata)) { - throw new Doctrine_Exception("This attribute can only be set at class level."); - } - if ($value !== null && ! $this->hasField($value)) { - throw new Doctrine_Exception("Couldn't set collection key attribute. No such field '$value'"); - } - break; - case Doctrine::ATTR_CACHE: // deprecated - case Doctrine::ATTR_RESULT_CACHE:// manager/session attribute - case Doctrine::ATTR_QUERY_CACHE: // manager/session attribute - if ($value !== null) { - if ( ! ($value instanceof Doctrine_Cache_Interface)) { - throw new Doctrine_Exception('Cache driver should implement Doctrine_Cache_Interface'); - } - } - break; - case Doctrine::ATTR_VALIDATE: // manager/session attribute - case Doctrine::ATTR_QUERY_LIMIT: // manager/session attribute - case Doctrine::ATTR_QUOTE_IDENTIFIER: // manager/session attribute - case Doctrine::ATTR_PORTABILITY: // manager/session attribute - case Doctrine::ATTR_DEFAULT_TABLE_TYPE: // manager/session attribute - case Doctrine::ATTR_EMULATE_DATABASE: // manager/session attribute - case Doctrine::ATTR_USE_NATIVE_ENUM: // manager/session attribute - case Doctrine::ATTR_DEFAULT_SEQUENCE: // ?? - case Doctrine::ATTR_EXPORT: // manager/session attribute - case Doctrine::ATTR_DECIMAL_PLACES: // manager/session attribute - case Doctrine::ATTR_LOAD_REFERENCES: // class attribute - case Doctrine::ATTR_RECORD_LISTENER: // not an attribute - case Doctrine::ATTR_THROW_EXCEPTIONS: // manager/session attribute - case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: - case Doctrine::ATTR_MODEL_LOADING: // manager/session attribute - - break; - case Doctrine::ATTR_SEQCOL_NAME: // class attribute - if ( ! is_string($value)) { - throw new Doctrine_Exception('Sequence column name attribute only accepts string values'); - } - break; - case Doctrine::ATTR_FIELD_CASE: // manager/session attribute - if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER) - throw new Doctrine_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.'); - break; - case Doctrine::ATTR_SEQNAME_FORMAT: // manager/session attribute - case Doctrine::ATTR_IDXNAME_FORMAT: // manager/session attribute - case Doctrine::ATTR_TBLNAME_FORMAT: // manager/session attribute - if ($this instanceof Doctrine_ClassMetadata) { - throw new Doctrine_Exception('Sequence / index name format attributes cannot be set' - . ' at class level (only at connection or global level).'); - } - break; - default: - throw new Doctrine_Exception("Unknown attribute."); - } - - $this->_attributes[$attribute] = $value; - - } - - /*public function getParams($namespace = null) - { - if ($namespace == null) { - $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); - } - - if ( ! isset($this->_params[$namespace])) { - return null; - } - - return $this->_params[$namespace]; - }*/ - - /*public function getParamNamespaces() - { - return array_keys($this->_params); - }*/ - - /*public function setParam($name, $value, $namespace = null) - { - if ($namespace == null) { - $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); - } - - $this->_params[$namespace][$name] = $value; - - return $this; - }*/ - - /*public function getParam($name, $value, $namespace) - { - if ($namespace == null) { - $namespace = $this->getAttribute(Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE); - } - - if ( ! isset($this->_params[$name])) { - if (isset($this->parent)) { - return $this->parent->getParam($name); - } - return null; - } - return $this->_params[$name]; - }*/ - - /** - * setImpl - * binds given class to given template name - * - * this method is the base of Doctrine dependency injection - * - * @param string $template name of the class template - * @param string $class name of the class to be bound - * @return Doctrine_Configurable this object - */ - /*public function setImpl($template, $class) - { - $this->_impl[$template] = $class; - - return $this; - }*/ - - /** - * getImpl - * returns the implementation for given class - * - * @return string name of the concrete implementation - */ - /*public function getImpl($template) - { - if ( ! isset($this->_impl[$template])) { - if (isset($this->parent)) { - return $this->parent->getImpl($template); - } - return null; - } - return $this->_impl[$template]; - }*/ - - - /*public function hasImpl($template) - { - if ( ! isset($this->_impl[$template])) { - if (isset($this->parent)) { - return $this->parent->hasImpl($template); - } - return false; - } - return true; - }*/ - - /** - * @param Doctrine_EventListener $listener - * @return void - */ - public function setEventListener($listener) - { - return $this->setListener($listener); - } - - /** - * addRecordListener - * - * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener - * @return mixed this object - */ - public function addRecordListener($listener, $name = null) - { - if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER]) || - ! ($this->_attributes[Doctrine::ATTR_RECORD_LISTENER] instanceof Doctrine_Record_Listener_Chain)) { - - $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener_Chain(); - } - $this->_attributes[Doctrine::ATTR_RECORD_LISTENER]->add($listener, $name); - - return $this; - } - - /** - * getListener - * - * @return Doctrine_EventListener_Interface|Doctrine_Overloadable - */ - public function getRecordListener() - { - if ( ! isset($this->_attributes[Doctrine::ATTR_RECORD_LISTENER])) { - if (isset($this->parent)) { - return $this->parent->getRecordListener(); - } - $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = new Doctrine_Record_Listener(); - } - return $this->_attributes[Doctrine::ATTR_RECORD_LISTENER]; - } - - /** - * setListener - * - * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener - * @return Doctrine_Configurable this object - */ - public function setRecordListener($listener) - { - if ( ! ($listener instanceof Doctrine_Record_Listener_Interface) - && ! ($listener instanceof Doctrine_Overloadable) - ) { - throw new Doctrine_Exception("Couldn't set eventlistener. Record listeners should implement either Doctrine_Record_Listener_Interface or Doctrine_Overloadable"); - } - $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = $listener; - - return $this; - } - - public function removeRecordListeners() - { - $this->_attributes[Doctrine::ATTR_RECORD_LISTENER] = null; - } - - /** - * addListener - * - * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener - * @return mixed this object - */ - public function addListener($listener, $name = null) - { - if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER]) || - ! ($this->_attributes[Doctrine::ATTR_LISTENER] instanceof Doctrine_EventListener_Chain)) { - - $this->_attributes[Doctrine::ATTR_LISTENER] = new Doctrine_EventListener_Chain(); - } - $this->_attributes[Doctrine::ATTR_LISTENER]->add($listener, $name); - - return $this; - } - - /** - * getListener - * - * @return Doctrine_EventListener_Interface|Doctrine_Overloadable - */ - public function getListener() - { - if ( ! isset($this->_attributes[Doctrine::ATTR_LISTENER])) { - if (isset($this->parent)) { - return $this->parent->getListener(); - } - return null; - } - return $this->_attributes[Doctrine::ATTR_LISTENER]; - } - - /** - * setListener - * - * @param Doctrine_EventListener_Interface|Doctrine_Overloadable $listener - * @return Doctrine_Configurable this object - */ - public function setListener($listener) - { - if ( ! ($listener instanceof Doctrine_EventListener_Interface) - && ! ($listener instanceof Doctrine_Overloadable)) { - throw new Doctrine_EventListener_Exception("Couldn't set eventlistener. EventListeners should implement either Doctrine_EventListener_Interface or Doctrine_Overloadable"); - } - $this->_attributes[Doctrine::ATTR_LISTENER] = $listener; - - return $this; - } - - /** - * returns the value of an attribute - * - * @param integer $attribute - * @return mixed - */ - public function getAttribute($attribute) - { - if (is_string($attribute)) { - $upper = strtoupper($attribute); - - $const = 'Doctrine::ATTR_' . $upper; - - if (defined($const)) { - $attribute = constant($const); - } else { - throw new Doctrine_Exception('Unknown attribute: "' . $attribute . '"'); - } - } - - $attribute = (int) $attribute; - - if ($attribute < 0) { - throw new Doctrine_Exception('Unknown attribute.'); - } - - if (isset($this->_attributes[$attribute])) { - return $this->_attributes[$attribute]; - } - - if (isset($this->parent)) { - return $this->parent->getAttribute($attribute); - } - return null; - } - - /** - * getAttributes - * returns all attributes as an array - * - * @return array - */ - public function getAttributes() - { - return $this->_attributes; - } - - /** - * Sets a parent for this configurable component - * the parent must be a configurable component itself. - * - * @param Doctrine_Configurable $component - * @return void - */ - public function setConfigurableParent(Doctrine_Configurable $component) - { - $this->parent = $component; - } - - /** - * getParent - * Returns the parent of this component. - * - * @return Doctrine_Configurable - */ - public function getParent() - { - return $this->parent; - } -} + public function getAttribute($name); + public function setAttribute($name, $value); + public function hasAttribute($name); +} \ No newline at end of file diff --git a/lib/Doctrine/Connection.php b/lib/Doctrine/Connection.php index 2131b11a5..6bbce578e 100644 --- a/lib/Doctrine/Connection.php +++ b/lib/Doctrine/Connection.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::DBAL::Connections; + /** * Doctrine_Connection * @@ -58,7 +60,7 @@ * it sits one layer below. * Right now, this is the unification of these two classes. */ -abstract class Doctrine_Connection extends Doctrine_Configurable implements Countable +abstract class Doctrine_Connection implements Doctrine_Configurable, Countable { /** * The PDO database handle. @@ -67,6 +69,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ protected $dbh; + /** + * The attributes. + * + * @var array + */ + protected $_attributes = array(); + /** * $_name * @@ -143,13 +152,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun /* * ----------- Mixed attributes (need to split up) --------------- */ - /** - * @var array $pendingAttributes An array of pending attributes. When setting attributes - * no connection is needed. When connected all the pending - * attributes are passed to the underlying adapter (usually PDO) instance. - */ - protected $pendingAttributes = array(); - /** * @var array $modules an array containing all modules * transaction Doctrine_Transaction driver, handles savepoint and transaction isolation abstraction @@ -184,14 +186,13 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun 'export' => false, 'import' => false, 'sequence' => false, - 'unitOfWork' => false, 'formatter' => false, 'util' => false, ); /** - * the constructor + * Constructor. * * @param Doctrine_Manager $manager the manager object * @param PDO|Doctrine_Adapter_Interface $adapter database driver @@ -220,34 +221,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } } - /** - * getOption - * - * Retrieves option - * - * @param string $option - * @return void - */ - public function getOption($option) - { - if (isset($this->options[$option])) { - return $this->options[$option]; - } - } - - /** - * setOption - * - * Set option value - * - * @param string $option - * @return void - */ - public function setOption($option, $value) - { - return $this->options[$option] = $value; - } - /** * returns an array of available PDO drivers */ @@ -301,7 +274,6 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun { //$this->connect(); - return $this->dbh; } @@ -1121,9 +1093,14 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun */ public function getAttribute($attribute) { + if ($attribute == Doctrine::ATTR_QUOTE_IDENTIFIER) { + return false; + } + + /* legacy */ if ($attribute >= 100) { if ( ! isset($this->_attributes[$attribute])) { - return parent::getAttribute($attribute); + return null; } return $this->_attributes[$attribute]; } @@ -1168,6 +1145,11 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } return $this; } + + public function hasAttribute($name) + { + return false; + } /** * __get diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index dca2d7011..7771c7e55 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM::Internal; + /** * The UnitOfWork is responsible for writing out changes to the database at * the correct time and in the correct order. diff --git a/lib/Doctrine/DataDict.php b/lib/Doctrine/DataDict.php index 74844acbb..161d7c78d 100644 --- a/lib/Doctrine/DataDict.php +++ b/lib/Doctrine/DataDict.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::DBAL::DataDicts; + /** * Doctrine_DataDict * diff --git a/lib/Doctrine/Entity.php b/lib/Doctrine/Entity.php index 0218f7a1a..1e9074a54 100644 --- a/lib/Doctrine/Entity.php +++ b/lib/Doctrine/Entity.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM; + /** * Doctrine_Entity * All record classes should inherit this super class @@ -997,7 +999,6 @@ abstract class Doctrine_Entity extends Doctrine_Access implements Countable, Ite if ($getter = $this->_getCustomAccessor($fieldName)) { return $this->$getter(); } - $this->_invokeCustomAccessor($fieldName); // Use built-in accessor functionality $nullObj = Doctrine_Null::$INSTANCE; diff --git a/lib/Doctrine/EntityManager.php b/lib/Doctrine/EntityManager.php index 5e7dd4f57..53aa670b4 100644 --- a/lib/Doctrine/EntityManager.php +++ b/lib/Doctrine/EntityManager.php @@ -19,7 +19,7 @@ * . */ -#namespace Doctrine::ORM; +#namespace org::phpdoctrine::orm; /** * The EntityManager is a central access point to ORM functionality. @@ -113,6 +113,13 @@ class Doctrine_EntityManager */ private $_unitOfWork; + /** + * The event manager that is the central point of the event system. + * + * @var EventManager + */ + private $_eventManager; + /** * Enter description here... * @@ -130,9 +137,11 @@ class Doctrine_EntityManager { $this->_conn = $conn; $this->_name = $name; - $this->_metadataFactory = new Doctrine_ClassMetadata_Factory($this, - new Doctrine_ClassMetadata_CodeDriver()); + $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 { @@ -164,10 +173,10 @@ class Doctrine_EntityManager } /** - * Enter description here... + * Binds an Entity to a specific EntityManager. * - * @param unknown_type $entityName - * @param unknown_type $emName + * @param string $entityName + * @param string $emName */ public static function bindEntityToManager($entityName, $emName) { @@ -544,10 +553,25 @@ class Doctrine_EntityManager } } + /** + * Gets the UnitOfWork used by the EntityManager. + * + * @return UnitOfWork + */ public function getUnitOfWork() { return $this->_unitOfWork; } + + /** + * Gets the EventManager used by the EntityManager. + * + * @return EventManager + */ + public function getEventManager() + { + return $this->_eventManager; + } } ?> \ No newline at end of file diff --git a/lib/Doctrine/EntityRepository.php b/lib/Doctrine/EntityRepository.php index 07773f84b..a037721b4 100644 --- a/lib/Doctrine/EntityRepository.php +++ b/lib/Doctrine/EntityRepository.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM; + /** * Base class for all custom user-defined repositories. * Provides basic finder methods, common to all repositories. diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Event.php index 3151b68af..49f17f13e 100644 --- a/lib/Doctrine/Event.php +++ b/lib/Doctrine/Event.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM::Events; /** * Doctrine_Event @@ -31,10 +33,14 @@ * @version $Revision$ */ class Doctrine_Event -{ - /** - * CONNECTION EVENT CODES - */ +{ + /* Event callback constants */ + const preDelete = 'preDelete'; + const postDelete = 'postDelete'; + + + + /* const CONN_QUERY = 1; const CONN_EXEC = 2; const CONN_PREPARE = 3; @@ -55,51 +61,48 @@ class Doctrine_Event const HYDRATE = 40; - /* - * RECORD EVENT CODES - */ 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; + //protected $_invoker; /** * @var string $_query the sql query associated with this event (if any) */ - protected $_query; + //protected $_query; /** * @var string $_params the parameters associated with the query (if any) */ - protected $_params; + //protected $_params; /** * @see Doctrine_Event constants * @var integer $_code the event code */ - protected $_code; + //protected $_code; /** * @var integer $_startedMicrotime the time point in which this event was started */ - protected $_startedMicrotime; + //protected $_startedMicrotime; /** * @var integer $_endedMicrotime the time point in which this event was ended */ - protected $_endedMicrotime; + //protected $_endedMicrotime; /** * @var array $_options an array of options */ - protected $_options = array(); + //protected $_options = array(); /** * constructor @@ -109,23 +112,23 @@ class Doctrine_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()) + /*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() + /*public function getQuery() { return $this->_query; - } + }*/ /** * getName @@ -133,7 +136,7 @@ class Doctrine_Event * * @return string the name of this event */ - public function getName() + /*public function getName() { switch ($this->_code) { case self::CONN_QUERY: @@ -184,16 +187,16 @@ class Doctrine_Event return 'unserialize record'; } } - + */ /** * getCode * * @return integer returns the code associated with this event */ - public function getCode() + /*public function getCode() { return $this->_code; - } + }*/ /** * getOption @@ -202,14 +205,14 @@ class Doctrine_Event * @param string $option the name of the option * @return mixed */ - public function __get($option) + /*public function __get($option) { if ( ! isset($this->_options[$option])) { return null; } return $this->_options[$option]; - } + }*/ /** * skipOperation @@ -218,12 +221,12 @@ class Doctrine_Event * * @return Doctrine_Event this object */ - public function skipOperation() + /*public function skipOperation() { $this->_options['skipOperation'] = true; return $this; - } + }*/ /** * setOption @@ -233,12 +236,12 @@ class Doctrine_Event * @param mixed $value the value of the given option * @return Doctrine_Event this object */ - public function __set($option, $value) + /*public function __set($option, $value) { $this->_options[$option] = $value; return $this; - } + }*/ /** * setOption @@ -248,12 +251,12 @@ class Doctrine_Event * @param mixed $value the value of the given option * @return Doctrine_Event this object */ - public function set($option, &$value) + /*public function set($option, &$value) { $this->_options[$option] =& $value; return $this; - } + }*/ /** * start @@ -261,10 +264,10 @@ class Doctrine_Event * * @return Doctrine_Event this object */ - public function start() + /*public function start() { $this->_startedMicrotime = microtime(true); - } + }*/ /** * hasEnded @@ -272,10 +275,10 @@ class Doctrine_Event * * @return boolean */ - public function hasEnded() + /*public function hasEnded() { return ($this->_endedMicrotime != null); - } + }*/ /** * end @@ -283,12 +286,12 @@ class Doctrine_Event * * @return Doctrine_Event this object */ - public function end() + /*public function end() { $this->_endedMicrotime = microtime(true); return $this; - } + }*/ /** * getInvoker @@ -297,10 +300,10 @@ class Doctrine_Event * @return Doctrine_Connection|Doctrine_Connection_Statement| * Doctrine_Connection_UnitOfWork|Doctrine_Transaction the handler that invoked this event */ - public function getInvoker() + /*public function getInvoker() { return $this->_invoker; - } + }*/ /** * getParams @@ -308,10 +311,10 @@ class Doctrine_Event * * @return array parameters of the query */ - public function getParams() + /*public function getParams() { return $this->_params; - } + }*/ /** * Get the elapsed time (in microseconds) that the event ran. If the event has @@ -319,11 +322,11 @@ class Doctrine_Event * * @return mixed */ - public function getElapsedSecs() + /*public function getElapsedSecs() { if (is_null($this->_endedMicrotime)) { return false; } return ($this->_endedMicrotime - $this->_startedMicrotime); - } + }*/ } diff --git a/lib/Doctrine/Exception.php b/lib/Doctrine/Exception.php index a2f91c608..950a25dc3 100644 --- a/lib/Doctrine/Exception.php +++ b/lib/Doctrine/Exception.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM::Exceptions; /** * Doctrine_Exception @@ -28,65 +30,22 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @author Roman Borschel */ class Doctrine_Exception extends Exception -{ - /** - * @var array $_errorMessages an array of error messages - */ - protected static $_errorMessages = array( - Doctrine::ERR => 'unknown error', - Doctrine::ERR_ALREADY_EXISTS => 'already exists', - Doctrine::ERR_CANNOT_CREATE => 'can not create', - Doctrine::ERR_CANNOT_ALTER => 'can not alter', - Doctrine::ERR_CANNOT_REPLACE => 'can not replace', - Doctrine::ERR_CANNOT_DELETE => 'can not delete', - Doctrine::ERR_CANNOT_DROP => 'can not drop', - Doctrine::ERR_CONSTRAINT => 'constraint violation', - Doctrine::ERR_CONSTRAINT_NOT_NULL=> 'null value violates not-null constraint', - Doctrine::ERR_DIVZERO => 'division by zero', - Doctrine::ERR_INVALID => 'invalid', - Doctrine::ERR_INVALID_DATE => 'invalid date or time', - Doctrine::ERR_INVALID_NUMBER => 'invalid number', - Doctrine::ERR_MISMATCH => 'mismatch', - Doctrine::ERR_NODBSELECTED => 'no database selected', - Doctrine::ERR_NOSUCHFIELD => 'no such field', - Doctrine::ERR_NOSUCHTABLE => 'no such table', - Doctrine::ERR_NOT_CAPABLE => 'Doctrine backend not capable', - Doctrine::ERR_NOT_FOUND => 'not found', - Doctrine::ERR_NOT_LOCKED => 'not locked', - Doctrine::ERR_SYNTAX => 'syntax error', - Doctrine::ERR_UNSUPPORTED => 'not supported', - Doctrine::ERR_VALUE_COUNT_ON_ROW => 'value count on row', - Doctrine::ERR_INVALID_DSN => 'invalid DSN', - Doctrine::ERR_CONNECT_FAILED => 'connect failed', - Doctrine::ERR_NEED_MORE_DATA => 'insufficient data supplied', - Doctrine::ERR_EXTENSION_NOT_FOUND=> 'extension not found', - Doctrine::ERR_NOSUCHDB => 'no such database', - Doctrine::ERR_ACCESS_VIOLATION => 'insufficient permissions', - Doctrine::ERR_LOADMODULE => 'error while including on demand module', - Doctrine::ERR_TRUNCATED => 'truncated', - Doctrine::ERR_DEADLOCK => 'deadlock detected', - ); - - /** - * Return a textual error message for a Doctrine error code - * - * @param int|array integer error code, - * null to get the current error code-message map, - * or an array with a new error code-message map - * - * @return string error message - */ - public function errorMessage($value = null) - { - if (is_null($value)) { - return self::$_errorMessages; - } - - return isset(self::$_errorMessages[$value]) ? - self::$_errorMessages[$value] : self::$_errorMessages[Doctrine::ERR]; +{ + private $_innerException; + + public function __construct($message = "", Doctrine_Exception $innerException = null) + { + parent::__construct($message); + $this->_innerException = $innerException; + } + + public function getInnerException() + { + return $this->_innerException; } } diff --git a/lib/Doctrine/Export.php b/lib/Doctrine/Export.php index 6a35ae8d9..c83129d70 100644 --- a/lib/Doctrine/Export.php +++ b/lib/Doctrine/Export.php @@ -18,7 +18,9 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + +#namespace Doctrine::DBAL::Export; + /** * Doctrine_Export * diff --git a/lib/Doctrine/Expression.php b/lib/Doctrine/Expression.php index 7970c6d9e..e603cba74 100644 --- a/lib/Doctrine/Expression.php +++ b/lib/Doctrine/Expression.php @@ -18,7 +18,9 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + +#namespace Doctrine::DBAL::Expressions; + /** * Doctrine_Expression * diff --git a/lib/Doctrine/Formatter.php b/lib/Doctrine/Formatter.php index be03b6428..2abc4f7db 100644 --- a/lib/Doctrine/Formatter.php +++ b/lib/Doctrine/Formatter.php @@ -18,7 +18,9 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + +#namespace Doctrine::DBAL::Tools; + /** * Doctrine_Formatter * diff --git a/lib/Doctrine/Hook.php b/lib/Doctrine/Hook.php index 6a7c718cd..4fb44ec24 100644 --- a/lib/Doctrine/Hook.php +++ b/lib/Doctrine/Hook.php @@ -28,7 +28,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @todo May be no longer useful and can be removed later. */ class Doctrine_Hook { diff --git a/lib/Doctrine/HydratorNew.php b/lib/Doctrine/HydratorNew.php index ae714190b..8d94ff0c8 100644 --- a/lib/Doctrine/HydratorNew.php +++ b/lib/Doctrine/HydratorNew.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM::Internal; + /** * The hydrator has the tedious to process result sets returned by the database * and turn them into useable structures. diff --git a/lib/Doctrine/I18n.php b/lib/Doctrine/I18n.php index d4d7f2e1f..36dd036a5 100644 --- a/lib/Doctrine/I18n.php +++ b/lib/Doctrine/I18n.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::Behaviors::I18n; /** * Doctrine_I18n @@ -28,7 +30,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @todo To "Doctrine Behaviors" package. Separate download. */ class Doctrine_I18n extends Doctrine_Record_Generator { diff --git a/lib/Doctrine/Import.php b/lib/Doctrine/Import.php index 6f557991e..27efecf0a 100644 --- a/lib/Doctrine/Import.php +++ b/lib/Doctrine/Import.php @@ -18,7 +18,9 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + +#namespace Doctrine::DBAL::Import; + /** * class Doctrine_Import * Main responsible of performing import operation. Delegates database schema diff --git a/lib/Doctrine/Inflector.php b/lib/Doctrine/Inflector.php index 08fd352da..15c8ed72b 100644 --- a/lib/Doctrine/Inflector.php +++ b/lib/Doctrine/Inflector.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::ORM::Tools; + /** * Doctrine_Inflector has static methods for inflecting text * diff --git a/lib/Doctrine/Lib.php b/lib/Doctrine/Lib.php index 71f39f9b7..6dbc16e21 100644 --- a/lib/Doctrine/Lib.php +++ b/lib/Doctrine/Lib.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM::Tools; /** * Doctrine_Lib has not commonly used static functions, mostly for debugging purposes @@ -28,7 +30,8 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @todo Split into DBAL/ORM parts. DBAL class goes into Doctrine::DBAL::Tools */ class Doctrine_Lib { diff --git a/lib/Doctrine/Log.php b/lib/Doctrine/Log.php index db3f57a94..1978c6cb9 100755 --- a/lib/Doctrine/Log.php +++ b/lib/Doctrine/Log.php @@ -27,6 +27,7 @@ * @link www.phpdoctrine.org * @since 1.0 * @version $Revision: 3155 $ + * @todo Can possibly be removed. */ class Doctrine_Log { diff --git a/lib/Doctrine/Manager.php b/lib/Doctrine/Manager.php index 7ac9c8487..875b63ac7 100644 --- a/lib/Doctrine/Manager.php +++ b/lib/Doctrine/Manager.php @@ -32,7 +32,7 @@ * @version $Revision$ * @author Konsta Vesterinen */ -class Doctrine_Manager extends Doctrine_Configurable implements Countable, IteratorAggregate +class Doctrine_Manager implements Doctrine_Configurable, Countable, IteratorAggregate { /** * @var array $connections an array containing all the opened connections @@ -124,47 +124,14 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera public function hasAttribute($key) { - switch ($key) { - case Doctrine::ATTR_DEFAULT_PARAM_NAMESPACE: - case Doctrine::ATTR_COLL_KEY: - case Doctrine::ATTR_SEQCOL_NAME: - case Doctrine::ATTR_LISTENER: - case Doctrine::ATTR_RECORD_LISTENER: - case Doctrine::ATTR_QUOTE_IDENTIFIER: - case Doctrine::ATTR_FIELD_CASE: - case Doctrine::ATTR_IDXNAME_FORMAT: - case Doctrine::ATTR_SEQNAME_FORMAT: - case Doctrine::ATTR_DBNAME_FORMAT: - case Doctrine::ATTR_TBLCLASS_FORMAT: - case Doctrine::ATTR_TBLNAME_FORMAT: - case Doctrine::ATTR_EXPORT: - case Doctrine::ATTR_DECIMAL_PLACES: - case Doctrine::ATTR_PORTABILITY: - case Doctrine::ATTR_VALIDATE: - case Doctrine::ATTR_QUERY_LIMIT: - case Doctrine::ATTR_DEFAULT_TABLE_TYPE: - case Doctrine::ATTR_DEF_TEXT_LENGTH: - case Doctrine::ATTR_DEF_VARCHAR_LENGTH: - case Doctrine::ATTR_DEF_TABLESPACE: - case Doctrine::ATTR_EMULATE_DATABASE: - case Doctrine::ATTR_USE_NATIVE_ENUM: - case Doctrine::ATTR_CREATE_TABLES: - case Doctrine::ATTR_COLL_LIMIT: - case Doctrine::ATTR_CACHE: // deprecated - case Doctrine::ATTR_RESULT_CACHE: - case Doctrine::ATTR_CACHE_LIFESPAN: // deprecated - case Doctrine::ATTR_RESULT_CACHE_LIFESPAN: - case Doctrine::ATTR_LOAD_REFERENCES: - case Doctrine::ATTR_THROW_EXCEPTIONS: - case Doctrine::ATTR_QUERY_CACHE: - case Doctrine::ATTR_QUERY_CACHE_LIFESPAN: - case Doctrine::ATTR_MODEL_LOADING: - case Doctrine::ATTR_METADATA_CACHE: - case Doctrine::ATTR_METADATA_CACHE_LIFESPAN: - return true; - default: - return false; - } + return false; + } + + public function setAttribute($name, $value) {} + public function getAttribute($name) { + if ($name == Doctrine::ATTR_MODEL_LOADING) { + return Doctrine::MODEL_LOADING_CONSERVATIVE; + } } /** diff --git a/lib/Doctrine/Migration.php b/lib/Doctrine/Migration.php index 54cb0955c..5733e21d6 100644 --- a/lib/Doctrine/Migration.php +++ b/lib/Doctrine/Migration.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::Migration; + /** * Doctrine_Migration * @@ -29,6 +31,7 @@ * @since 1.0 * @version $Revision: 1080 $ * @author Jonathan H. Wage + * @todo Move to "Doctrine Migration" package. Separate download. */ class Doctrine_Migration { diff --git a/lib/Doctrine/Null.php b/lib/Doctrine/Null.php index 0b6ecb7c0..b2f5f0e0b 100644 --- a/lib/Doctrine/Null.php +++ b/lib/Doctrine/Null.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM::Internal; /** * Null class representing a null value that has been fetched from diff --git a/lib/Doctrine/Relation/ForeignKey.php b/lib/Doctrine/Relation/ForeignKey.php index 1ffc0f55c..0da32cd80 100644 --- a/lib/Doctrine/Relation/ForeignKey.php +++ b/lib/Doctrine/Relation/ForeignKey.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Relation'); + /** * Doctrine_Relation_ForeignKey * This class represents a foreign key relation diff --git a/lib/Doctrine/Search.php b/lib/Doctrine/Search.php index fe524c7d1..b74a0faf0 100644 --- a/lib/Doctrine/Search.php +++ b/lib/Doctrine/Search.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::Search; /** * Doctrine_Search diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php index d9a77e4c7..144dec405 100644 --- a/lib/Doctrine/Transaction.php +++ b/lib/Doctrine/Transaction.php @@ -18,7 +18,9 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + +#namespace Doctrine::DBAL::Transactions; + /** * Doctrine_Transaction * Handles transaction savepoint and isolation abstraction diff --git a/lib/Doctrine/Util.php b/lib/Doctrine/Util.php index 305e21b3f..29e02422b 100644 --- a/lib/Doctrine/Util.php +++ b/lib/Doctrine/Util.php @@ -18,7 +18,7 @@ * and is licensed under the LGPL. For more information, see * . */ -Doctrine::autoload('Doctrine_Connection_Module'); + /** * Doctrine_Util * @@ -28,7 +28,8 @@ Doctrine::autoload('Doctrine_Connection_Module'); * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ - * @author Konsta Vesterinen + * @author Konsta Vesterinen + * @todo Remove? */ class Doctrine_Util extends Doctrine_Connection_Module { } \ No newline at end of file diff --git a/lib/Doctrine/Validator.php b/lib/Doctrine/Validator.php index 4a342d143..d043c1da7 100644 --- a/lib/Doctrine/Validator.php +++ b/lib/Doctrine/Validator.php @@ -19,6 +19,8 @@ * . */ +#namespace Doctrine::Validator; + /** * Doctrine_Validator * Doctrine_Validator performs validations on record properties diff --git a/lib/Doctrine/View.php b/lib/Doctrine/View.php index 66824e3e0..e59217d5b 100644 --- a/lib/Doctrine/View.php +++ b/lib/Doctrine/View.php @@ -18,6 +18,8 @@ * and is licensed under the LGPL. For more information, see * . */ + +#namespace Doctrine::ORM::?; /** * Doctrine_View @@ -30,7 +32,8 @@ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link www.phpdoctrine.org * @since 1.0 - * @version $Revision$ + * @version $Revision$ + * @todo Maybe needs a reworked implementation and a new place. */ class Doctrine_View { diff --git a/tests/Orm/Hydration/BasicHydrationTest.php b/tests/Orm/Hydration/BasicHydrationTest.php index 96958193e..475bf3f27 100644 --- a/tests/Orm/Hydration/BasicHydrationTest.php +++ b/tests/Orm/Hydration/BasicHydrationTest.php @@ -1,4 +1,7 @@