PHP Класс Doctrine\ORM\EntityManager

С версии: 2.0
Автор: Roman Borschel ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
__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.

Приватные методы

Метод Описание
errorIfClosed ( ) Throws an exception if the EntityManager is closed or currently not active.

Описание методов

__construct() защищенный Метод

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() публичный Метод

Starts a transaction on the underlying database connection.
Устаревший: Use {@link getConnection}.beginTransaction().
public beginTransaction ( )

clear() публичный Метод

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

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 ( )

commit() публичный Метод

Commits a transaction on the underlying database connection.
Устаревший: Use {@link getConnection}.commit().
public commit ( )

contains() публичный Метод

Determines whether an entity instance is managed in this EntityManager.
public contains ( object $entity ) : boolean
$entity object
Результат boolean TRUE if this EntityManager currently manages the given entity, FALSE otherwise.

copy() публичный Метод

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.
Результат object The new entity.

create() публичный статический Метод

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.
Результат EntityManager The created EntityManager.

createNamedNativeQuery() публичный Метод

Creates a NativeQuery from a named native query.
public createNamedNativeQuery ( string $name ) : Doctrine\ORM\NativeQuery
$name string
Результат Doctrine\ORM\NativeQuery

createNamedQuery() публичный Метод

Creates a Query from a named query.
public createNamedQuery ( string $name ) : Doctrine\ORM\Query
$name string
Результат Doctrine\ORM\Query

createNativeQuery() публичный Метод

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.
Результат Doctrine\ORM\NativeQuery

createQuery() публичный Метод

Creates a new Query object.
public createQuery ( $dql = "" ) : Doctrine\ORM\Query
Результат Doctrine\ORM\Query

createQueryBuilder() публичный Метод

Create a QueryBuilder instance
public createQueryBuilder ( ) : Doctrine\ORM\QueryBuilder
Результат Doctrine\ORM\QueryBuilder $qb

detach() публичный Метод

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

find() публичный Метод

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
Результат object

flush() публичный Метод

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

getClassMetadata() публичный Метод

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
Результат Doctrine\ORM\Mapping\ClassMetadata

getConfiguration() публичный Метод

Gets the Configuration used by the EntityManager.
public getConfiguration ( ) : Doctrine\ORM\Configuration
Результат Doctrine\ORM\Configuration

getConnection() публичный Метод

Gets the database connection object used by the EntityManager.
public getConnection ( ) : Doctrine\DBAL\Connection
Результат Doctrine\DBAL\Connection

getEventManager() публичный Метод

Gets the EventManager used by the EntityManager.
public getEventManager ( ) : Doctrine\Common\EventManager
Результат Doctrine\Common\EventManager

getExpressionBuilder() публичный Метод

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
Результат ExpressionBuilder

getHydrator() публичный Метод

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
Результат Doctrine\ORM\Internal\Hydration\AbstractHydrator

getMetadataFactory() публичный Метод

Gets the metadata factory used to gather the metadata of classes.
public getMetadataFactory ( ) : Doctrine\ORM\Mapping\ClassMetadataFactory
Результат Doctrine\ORM\Mapping\ClassMetadataFactory

getPartialReference() публичный Метод

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.
Результат object The (partial) entity reference.

getProxyFactory() публичный Метод

Gets the proxy factory used by the EntityManager to create entity proxies.
public getProxyFactory ( ) : Doctrine\ORM\Proxy\ProxyFactory
Результат Doctrine\ORM\Proxy\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 $identifier ) : object
$entityName string The name of the entity type.
$identifier mixed The entity identifier.
Результат object The entity reference.

getRepository() публичный Метод

Gets the repository for an entity class.
public getRepository ( string $entityName ) : Doctrine\ORM\EntityRepository
$entityName string The name of the entity.
Результат Doctrine\ORM\EntityRepository The repository class.

getUnitOfWork() публичный Метод

Gets the UnitOfWork used by the EntityManager to coordinate operations.
public getUnitOfWork ( ) : Doctrine\ORM\UnitOfWork
Результат Doctrine\ORM\UnitOfWork

lock() публичный Метод

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

merge() публичный Метод

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.
Результат object The managed copy of the entity.

newHydrator() публичный Метод

Create a new instance for the given hydration mode.
public newHydrator ( integer $hydrationMode ) : Doctrine\ORM\Internal\Hydration\AbstractHydrator
$hydrationMode integer
Результат Doctrine\ORM\Internal\Hydration\AbstractHydrator

persist() публичный Метод

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() публичный Метод

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() публичный Метод

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() публичный Метод

Performs a rollback on the underlying database connection.
Устаревший: Use {@link getConnection}.rollback().
public rollback ( )

transactional() публичный Метод

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.