PHP Class Doctrine\ORM\EntityManager

Since: 2.0
Author: Roman Borschel ([email protected])
Show file Open project: pmjones/php-framework-benchmarks Class Usage Examples

Public Methods

Method Description
beginTransaction ( ) Starts a transaction on the underlying database connection.
clear ( string $entityName = null ) Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.
close ( ) Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.
commit ( ) Commits a transaction on the underlying database connection.
contains ( object $entity ) : boolean Determines whether an entity instance is managed in this EntityManager.
copy ( object $entity, $deep = false ) : object Creates a copy of the given entity. Can create a shallow or a deep copy.
create ( mixed $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager = null ) : EntityManager Factory method to create EntityManager instances.
createNamedNativeQuery ( string $name ) : Doctrine\ORM\NativeQuery Creates a NativeQuery from a named native query.
createNamedQuery ( string $name ) : Doctrine\ORM\Query Creates a Query from a named query.
createNativeQuery ( string $sql, Doctrine\ORM\Query\ResultSetMapping $rsm ) : Doctrine\ORM\NativeQuery Creates a native SQL query.
createQuery ( $dql = "" ) : Doctrine\ORM\Query Creates a new Query object.
createQueryBuilder ( ) : Doctrine\ORM\QueryBuilder Create a QueryBuilder instance
detach ( object $entity ) Detaches an entity from the EntityManager, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database.
find ( string $entityName, mixed $identifier, integer $lockMode = LockMode::NONE, integer $lockVersion = null ) : object Finds an Entity by its identifier.
flush ( ) Flushes all changes to objects that have been queued up to now to the database.
getClassMetadata ( $className ) : Doctrine\ORM\Mapping\ClassMetadata Returns the ORM metadata descriptor for a class.
getConfiguration ( ) : Doctrine\ORM\Configuration Gets the Configuration used by the EntityManager.
getConnection ( ) : Doctrine\DBAL\Connection Gets the database connection object used by the EntityManager.
getEventManager ( ) : Doctrine\Common\EventManager Gets the EventManager used by the EntityManager.
getExpressionBuilder ( ) : ExpressionBuilder Gets an ExpressionBuilder used for object-oriented construction of query expressions.
getHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator Gets a hydrator for the given hydration mode.
getMetadataFactory ( ) : Doctrine\ORM\Mapping\ClassMetadataFactory Gets the metadata factory used to gather the metadata of classes.
getPartialReference ( string $entityName, mixed $identifier ) : object Gets a partial reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.
getProxyFactory ( ) : Doctrine\ORM\Proxy\ProxyFactory Gets the proxy factory used by the EntityManager to create entity proxies.
getReference ( string $entityName, mixed $identifier ) : object Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.
getRepository ( string $entityName ) : Doctrine\ORM\EntityRepository Gets the repository for an entity class.
getUnitOfWork ( ) : Doctrine\ORM\UnitOfWork Gets the UnitOfWork used by the EntityManager to coordinate operations.
lock ( object $entity, integer $lockMode, integer $lockVersion = null ) Acquire a lock on the given entity.
merge ( object $entity ) : object Merges the state of a detached entity into the persistence context of this EntityManager and returns the managed copy of the entity.
newHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator Create a new instance for the given hydration mode.
persist ( $entity ) Tells the EntityManager to make an instance managed and persistent.
refresh ( object $entity ) Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted.
remove ( object $entity ) Removes an entity instance.
rollback ( ) Performs a rollback on the underlying database connection.
transactional ( Closur\Closure $func ) Executes a function in a transaction.

Protected Methods

Method Description
__construct ( Doctrine\DBAL\Connection $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager ) Creates a new EntityManager that operates on the given database connection and uses the given Configuration and EventManager implementations.

Private Methods

Method Description
errorIfClosed ( ) Throws an exception if the EntityManager is closed or currently not active.

Method Details

__construct() protected method

Creates a new EntityManager that operates on the given database connection and uses the given Configuration and EventManager implementations.
protected __construct ( Doctrine\DBAL\Connection $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager )
$conn Doctrine\DBAL\Connection
$config Doctrine\ORM\Configuration
$eventManager Doctrine\Common\EventManager

beginTransaction() public method

Starts a transaction on the underlying database connection.
Deprecation: Use {@link getConnection}.beginTransaction().
public beginTransaction ( )

clear() public method

Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.
public clear ( string $entityName = null )
$entityName string

close() public method

Closes the EntityManager. All entities that are currently managed by this EntityManager become detached. The EntityManager may no longer be used after it is closed.
public close ( )

commit() public method

Commits a transaction on the underlying database connection.
Deprecation: Use {@link getConnection}.commit().
public commit ( )

contains() public method

Determines whether an entity instance is managed in this EntityManager.
public contains ( object $entity ) : boolean
$entity object
return boolean TRUE if this EntityManager currently manages the given entity, FALSE otherwise.

copy() public method

Creates a copy of the given entity. Can create a shallow or a deep copy.
public copy ( object $entity, $deep = false ) : object
$entity object The entity to copy.
return object The new entity.

create() public static method

Factory method to create EntityManager instances.
public static create ( mixed $conn, Doctrine\ORM\Configuration $config, Doctrine\Common\EventManager $eventManager = null ) : EntityManager
$conn mixed An array with the connection parameters or an existing Connection instance.
$config Doctrine\ORM\Configuration The Configuration instance to use.
$eventManager Doctrine\Common\EventManager The EventManager instance to use.
return EntityManager The created EntityManager.

createNamedNativeQuery() public method

Creates a NativeQuery from a named native query.
public createNamedNativeQuery ( string $name ) : Doctrine\ORM\NativeQuery
$name string
return Doctrine\ORM\NativeQuery

createNamedQuery() public method

Creates a Query from a named query.
public createNamedQuery ( string $name ) : Doctrine\ORM\Query
$name string
return Doctrine\ORM\Query

createNativeQuery() public method

Creates a native SQL query.
public createNativeQuery ( string $sql, Doctrine\ORM\Query\ResultSetMapping $rsm ) : Doctrine\ORM\NativeQuery
$sql string
$rsm Doctrine\ORM\Query\ResultSetMapping The ResultSetMapping to use.
return Doctrine\ORM\NativeQuery

createQuery() public method

Creates a new Query object.
public createQuery ( $dql = "" ) : Doctrine\ORM\Query
return Doctrine\ORM\Query

createQueryBuilder() public method

Create a QueryBuilder instance
public createQueryBuilder ( ) : Doctrine\ORM\QueryBuilder
return Doctrine\ORM\QueryBuilder $qb

detach() public method

Entities which previously referenced the detached entity will continue to reference it.
public detach ( object $entity )
$entity object The entity to detach.

find() public method

This is just a convenient shortcut for getRepository($entityName)->find($id).
public find ( string $entityName, mixed $identifier, integer $lockMode = LockMode::NONE, integer $lockVersion = null ) : object
$entityName string
$identifier mixed
$lockMode integer
$lockVersion integer
return object

flush() public method

This effectively synchronizes the in-memory state of managed objects with the database.
public flush ( )

getClassMetadata() public method

The class name must be the fully-qualified class name without a leading backslash (as it is returned by get_class($obj)) or an aliased class name. Examples: MyProject\Domain\User sales:PriceRequest
public getClassMetadata ( $className ) : Doctrine\ORM\Mapping\ClassMetadata
return Doctrine\ORM\Mapping\ClassMetadata

getConfiguration() public method

Gets the Configuration used by the EntityManager.
public getConfiguration ( ) : Doctrine\ORM\Configuration
return Doctrine\ORM\Configuration

getConnection() public method

Gets the database connection object used by the EntityManager.
public getConnection ( ) : Doctrine\DBAL\Connection
return Doctrine\DBAL\Connection

getEventManager() public method

Gets the EventManager used by the EntityManager.
public getEventManager ( ) : Doctrine\Common\EventManager
return Doctrine\Common\EventManager

getExpressionBuilder() public method

Example: $qb = $em->createQueryBuilder(); $expr = $em->getExpressionBuilder(); $qb->select('u')->from('User', 'u') ->where($expr->orX($expr->eq('u.id', 1), $expr->eq('u.id', 2)));
public getExpressionBuilder ( ) : ExpressionBuilder
return ExpressionBuilder

getHydrator() public method

This method caches the hydrator instances which is used for all queries that don't selectively iterate over the result.
public getHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator
$hydrationMode integer
return Doctrine\ORM\Internal\Hydration\AbstractHydrator

getMetadataFactory() public method

Gets the metadata factory used to gather the metadata of classes.
public getMetadataFactory ( ) : Doctrine\ORM\Mapping\ClassMetadataFactory
return Doctrine\ORM\Mapping\ClassMetadataFactory

getPartialReference() public method

The returned reference may be a partial object if the entity is not yet loaded/managed. If it is a partial object it will not initialize the rest of the entity state on access. Thus you can only ever safely access the identifier of an entity obtained through this method. The use-cases for partial references involve maintaining bidirectional associations without loading one side of the association or to update an entity without loading it. Note, however, that in the latter case the original (persistent) entity data will never be visible to the application (especially not event listeners) as it will never be loaded in the first place.
public getPartialReference ( string $entityName, mixed $identifier ) : object
$entityName string The name of the entity type.
$identifier mixed The entity identifier.
return object The (partial) entity reference.

getProxyFactory() public method

Gets the proxy factory used by the EntityManager to create entity proxies.
public getProxyFactory ( ) : Doctrine\ORM\Proxy\ProxyFactory
return Doctrine\ORM\Proxy\ProxyFactory

getReference() public method

Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded.
public getReference ( string $entityName, mixed $identifier ) : object
$entityName string The name of the entity type.
$identifier mixed The entity identifier.
return object The entity reference.

getRepository() public method

Gets the repository for an entity class.
public getRepository ( string $entityName ) : Doctrine\ORM\EntityRepository
$entityName string The name of the entity.
return Doctrine\ORM\EntityRepository The repository class.

getUnitOfWork() public method

Gets the UnitOfWork used by the EntityManager to coordinate operations.
public getUnitOfWork ( ) : Doctrine\ORM\UnitOfWork
return Doctrine\ORM\UnitOfWork

lock() public method

Acquire a lock on the given entity.
public lock ( object $entity, integer $lockMode, integer $lockVersion = null )
$entity object
$lockMode integer
$lockVersion integer

merge() public method

The entity passed to merge will not become associated/managed with this EntityManager.
public merge ( object $entity ) : object
$entity object The detached entity to merge into the persistence context.
return object The managed copy of the entity.

newHydrator() public method

Create a new instance for the given hydration mode.
public newHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator
$hydrationMode integer
return Doctrine\ORM\Internal\Hydration\AbstractHydrator

persist() public method

The entity will be entered into the database at or before transaction commit or as a result of the flush operation. NOTE: The persist operation always considers entities that are not yet known to this EntityManager as NEW. Do not pass detached entities to the persist operation.
public persist ( $entity )

refresh() public method

Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been persisted.
public refresh ( object $entity )
$entity object The entity to refresh.

remove() public method

A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
public remove ( object $entity )
$entity object The entity instance to remove.

rollback() public method

Performs a rollback on the underlying database connection.
Deprecation: Use {@link getConnection}.rollback().
public rollback ( )

transactional() public method

The function gets passed this EntityManager instance as an (optional) parameter. {@link flush} is invoked prior to transaction commit. If an exception occurs during execution of the function or flushing or transaction commit, the transaction is rolled back, the EntityManager closed and the exception re-thrown.
public transactional ( Closur\Closure $func )
$func Closur\Closure The function to execute transactionally.