Commit 9dcab5ee authored by romanb's avatar romanb

Small reorganizations, improvements and progress.

parent 2eb4a16d
......@@ -16,60 +16,51 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common\Events;
namespace Doctrine\Common;
/**
* Doctrine_Event
* EventArgs is the base class for classes containing event data.
*
* This class contains no event data and cannot be instantiated.
* It is used by events that do not pass state information to an event handler
* when an event is raised. The single empty EventArgs instance can be obtained
* through {@link getEmptyInstance()}.
*
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
*/
class Event
class EventArgs
{
/* Event callback constants */
const preDelete = 'preDelete';
const postDelete = 'postDelete';
//...more
protected $_type;
protected $_target;
protected $_defaultPrevented;
private static $_emptyEventArgsInstance;
private $_defaultPrevented;
public function __construct($type, $target = null)
protected function __construct()
{
$this->_type = $type;
$this->_target = $target;
$this->_defaultPrevented = false;
}
public function getType()
{
return $this->_type;
}
public function preventDefault()
{
$this->_defaultPrevented = true;
}
public function getDefaultPrevented()
{
return $this->_defaultPrevented;
}
public function getTarget()
public static function getEmptyInstance()
{
return $this->_target;
if ( ! self::$_emptyEventArgsInstance) {
self::$_emptyEventArgsInstance = new EventArgs;
}
return self::$_emptyEventArgsInstance;
}
}
......@@ -16,7 +16,7 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\Common;
......@@ -45,20 +45,20 @@ class EventManager
/**
* Dispatches an event to all registered listeners.
*
* @param string|Event $event The name of the event or the event object.
* @param string $eventName The name of the event to dispatch. The name of the event is
* the name of the method that is invoked on listeners.
* @param EventArgs $eventArgs The event arguments to pass to the event handlers/listeners.
* If not supplied, the single empty EventArgs instance is used.
* @return boolean
*/
public function dispatchEvent($event)
public function dispatchEvent($eventName, EventArgs $eventArgs = null)
{
$argIsCallback = is_string($event);
$callback = $argIsCallback ? $event : $event->getType();
if (isset($this->_listeners[$callback])) {
$event = $argIsCallback ? new Event($event) : $event;
foreach ($this->_listeners[$callback] as $listener) {
$listener->$callback($event);
if (isset($this->_listeners[$eventName])) {
$eventArgs = is_null($eventArgs) ? EventArgs::getEmptyInstance() : $eventArgs;
foreach ($this->_listeners[$eventName] as $listener) {
$listener->$eventName($eventArgs);
}
return ! $event->getDefaultPrevented();
return ! $eventArgs->getDefaultPrevented();
}
return true;
}
......@@ -95,7 +95,7 @@ class EventManager
{
// TODO: maybe check for duplicate registrations?
foreach ((array)$events as $event) {
$this->_listeners[$event] = $listener;
$this->_listeners[$event][] = $listener;
}
}
......@@ -110,4 +110,3 @@ class EventManager
$this->addEventListener($subscriber->getSubscribedEvents(), $subscriber);
}
}
\ No newline at end of file
......@@ -154,9 +154,11 @@ class Connection
* Initializes a new instance of the Connection class.
*
* @param array $params The connection parameters.
* @param Driver $driver
* @param Configuration $config
* @param EventManager $eventManager
*/
public function __construct(array $params, Driver $driver,
Configuration $config = null,
public function __construct(array $params, Driver $driver, Configuration $config = null,
EventManager $eventManager = null)
{
$this->_driver = $driver;
......@@ -182,7 +184,7 @@ class Connection
/**
* Gets the Configuration used by the Connection.
*
* @return Configuration
* @return Doctrine\DBAL\Configuration
*/
public function getConfiguration()
{
......@@ -389,22 +391,22 @@ class Connection
}
/**
* fetchAll
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_ASSOC).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @param string $sql The SQL query.
* @param array $params The query parameters.
* @return array
*/
public function fetchAll($statement, array $params = array())
public function fetchAll($sql, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
return $this->execute($sql, $params)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* fetchOne
* Convenience method for PDO::query("...") followed by $stmt->fetchColumn().
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @param string $statement The SQL query.
* @param array $params The query parameters.
* @param int $colnum 0-indexed column number to retrieve
* @return mixed
*/
......@@ -414,10 +416,10 @@ class Connection
}
/**
* fetchRow
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_ASSOC).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @param string $statement The SQL query.
* @param array $params The query parameters.
* @return array
*/
public function fetchRow($statement, array $params = array())
......@@ -426,7 +428,7 @@ class Connection
}
/**
* fetchArray
* Convenience method for PDO::query("...") followed by $stmt->fetch(PDO::FETCH_NUM).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
......@@ -438,7 +440,7 @@ class Connection
}
/**
* fetchColumn
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_COLUMN, ...).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
......@@ -451,19 +453,7 @@ class Connection
}
/**
* fetchAssoc
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
* @return array
*/
public function fetchAssoc($statement, array $params = array())
{
return $this->execute($statement, $params)->fetchAll(PDO::FETCH_ASSOC);
}
/**
* fetchBoth
* Convenience method for PDO::query("...") followed by $stmt->fetchAll(PDO::FETCH_BOTH).
*
* @param string $statement sql query to be executed
* @param array $params prepared statement params
......@@ -478,7 +468,7 @@ class Connection
* Prepares an SQL statement.
*
* @param string $statement
* @return Doctrine::DBAL::Statement
* @return PDOStatement
*/
public function prepare($statement)
{
......@@ -487,13 +477,13 @@ class Connection
}
/**
* Queries the database with limit and offset
* added to the query and returns a Doctrine_Connection_Statement object
* Queries the database with limit and offset added to the query and returns
* a Statement object.
*
* @param string $query
* @param integer $limit
* @param integer $offset
* @return Doctrine_Connection_Statement
* @return Statement
*/
public function select($query, $limit = 0, $offset = 0)
{
......
......@@ -17,23 +17,21 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM;
/**
* Doctrine_ORM_Query_Abstract
* Base class for Query and NativeQuery.
*
* @package Doctrine
* @subpackage Query
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.com
* @link www.doctrine-project.com
* @since 1.0
* @version $Revision: 1393 $
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @todo See {@link Doctrine_ORM_Query}
* @author Roman Borschel <roman@code-factory.org>
*/
abstract class AbstractQuery
{
......@@ -101,7 +99,7 @@ abstract class AbstractQuery
/**
* @var integer $type Query type.
*
* @see Doctrine_ORM_Query::* constants
* @see Query::* constants
*/
protected $_type = self::SELECT;
......@@ -112,19 +110,19 @@ abstract class AbstractQuery
/**
* @var array $params Parameters of this query.
* @see Doctrine_ORM_Query::free that initializes this property
* @see Query::free that initializes this property
*/
protected $_params = array();
/**
* @var array $_enumParams Array containing the keys of the parameters that should be enumerated.
* @see Doctrine_ORM_Query::free that initializes this property
* @see Query::free that initializes this property
*/
protected $_enumParams = array();
/**
* @var array $_dqlParts An array containing all DQL query parts.
* @see Doctrine_ORM_Query::free that initializes this property
* @see Query::free that initializes this property
*/
protected $_dqlParts = array();
......
......@@ -24,7 +24,6 @@ namespace Doctrine\ORM;
use Doctrine\Common\EventManager;
use Doctrine\Common\DoctrineException;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Exceptions\EntityManagerException;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\ClassMetadataFactory;
......@@ -90,7 +89,7 @@ class EntityManager
private $_conn;
/**
* The metadata factory, used to retrieve the metadata of entity classes.
* The metadata factory, used to retrieve the ORM metadata of entity classes.
*
* @var Doctrine\ORM\Mapping\ClassMetadataFactory
*/
......@@ -330,7 +329,7 @@ class EntityManager
*/
public function flush()
{
$this->_errorIfNotActiveOrClosed();
$this->_errorIfClosed();
$this->_unitOfWork->commit();
}
......@@ -412,7 +411,7 @@ class EntityManager
*/
public function save($object)
{
$this->_errorIfNotActiveOrClosed();
$this->_errorIfClosed();
$this->_unitOfWork->save($object);
if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) {
$this->flush();
......@@ -426,7 +425,7 @@ class EntityManager
*/
public function delete($entity)
{
$this->_errorIfNotActiveOrClosed();
$this->_errorIfClosed();
$this->_unitOfWork->delete($entity);
if ($this->_flushMode == self::FLUSHMODE_IMMEDIATE) {
$this->flush();
......@@ -459,7 +458,7 @@ class EntityManager
}
/**
* Gets the repository for an Entity.
* Gets the repository for an entity class.
*
* @param string $entityName The name of the Entity.
* @return Doctrine\ORM\EntityRepository The repository.
......@@ -520,7 +519,7 @@ class EntityManager
*
* @throws EntityManagerException If the EntityManager is closed or not active.
*/
private function _errorIfNotActiveOrClosed()
private function _errorIfClosed()
{
if ($this->_closed) {
throw EntityManagerException::notActiveOrClosed($this->_name);
......
......@@ -16,10 +16,10 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ORM\Exceptions;
namespace Doctrine\ORM;
/**
* Doctrine_EntityManager_Exception
......@@ -27,7 +27,7 @@ namespace Doctrine\ORM\Exceptions;
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @link www.doctrine-project.org
* @since 2.0
* @version $Revision$
*/
......
<?php
/*
* $Id: Exception.php 4776 2008-08-16 19:40:59Z romanb $
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
......@@ -16,22 +16,27 @@
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.org>.
* <http://www.doctrine-project.org>.
*/
#namespace Doctrine::ORM::Exceptions;
namespace Doctrine\ORM;
/**
* Doctrine_Exception
* Container for all ORM events.
*
* @package Doctrine
* @subpackage Exception
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @link www.phpdoctrine.org
* @since 1.0
* @version $Revision: 4776 $
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
* @author Roman Borschel <roman@code-factory.org>
* This class cannot be instantiated.
*
* @author robo
* @since 2.0
*/
class Doctrine_ORM_Exceptions_ORMException extends Doctrine_Common_Exceptions_DoctrineException
{}
final class Events
{
private function __construct() {}
const preDelete = 'preDelete';
const postDelete = 'postDelete';
const preSave = 'preSave';
const postSave = 'postSave';
}
<?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>.
*/
#namespace Doctrine::ORM::Exceptions;
/**
* Doctrine_Entity_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
* @link www.phpdoctrine.org
* @since 2.0
* @version $Revision$
*/
class Doctrine_ORM_Exceptions_EntityException extends Doctrine_ORM_Exceptions_ORMException
{
public static function unknownField($field)
{
return new self("Undefined field: '$field'.");
}
public static function invalidValueForOneToManyReference()
{
return new self("Invalid value. The value of a reference in a OneToMany "
. "association must be a Collection.");
}
public static function invalidValueForOneToOneReference()
{
return new self("Invalid value. The value of a reference in a OneToOne "
. "association must be an Entity.");
}
public static function invalidValueForManyToManyReference()
{
return new self("Invalid value. The value of a reference in a ManyToMany "
. "association must be a Collection.");
}
public static function invalidField($field)
{
return new self("Invalid field: '$field'.");
}
}
\ No newline at end of file
<?php
namespace Doctrine\ORM\Exceptions;
namespace Doctrine\ORM\Internal\Hydration;
class HydrationException extends \Doctrine\Common\DoctrineException
{
......
<?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.doctrine-project.org>.
*/
namespace Doctrine\ORM\Internal\Hydration;
use \PDO;
/**
* Description of ObjectHydrator
* The ObjectHydrator constructs an object graph out of an SQL result set.
*
* @author robo
* @since 2.0
*/
class ObjectHydrator extends AbstractHydrator
{
......@@ -64,8 +84,8 @@ class ObjectHydrator extends AbstractHydrator
// Take snapshots from all initialized collections
foreach ($this->_collections as $coll) {
$coll->_takeSnapshot();
$coll->_setHydrationFlag(false);
$coll->takeSnapshot();
$coll->setHydrationFlag(false);
}
// Clean up
......@@ -128,8 +148,8 @@ class ObjectHydrator extends AbstractHydrator
$relation = $classMetadata->getAssociationMapping($name);
$relatedClass = $this->_em->getClassMetadata($relation->getTargetEntityName());
$coll = $this->getCollection($relatedClass->getClassName());
$coll->_setOwner($entity, $relation);
$coll->_setHydrationFlag(true);
$coll->setOwner($entity, $relation);
$coll->setHydrationFlag(true);
$classMetadata->getReflectionProperty($name)->setValue($entity, $coll);
$this->_initializedRelations[$oid][$name] = true;
$this->_uow->setOriginalEntityProperty($oid, $name, $coll);
......
......@@ -7,7 +7,6 @@
namespace Doctrine\ORM\Internal\Hydration;
use \PDO;
use Doctrine\ORM\Exceptions\HydrationException;
/**
* Description of SingleScalarHydrator
......
......@@ -21,8 +21,6 @@
namespace Doctrine\ORM\Mapping;
use Doctrine\ORM\Exceptions\MappingException;
/**
* Base class for association mappings.
*
......
This diff is collapsed.
......@@ -22,7 +22,7 @@
namespace Doctrine\ORM\Mapping\Driver;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Exceptions\MappingException;
use Doctrine\ORM\Mapping\MappingException;
/* Addendum annotation reflection extensions */
if ( ! class_exists('\Addendum', false)) {
......@@ -134,6 +134,7 @@ class AnnotationDriver
$metadata->mapOneToMany($mapping);
} else if ($manyToOneAnnot = $property->getAnnotation('DoctrineManyToOne')) {
$mapping['joinColumns'] = $joinColumns;
$mapping['cascade'] = $manyToOneAnnot->cascade;
$mapping['targetEntity'] = $manyToOneAnnot->targetEntity;
$metadata->mapManyToOne($mapping);
} else if ($manyToManyAnnot = $property->getAnnotation('DoctrineManyToMany')) {
......@@ -150,6 +151,7 @@ class AnnotationDriver
$mapping['joinTable'] = $joinTable;
$mapping['targetEntity'] = $manyToManyAnnot->targetEntity;
$mapping['mappedBy'] = $manyToManyAnnot->mappedBy;
$mapping['cascade'] = $manyToManyAnnot->cascade;
$metadata->mapManyToMany($mapping);
}
......
......@@ -21,8 +21,6 @@
namespace Doctrine\ORM\Mapping;
use Doctrine\ORM\Exceptions\MappingException;
/**
* A many-to-many mapping describes the mapping between two collections of
* entities.
......
......@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.org>.
*/
namespace Doctrine\ORM\Exceptions;
namespace Doctrine\ORM\Mapping;
/**
* A MappingException indicates that something is wrong with the mapping setup.
......
......@@ -21,8 +21,6 @@
namespace Doctrine\ORM\Mapping;
use Doctrine\ORM\Exceptions\MappingException;
/**
* Represents a one-to-many mapping.
*
......@@ -53,7 +51,7 @@ class OneToManyMapping extends AssociationMapping
//protected $_sourceKeysToTargetForeignKeys;
/** Whether to delete orphaned elements (removed from the collection) */
protected $_deleteOrphans = false;
private $_deleteOrphans = false;
/**
* Initializes a new OneToManyMapping.
......@@ -96,9 +94,8 @@ class OneToManyMapping extends AssociationMapping
}
/**
* Whether the association is one-to-many.
* {@inheritdoc}
*
* @return boolean TRUE if the association is one-to-many, FALSE otherwise.
* @override
*/
public function isOneToMany()
......
......@@ -21,8 +21,6 @@
namespace Doctrine\ORM\Mapping;
use Doctrine\ORM\Exceptions\MappingException;
/**
* A one-to-one mapping describes a uni-directional mapping from one entity
* to another entity.
......
......@@ -48,7 +48,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*
* @var string
*/
private $_entityBaseType;
private $_type;
/**
* A snapshot of the collection at the moment it was fetched from the database.
......@@ -99,7 +99,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
* Hydration flag.
*
* @var boolean
* @see _setHydrationFlag()
* @see setHydrationFlag()
*/
private $_hydrationFlag;
......@@ -119,12 +119,12 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
/**
* Creates a new persistent collection.
*/
public function __construct(EntityManager $em, $entityBaseType, array $data = array(), $keyField = null)
public function __construct(EntityManager $em, $type, array $data = array(), $keyField = null)
{
parent::__construct($data);
$this->_entityBaseType = $entityBaseType;
$this->_type = $type;
$this->_em = $em;
$this->_ownerClass = $em->getClassMetadata($entityBaseType);
$this->_ownerClass = $em->getClassMetadata($type);
if ($keyField !== null) {
if ( ! $this->_ownerClass->hasField($keyField)) {
throw new DoctrineException("Invalid field '$keyField' can't be used as key.");
......@@ -162,7 +162,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
* @param object $entity
* @param AssociationMapping $assoc
*/
public function _setOwner($entity, AssociationMapping $assoc)
public function setOwner($entity, AssociationMapping $assoc)
{
$this->_owner = $entity;
$this->_association = $assoc;
......@@ -289,7 +289,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*
* @param boolean $bool
*/
public function _setHydrationFlag($bool)
public function setHydrationFlag($bool)
{
$this->_hydrationFlag = $bool;
}
......@@ -301,9 +301,9 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
* when a fetched collection has three elements, then two of those
* are being removed the diff would contain one element.
*/
public function _takeSnapshot()
public function takeSnapshot()
{
$this->_snapshot = $this->_data;
$this->_snapshot = $this->_elements;
}
/**
......@@ -312,7 +312,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*
* @return array The last snapshot of the elements.
*/
public function _getSnapshot()
public function getSnapshot()
{
return $this->_snapshot;
}
......@@ -325,7 +325,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*/
public function getDeleteDiff()
{
return array_udiff($this->_snapshot, $this->_data, array($this, '_compareRecords'));
return array_udiff($this->_snapshot, $this->_elements, array($this, '_compareRecords'));
}
/**
......@@ -335,7 +335,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*/
public function getInsertDiff()
{
return array_udiff($this->_data, $this->_snapshot, array($this, '_compareRecords'));
return array_udiff($this->_elements, $this->_snapshot, array($this, '_compareRecords'));
}
/**
......
......@@ -66,20 +66,36 @@ abstract class AbstractCollectionPersister
if ($coll->getMapping()->isInverseSide()) {
return; // ignore inverse side
}
$sql = $this->_getDeleteSql($coll);
$this->_conn->exec($sql, $this->_getDeleteSqlParameters($coll));
}
/**
* Gets the SQL statement for deleting the given collection.
*
* @param PersistentCollection $coll
*/
abstract protected function _getDeleteSql(PersistentCollection $coll);
/**
* Gets the SQL parameters for the corresponding SQL statement to delete
* the given collection.
*
* @param PersistentCollection $coll
*/
abstract protected function _getDeleteSqlParameters(PersistentCollection $coll);
/**
* Updates the given collection, synchronizing it's state with the database
* by inserting, updating and deleting individual elements.
*
* @param PersistentCollection $coll
*/
public function update(PersistentCollection $coll)
{
if ($coll->getMapping()->isInverseSide()) {
return; // ignore inverse side
}
$this->deleteRows($coll);
//$this->updateRows($coll);
$this->insertRows($coll);
......@@ -113,6 +129,13 @@ abstract class AbstractCollectionPersister
*/
abstract protected function _getDeleteRowSql(PersistentCollection $coll);
/**
* Gets the SQL parameters for the corresponding SQL statement to delete the given
* element from the given collection.
*
* @param PersistentCollection $coll
* @param mixed $element
*/
abstract protected function _getDeleteRowSqlParameters(PersistentCollection $coll, $element);
/**
......@@ -129,6 +152,13 @@ abstract class AbstractCollectionPersister
*/
abstract protected function _getInsertRowSql(PersistentCollection $coll);
/**
* Gets the SQL parameters for the corresponding SQL statement to insert the given
* element of the given collection into the database.
*
* @param PersistentCollection $coll
* @param mixed $element
*/
abstract protected function _getInsertRowSqlParameters(PersistentCollection $coll, $element);
}
......@@ -21,6 +21,9 @@
namespace Doctrine\ORM\Persisters;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\ClassMetadata;
/**
* Base class for all EntityPersisters.
*
......@@ -65,7 +68,7 @@ abstract class AbstractEntityPersister
* that uses the given EntityManager and persists instances of the class described
* by the given class metadata descriptor.
*/
public function __construct(\Doctrine\ORM\EntityManager $em, \Doctrine\ORM\Mapping\ClassMetadata $classMetadata)
public function __construct(EntityManager $em, ClassMetadata $classMetadata)
{
$this->_em = $em;
$this->_entityName = $classMetadata->getClassName();
......@@ -112,8 +115,10 @@ abstract class AbstractEntityPersister
*/
public function delete($entity)
{
$id = array_combine($this->_classMetadata->getIdentifierFieldNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity));
$id = array_combine(
$this->_classMetadata->getIdentifierFieldNames(),
$this->_em->getUnitOfWork()->getEntityIdentifier($entity)
);
$this->_conn->delete($this->_classMetadata->getTableName(), $id);
}
......@@ -132,7 +137,7 @@ abstract class AbstractEntityPersister
*
* @param string $fieldName
* @return string
* @todo Consider using 'inherited' => 'ClassName' to make the lookup simpler.
* @todo Move to ClassMetadata?
*/
public function getOwningClass($fieldName)
{
......@@ -180,11 +185,9 @@ abstract class AbstractEntityPersister
if ($this->_classMetadata->hasAssociation($field)) {
$assocMapping = $this->_classMetadata->getAssociationMapping($field);
if ( ! $assocMapping->isOneToOne() || $assocMapping->isInverseSide()) {
//echo "NOT TO-ONE OR INVERSE!";
continue;
}
foreach ($assocMapping->getSourceToTargetKeyColumns() as $sourceColumn => $targetColumn) {
//TODO: throw exc if field not set
$otherClass = $this->_em->getClassMetadata($assocMapping->getTargetEntityName());
if (is_null($newVal)) {
$result[$sourceColumn] = null;
......@@ -192,7 +195,6 @@ abstract class AbstractEntityPersister
$result[$sourceColumn] = $otherClass->getReflectionProperty(
$otherClass->getFieldName($targetColumn))->getValue($newVal);
}
}
} else if (is_null($newVal)) {
$result[$columnName] = null;
......
......@@ -65,9 +65,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
* @override
*/
protected function _getUpdateRowSql(PersistentCollection $coll)
{
}
{}
/**
* {@inheritdoc}
......@@ -96,7 +94,7 @@ class ManyToManyPersister extends AbstractCollectionPersister
$this->_uow->getEntityIdentifier($coll->getOwner()),
$this->_uow->getEntityIdentifier($element)
);
var_dump($params);
//var_dump($params);
return $params;
}
......
......@@ -23,7 +23,6 @@
namespace Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST;
use Doctrine\ORM\Exceptions\QueryException;
use Doctrine\ORM\Query\Exec;
/**
......
......@@ -4,7 +4,7 @@
* and open the template in the editor.
*/
namespace Doctrine\ORM\Exceptions;
namespace Doctrine\ORM\Query;
/**
* Description of QueryException
......
This diff is collapsed.
<?php
#namespace Doctrine\ORM;
/*
* $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.doctrine-project.org>.
*/
namespace Doctrine\ORM;
use Doctrine\ORM\Mapping\AssociationMapping;
/**
* Represents a virtual proxy that is used for lazy to-one associations.
......@@ -7,7 +29,7 @@
* @author robo
* @since 2.0
*/
class Doctrine_ORM_VirtualProxy
class VirtualProxy
{
private $_assoc;
private $_refProp;
......@@ -22,7 +44,7 @@ class Doctrine_ORM_VirtualProxy
* @param <type> $assoc
* @param <type> $refProp
*/
public function __construct($owner, Doctrine_ORM_Mapping_AssociationMapping $assoc, ReflectionProperty $refProp)
public function __construct($owner, AssociationMapping $assoc, \ReflectionProperty $refProp)
{
$this->_owner = $owner;
$this->_assoc = $assoc;
......
......@@ -10,9 +10,6 @@ if (!defined('PHPUnit_MAIN_METHOD')) {
require_once __DIR__ . '/../TestInit.php';
// Suites
#require_once 'Common/Collections/AllTests.php';
class AllTests
{
public static function main()
......@@ -24,6 +21,8 @@ class AllTests
{
$suite = new \Doctrine\Tests\DoctrineTestSuite('Doctrine Common Tests');
$suite->addTestSuite('Doctrine\Tests\Common\EventManagerTest');
$suite->addTest(Collections\AllTests::suite());
return $suite;
......
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
namespace Doctrine\Tests\Common;
use Doctrine\Common\EventManager;
use Doctrine\Common\EventArgs;
/**
* Description of EventManagerTest
*
* @author robo
*/
class EventManagerTest extends \Doctrine\Tests\DoctrineTestCase
{
/* Some pseudo events */
const preFoo = 'preFoo';
const postFoo = 'postFoo';
private $_preFooInvoked = false;
private $_postFooInvoked = false;
private $_eventManager;
protected function setUp() {
$this->_eventManager = new EventManager;
$this->_preFooInvoked = false;
$this->_postFooInvoked = false;
}
public function testInitialState()
{
$this->assertEquals(array(), $this->_eventManager->getListeners());
$this->assertFalse($this->_eventManager->hasListeners(self::preFoo));
$this->assertFalse($this->_eventManager->hasListeners(self::postFoo));
}
public function testAddEventListener()
{
$this->_eventManager->addEventListener(array('preFoo', 'postFoo'), $this);
$this->assertTrue($this->_eventManager->hasListeners(self::preFoo));
$this->assertTrue($this->_eventManager->hasListeners(self::postFoo));
$this->assertEquals(1, count($this->_eventManager->getListeners(self::preFoo)));
$this->assertEquals(1, count($this->_eventManager->getListeners(self::postFoo)));
$this->assertEquals(2, count($this->_eventManager->getListeners()));
}
public function testDispatchEvent()
{
$this->_eventManager->addEventListener(array('preFoo', 'postFoo'), $this);
$this->_eventManager->dispatchEvent(self::preFoo);
$this->assertTrue($this->_preFooInvoked);
$this->assertFalse($this->_postFooInvoked);
}
/* Listener methods */
public function preFoo(EventArgs $e)
{
$this->_preFooInvoked = true;
}
public function postFoo(EventArgs $e)
{
$this->_postFooInvoked = true;
}
}
......@@ -39,7 +39,7 @@ class CmsUser
*/
public $address;
/**
* @DoctrineManyToMany(targetEntity="CmsGroup")
* @DoctrineManyToMany(targetEntity="CmsGroup", cascade={"save"})
* @DoctrineJoinTable(name="cms_users_groups",
joinColumns={{"name"="user_id", "referencedColumnName"="id"}},
inverseJoinColumns={{"name"="group_id", "referencedColumnName"="id"}})
......
......@@ -22,7 +22,7 @@ class EntityManagerTest extends \Doctrine\Tests\OrmTestCase
try {
$this->_em->setFlushMode('foobar');
$this->fail("Setting invalid flushmode did not trigger exception.");
} catch (\Doctrine\ORM\Exceptions\EntityManagerException $expected) {}
} catch (\Doctrine\ORM\EntityManagerException $expected) {}
$this->_em->setFlushMode($prev);
}
}
\ No newline at end of file
......@@ -157,6 +157,8 @@ class BasicCRUDTest extends \Doctrine\Tests\OrmFunctionalTestCase {
public function testManyToManyCollectionClearing()
{
echo PHP_EOL . "MANY-MANY" . PHP_EOL;
$user = new CmsUser;
$user->name = 'Guilherme';
$user->username = 'gblanco';
......@@ -171,11 +173,17 @@ class BasicCRUDTest extends \Doctrine\Tests\OrmFunctionalTestCase {
$this->_em->save($user); // Saves the user, cause of post-insert ID
$this->_em->flush(); // Saves the groups, cause they're attached to a persistent entity ($user)
$this->_em->flush();
// Check that there are indeed 10 links in the association table
$count = $this->_em->getConnection()->execute("SELECT COUNT(*) FROM cms_users_groups",
array())->fetchColumn();
$this->assertEquals(10, $count);
//$user->groups->clear();
unset($user->groups);
echo PHP_EOL . "FINAL FLUSH" . PHP_EOL;
$this->_em->flush();
// Check that the links in the association table have been deleted
......
......@@ -89,7 +89,7 @@ class SingleScalarHydratorTest extends HydrationTest
$result = $hydrator->hydrateall($stmt, $this->_createParserResult(
$queryComponents, $tableAliasMap));
$this->fail();
} catch (\Doctrine\ORM\Exceptions\HydrationException $ex) {}
} catch (\Doctrine\ORM\Internal\Hydration\HydrationException $ex) {}
}
}
......
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