interface ObjectManager (View source)

Contract for a Doctrine persistence layer ObjectManager class to implement.

Methods

object
find(string $className, mixed $id)

Finds an object by its identifier.

void
persist(object $object)

Tells the ObjectManager to make an instance managed and persistent.

void
remove(object $object)

Removes an object instance.

object
merge(object $object)

Merges the state of a detached object into the persistence context of this ObjectManager and returns the managed copy of the object.

void
clear(string|null $objectName = null)

Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.

void
detach(object $object)

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.

void
refresh(object $object)

Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.

void
flush()

Flushes all changes to objects that have been queued up to now to the database.

getRepository(string $className)

Gets the repository for a class.

getClassMetadata(string $className)

Returns the ClassMetadata descriptor for a class.

getMetadataFactory()

Gets the metadata factory used to gather the metadata of classes.

void
initializeObject(object $obj)

Helper method to initialize a lazy loading proxy or persistent collection.

bool
contains(object $object)

Checks if the object is part of the current UnitOfWork and therefore managed.

Details

object find(string $className, mixed $id)

Finds an object by its identifier.

This is just a convenient shortcut for getRepository($className)->find($id).

Parameters

string $className The class name of the object to find.
mixed $id The identity of the object to find.

Return Value

object The found object.

void persist(object $object)

Tells the ObjectManager to make an instance managed and persistent.

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 Value

void

void remove(object $object)

Removes an object instance.

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 Value

void

object merge(object $object)

Merges the state of a detached object into the persistence context of this ObjectManager and returns the managed copy of the object.

The object passed to merge will not become associated/managed with this ObjectManager.

Parameters

object $object

Return Value

object

void clear(string|null $objectName = null)

Clears the ObjectManager. All objects that are currently managed by this ObjectManager become detached.

Parameters

string|null $objectName if given, only objects of this type will get detached.

Return Value

void

void detach(object $object)

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.

Objects which previously referenced the detached object will continue to reference it.

Parameters

object $object The object to detach.

Return Value

void

void refresh(object $object)

Refreshes the persistent state of an object from the database, overriding any local changes that have not yet been persisted.

Parameters

object $object The object to refresh.

Return Value

void

void flush()

Flushes all changes to objects that have been queued up to now to the database.

This effectively synchronizes the in-memory state of managed objects with the database.

Return Value

void

ObjectRepository getRepository(string $className)

Gets the repository for a class.

Parameters

string $className

Return Value

ObjectRepository

ClassMetadata getClassMetadata(string $className)

Returns the ClassMetadata descriptor for a class.

The class name must be the fully-qualified class name without a leading backslash (as it is returned by get_class($obj)).

Parameters

string $className

Return Value

ClassMetadata

ClassMetadataFactory getMetadataFactory()

Gets the metadata factory used to gather the metadata of classes.

Return Value

ClassMetadataFactory

void initializeObject(object $obj)

Helper method to initialize a lazy loading proxy or persistent collection.

This method is a no-op for other objects.

Parameters

object $obj

Return Value

void

bool contains(object $object)

Checks if the object is part of the current UnitOfWork and therefore managed.

Parameters

object $object

Return Value

bool