Commit 9dcab5ee authored by romanb's avatar romanb

Small reorganizations, improvements and progress.

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