EntityManagerInterface
extends
ObjectManager
in
EntityManager interface
Table of Contents
- beginTransaction() : void
- Starts a transaction on the underlying database connection.
- clear() : void
- Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.
- close() : void
- 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() : void
- Commits a transaction on the underlying database connection.
- contains() : bool
- Checks if the object is part of the current UnitOfWork and therefore managed.
- copy() : object
- Creates a copy of the given entity. Can create a shallow or a deep copy.
- createNamedNativeQuery() : NativeQuery
- Creates a NativeQuery from a named native query.
- createNamedQuery() : Query
- Creates a Query from a named query.
- createNativeQuery() : NativeQuery
- Creates a native SQL query.
- createQuery() : Query
- Creates a new Query object.
- createQueryBuilder() : QueryBuilder
- Create a QueryBuilder instance
- detach() : void
- Detaches an object from the ObjectManager, causing a managed object to become detached. Unflushed changes made to the object if any (including removal of the object), will not be synchronized to the database.
- find() : object|null
- Finds an object by its identifier.
- flush() : void
- Flushes all changes to objects that have been queued up to now to the database.
- getCache() : Cache|null
- Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
- getClassMetadata() : ClassMetadata
- Returns the ClassMetadata descriptor for a class.
- getConfiguration() : Configuration
- Gets the Configuration used by the EntityManager.
- getConnection() : Connection
- Gets the database connection object used by the EntityManager.
- getEventManager() : EventManager
- Gets the EventManager used by the EntityManager.
- getExpressionBuilder() : Expr
- Gets an ExpressionBuilder used for object-oriented construction of query expressions.
- getFilters() : FilterCollection
- Gets the enabled filters.
- getHydrator() : AbstractHydrator
- Gets a hydrator for the given hydration mode.
- getMetadataFactory() : ClassMetadataFactory
- Gets the metadata factory used to gather the metadata of classes.
- getPartialReference() : object|null
- 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() : ProxyFactory
- Gets the proxy factory used by the EntityManager to create entity proxies.
- getReference() : object|null
- 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() : ObjectRepository
- Gets the repository for a class.
- getUnitOfWork() : UnitOfWork
- Gets the UnitOfWork used by the EntityManager to coordinate operations.
- hasFilters() : bool
- Checks whether the Entity Manager has filters.
- initializeObject() : void
- Helper method to initialize a lazy loading proxy or persistent collection.
- isFiltersStateClean() : bool
- Checks whether the state of the filter collection is clean.
- isOpen() : bool
- Check if the Entity manager is open or closed.
- lock() : void
- Acquire a lock on the given entity.
- merge() : object
- Merges the state of a detached object into the persistence context of this ObjectManager and returns the managed copy of the object.
- newHydrator() : AbstractHydrator
- Create a new instance for the given hydration mode.
- persist() : void
- Tells the ObjectManager to make an instance managed and persistent.
- refresh() : void
- Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.
- remove() : void
- Removes an object instance.
- rollback() : void
- Performs a rollback on the underlying database connection.
- transactional() : mixed
- Executes a function in a transaction.
Methods
beginTransaction()
Starts a transaction on the underlying database connection.
public
beginTransaction() : void
Return values
void —clear()
Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.
public
clear([string|null $objectName = null ]) : void
Parameters
- $objectName : string|null = null
-
if given, only objects of this type will get detached.
Return values
void —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.
public
close() : void
Return values
void —commit()
Commits a transaction on the underlying database connection.
public
commit() : void
Return values
void —contains()
Checks if the object is part of the current UnitOfWork and therefore managed.
public
contains(object $object) : bool
Parameters
- $object : object
Return values
bool —copy()
Creates a copy of the given entity. Can create a shallow or a deep copy.
public
copy(object $entity[, bool $deep = false ]) : object
Parameters
- $entity : object
-
The entity to copy.
- $deep : bool = false
-
FALSE for a shallow copy, TRUE for a deep copy.
Tags
Return values
object —The new entity.
createNamedNativeQuery()
Creates a NativeQuery from a named native query.
public
createNamedNativeQuery(string $name) : NativeQuery
Parameters
- $name : string
Return values
NativeQuery —createNamedQuery()
Creates a Query from a named query.
public
createNamedQuery(string $name) : Query
Parameters
- $name : string
Return values
Query —createNativeQuery()
Creates a native SQL query.
public
createNativeQuery(string $sql, ResultSetMapping $rsm) : NativeQuery
Parameters
- $sql : string
- $rsm : ResultSetMapping
-
The ResultSetMapping to use.
Return values
NativeQuery —createQuery()
Creates a new Query object.
public
createQuery([string $dql = '' ]) : Query
Parameters
- $dql : string = ''
-
The DQL string.
Return values
Query —createQueryBuilder()
Create a QueryBuilder instance
public
createQueryBuilder() : QueryBuilder
Return values
QueryBuilder —detach()
Detaches an object from the ObjectManager, causing a managed object to become detached. Unflushed changes made to the object if any (including removal of the object), will not be synchronized to the database.
public
detach(object $object) : void
Objects which previously referenced the detached object will continue to reference it.
Parameters
- $object : object
-
The object to detach.
Return values
void —find()
Finds an object by its identifier.
public
find(string $className, mixed $id) : object|null
This is just a convenient shortcut for getRepository($className)->find($id).
Parameters
- $className : string
-
The class name of the object to find.
- $id : mixed
-
The identity of the object to find.
Tags
Return values
object|null —The found object.
flush()
Flushes all changes to objects that have been queued up to now to the database.
public
flush() : void
This effectively synchronizes the in-memory state of managed objects with the database.
Return values
void —getCache()
Returns the cache API for managing the second level cache regions or NULL if the cache is not enabled.
public
getCache() : Cache|null
Return values
Cache|null —getClassMetadata()
Returns the ClassMetadata descriptor for a class.
public
getClassMetadata(mixed $className) : ClassMetadata
Parameters
- $className : mixed
Tags
Return values
ClassMetadata —getConfiguration()
Gets the Configuration used by the EntityManager.
public
getConfiguration() : Configuration
Return values
Configuration —getConnection()
Gets the database connection object used by the EntityManager.
public
getConnection() : Connection
Return values
Connection —getEventManager()
Gets the EventManager used by the EntityManager.
public
getEventManager() : EventManager
Return values
EventManager —getExpressionBuilder()
Gets an ExpressionBuilder used for object-oriented construction of query expressions.
public
getExpressionBuilder() : Expr
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)));
Return values
Expr —getFilters()
Gets the enabled filters.
public
getFilters() : FilterCollection
Return values
FilterCollection —The active filter collection.
getHydrator()
Gets a hydrator for the given hydration mode.
public
getHydrator(string|int $hydrationMode) : AbstractHydrator
This method caches the hydrator instances which is used for all queries that don't selectively iterate over the result.
Parameters
- $hydrationMode : string|int
Tags
Return values
AbstractHydrator —getMetadataFactory()
Gets the metadata factory used to gather the metadata of classes.
public
getMetadataFactory() : ClassMetadataFactory
Tags
Return values
ClassMetadataFactory —getPartialReference()
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.
public
getPartialReference(string $entityName, mixed $identifier) : object|null
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.
Parameters
- $entityName : string
-
The name of the entity type.
- $identifier : mixed
-
The entity identifier.
Tags
Return values
object|null —The (partial) entity reference
getProxyFactory()
Gets the proxy factory used by the EntityManager to create entity proxies.
public
getProxyFactory() : ProxyFactory
Return values
ProxyFactory —getReference()
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 $id) : object|null
Parameters
- $entityName : string
-
The name of the entity type.
- $id : mixed
-
The entity identifier.
Tags
Return values
object|null —The entity reference.
getRepository()
Gets the repository for a class.
public
getRepository(mixed $className) : ObjectRepository
Parameters
- $className : mixed
Tags
Return values
ObjectRepository —getUnitOfWork()
Gets the UnitOfWork used by the EntityManager to coordinate operations.
public
getUnitOfWork() : UnitOfWork
Return values
UnitOfWork —hasFilters()
Checks whether the Entity Manager has filters.
public
hasFilters() : bool
Return values
bool —True, if the EM has a filter collection.
initializeObject()
Helper method to initialize a lazy loading proxy or persistent collection.
public
initializeObject(object $obj) : void
This method is a no-op for other objects.
Parameters
- $obj : object
Return values
void —isFiltersStateClean()
Checks whether the state of the filter collection is clean.
public
isFiltersStateClean() : bool
Return values
bool —True, if the filter collection is clean.
isOpen()
Check if the Entity manager is open or closed.
public
isOpen() : bool
Return values
bool —lock()
Acquire a lock on the given entity.
public
lock(object $entity, int $lockMode[, int|DateTimeInterface|null $lockVersion = null ]) : void
Parameters
- $entity : object
- $lockMode : int
- $lockVersion : int|DateTimeInterface|null = null
Tags
Return values
void —merge()
Merges the state of a detached object into the persistence context of this ObjectManager and returns the managed copy of the object.
public
merge(object $object) : object
The object passed to merge will not become associated/managed with this ObjectManager.
Parameters
- $object : object
Tags
Return values
object —newHydrator()
Create a new instance for the given hydration mode.
public
newHydrator(string|int $hydrationMode) : AbstractHydrator
Parameters
- $hydrationMode : string|int
Tags
Return values
AbstractHydrator —persist()
Tells the ObjectManager to make an instance managed and persistent.
public
persist(object $object) : void
The object will be entered into the database as a result of the flush operation.
NOTE: The persist operation always considers objects that are not yet known to this ObjectManager as NEW. Do not pass detached objects to the persist operation.
Parameters
- $object : object
-
The instance to make managed and persistent.
Return values
void —refresh()
Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.
public
refresh(object $object) : void
Parameters
- $object : object
-
The object to refresh.
Return values
void —remove()
Removes an object instance.
public
remove(object $object) : void
A removed object will be removed from the database as a result of the flush operation.
Parameters
- $object : object
-
The object instance to remove.
Return values
void —rollback()
Performs a rollback on the underlying database connection.
public
rollback() : void
Return values
void —transactional()
Executes a function in a transaction.
public
transactional(callable $func) : mixed
The function gets passed this EntityManager instance as an (optional) parameter.
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.
Parameters
- $func : callable
-
The function to execute transactionally.
Tags
Return values
mixed —The non-empty value returned from the closure or true instead.