class UnitOfWork (View source)

Unit of work class.

Constants

STATE_NEW

STATE_MANAGED

STATE_REMOVED

STATE_DETACHED

STATE_FROZEN

Used for versions of documents (these are unmodifiable frozen nodes).

Methods

setPrefetchHelper($helper)

No description

getPrefetchHelper()

No description

validateClassName(object $document, string|null $className)

Validate if a document is of the specified class, if the global setting to validate is activated.

object
getOrCreateDocument(null|string $className, NodeInterface $node, array $hints = [])

Get the existing document or proxy of the specified class and node data or create a new one if not existing.

array
getOrCreateDocuments(null|string $className, Iterator|array $nodes, array $hints = [])

Get the existing document or proxy of the specified class and node data or create a new one if not existing.

object
getOrCreateProxyFromNode(NodeInterface $node, string $locale = null)

Get the existing document or proxy or create a new one for this PHPCR Node.

object
getOrCreateProxy(string $targetId, string $className, string $locale = null)

Get the existing document or proxy for this id of this class, or create a new one.

refreshDocumentForProxy(string $className, Proxy $document)

Populate the proxy with actual data.

bindTranslation(object $document, string $locale)

Bind the translatable fields of the document in the specified locale.

scheduleInsert(object $document)

Schedule insertion of this document and cascade if necessary.

scheduleMove($document, $targetPath)

No description

scheduleReorder($document, $srcName, $targetName, $before)

No description

scheduleRemove($document)

No description

int
getDocumentState(object $document)

Get the state of this document.

bool
isScheduledForInsert(object $document)

Checks whether a document is scheduled for insertion.

computeSingleDocumentChangeSet(object $document)

Detects the changes for a single document.

computeChangeSets()

Detects the changes that need to be persisted.

computeChangeSet(ClassMetadata $class, object $document)

Computes changeset for a given document.

persistNew(ClassMetadata $class, $document, $overrideIdGenerator = null, $parent = null)

Persist new document, marking it managed and generating the id and the node.

refresh($document)

No description

merge($document)

No description

detach(object $document)

Detaches a document from the persistence management. It's persistence will no longer be managed by Doctrine.

commit(object|array|null $document = null)

Commits the UnitOfWork.

findVersionByName($className, $id, $versionName)

No description

checkin($document)

Checkin operation - Save all current changes and then check in the Node by id.

checkout($document)

Check out operation - Save all current changes and then check out the Node by path.

checkpoint($document)

Create a version of the document and check it out right again to continue editing.

array
getAllLinearVersions(object $document, int $limit = -1)

Get the version history information for a document.

restoreVersion(string $documentVersion, bool $removeExisting)

Restore the document to the state it was before.

removeVersion(string $documentVersion)

Delete an old version of a document.

string
registerDocument(object $document, string $id)

No description

bool
contains(object|string $document)

No description

object|false
getDocumentById($id)

Tries to find a document with the given id in the identity map of this UnitOfWork.

string|null
getDocumentId($document, $throw = true)

Get the object ID for the given document.

string|null
determineDocumentId(object $document, ClassMetadata $metadata = null)

Try to determine the document id first by looking into the document, but if not mapped, look into the document id cache.

initializeObject(object $obj)

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

clear()

Clears the UnitOfWork.

array
getLocalesFor(object $document)

Get all locales in which this document currently exists in storage.

bool
doLoadPendingTranslation(object $document, ClassMetadata $metadata, string $locale)

Load an in-memory bound translation if there is one in the requested locale. Does not attempt any fallback.

string
doLoadDatabaseTranslation(object $document, ClassMetadata $metadata, string $locale, bool $fallback, bool $refresh)

Attempt to load translation from the database.

doLoadTranslation(object $document, ClassMetadata $metadata, string $locale = null, bool $fallback = false, bool $refresh = false)

Load the translatable fields of the document.

removeTranslation(object $document, string $locale)

No description

string|null
getCurrentLocale(object $document, ClassMetadata $metadata = null)

Determine the current locale of a managed document.

bool
isDocumentTranslatable(ClassMetadata $metadata)

Determine whether this document is translatable.

int
setFetchDepth(int|null $fetchDepth = null)

Sets the fetch depth on the session if the PHPCR session instance supports it and returns the previous fetch depth value.

array
getScheduledUpdates()

Gets the currently scheduled document updates in this UnitOfWork.

array
getScheduledInserts()

Gets the currently scheduled document insertions in this UnitOfWork.

array
getScheduledMoves()

Gets the currently scheduled document moves in this UnitOfWork.

array
getScheduledReorders()

Gets the currently scheduled document reorders in this UnitOfWork.

array
getScheduledRemovals()

Gets the currently scheduled document deletions in this UnitOfWork.

array
processAssoc(NodeInterface $node, array $mapping, array $assoc)

Process null values in an associative array so that they can be stored in phpcr.

array
createAssoc(array $properties, array $mapping)

Create an associative array form the properties stored with the node.

removeAssoc(NodeInterface $node, array $mapping)

Remove an associative array form the properties stored with the node.

invokeGlobalEvent($eventName, EventArgs $event)

To invoke a global invent without using the ListenersInvoker.

Details

__construct(DocumentManagerInterface $dm)

Parameters

DocumentManagerInterface $dm

setPrefetchHelper($helper)

Parameters

$helper

getPrefetchHelper()

validateClassName(object $document, string|null $className)

Validate if a document is of the specified class, if the global setting to validate is activated.

Parameters

object $document
string|null $className The class name $document must be instanceof. Pass empty to not validate anything.

Exceptions

PHPCRException

object getOrCreateDocument(null|string $className, NodeInterface $node, array $hints = [])

Get the existing document or proxy of the specified class and node data or create a new one if not existing.

Supported hints are - refresh: reload the fields from the database if set - locale: use this locale instead of the one from the annotation or the default - fallback: whether to try other languages or throw a not found exception if the desired locale is not found. defaults to true if not set and locale is not given either. - prefetch: if set to false, do not attempt to prefetch related data. (This makes sense when the caller already did this beforehand.)

Parameters

null|string $className
NodeInterface $node
array $hints

Return Value

object

Exceptions

PHPCRExceptionInterface if $className was specified and does not match the class of the document corresponding to $node.

array getOrCreateDocuments(null|string $className, Iterator|array $nodes, array $hints = [])

Get the existing document or proxy of the specified class and node data or create a new one if not existing.

Supported hints are - refresh: reload the fields from the database if set - locale: use this locale instead of the one from the annotation or the default - fallback: whether to try other languages or throw a not found exception if the desired locale is not found. defaults to true if not set and locale is not given either. - prefetch: if set to false, do not attempt to prefetch related data. (This makes sense when the caller already did this beforehand.)

Parameters

null|string $className
Iterator|array $nodes
array $hints

Return Value

array

Exceptions

InvalidArgumentException
PHPCRException

object getOrCreateProxyFromNode(NodeInterface $node, string $locale = null)

Get the existing document or proxy or create a new one for this PHPCR Node.

Parameters

NodeInterface $node
string $locale

Return Value

object

object getOrCreateProxy(string $targetId, string $className, string $locale = null)

Get the existing document or proxy for this id of this class, or create a new one.

Parameters

string $targetId
string $className
string $locale

Return Value

object

refreshDocumentForProxy(string $className, Proxy $document)

Populate the proxy with actual data.

Parameters

string $className
Proxy $document

bindTranslation(object $document, string $locale)

Bind the translatable fields of the document in the specified locale.

This method will update the field mapped to Locale if it does not match the $locale argument.

Parameters

object $document the document to persist a translation of
string $locale the locale this document currently has

Exceptions

PHPCRException if the document is not translatable

scheduleInsert(object $document)

Schedule insertion of this document and cascade if necessary.

Parameters

object $document

scheduleMove($document, $targetPath)

Parameters

$document
$targetPath

scheduleReorder($document, $srcName, $targetName, $before)

Parameters

$document
$srcName
$targetName
$before

scheduleRemove($document)

Parameters

$document

int getDocumentState(object $document)

Get the state of this document.

STATE_NEW: the document is not persisted, but a valid mapped document STATE_MANAGED: the document is tracked and will be updated on flush STATE_REMOVED: the document is scheduled for removal STATE_DETACHED: there is a corresponding Node in storage, but this document is not bound to it

Parameters

object $document the document to get the state of

Return Value

int one of the STATE_* constants of this class

bool isScheduledForInsert(object $document)

Checks whether a document is scheduled for insertion.

Parameters

object $document

Return Value

bool

computeSingleDocumentChangeSet(object $document)

Detects the changes for a single document.

Parameters

object $document

computeChangeSets()

Detects the changes that need to be persisted.

computeChangeSet(ClassMetadata $class, object $document)

Computes changeset for a given document.

Parameters

ClassMetadata $class
object $document

persistNew(ClassMetadata $class, $document, $overrideIdGenerator = null, $parent = null)

Persist new document, marking it managed and generating the id and the node.

This method is either called through DocumentManager#persist() or during DocumentManager#flush(), when persistence by reachability is applied.

Parameters

ClassMetadata $class
$document
$overrideIdGenerator
$parent

refresh($document)

Parameters

$document

merge($document)

Parameters

$document

detach(object $document)

Detaches a document from the persistence management. It's persistence will no longer be managed by Doctrine.

Parameters

object $document The document to detach.

commit(object|array|null $document = null)

Commits the UnitOfWork.

Parameters

object|array|null $document optionally limit to a specific document or an array of documents

findVersionByName($className, $id, $versionName)

Parameters

$className
$id
$versionName

See also

DocumentManager::findVersionByName

checkin($document)

Checkin operation - Save all current changes and then check in the Node by id.

Parameters

$document

checkout($document)

Check out operation - Save all current changes and then check out the Node by path.

Parameters

$document

checkpoint($document)

Create a version of the document and check it out right again to continue editing.

Parameters

$document

array getAllLinearVersions(object $document, int $limit = -1)

Get the version history information for a document.

TODO: implement labels once jackalope implements them, until then labels will be an empty array. TODO: implement limit

Parameters

object $document the document of which to get the version history
int $limit an optional limit to only get the latest $limit information

Return Value

array of => array("name" => , "labels" => , "created" => ) oldest version first

restoreVersion(string $documentVersion, bool $removeExisting)

Restore the document to the state it was before.

Parameters

string $documentVersion the version name to restore
bool $removeExisting how to handle identifier collisions

See also

VersionManager::restore

removeVersion(string $documentVersion)

Delete an old version of a document.

Parameters

string $documentVersion the version name

string registerDocument(object $document, string $id)

Parameters

object $document
string $id The document id to look for.

Return Value

string generated object hash

bool contains(object|string $document)

Parameters

object|string $document document instance or document object hash

Return Value

bool

object|false getDocumentById($id)

Tries to find a document with the given id in the identity map of this UnitOfWork.

Parameters

$id

Return Value

object|false Returns the document with the specified id if it exists in this UnitOfWork, FALSE otherwise.

string|null getDocumentId($document, $throw = true)

Get the object ID for the given document.

Parameters

$document
$throw

Return Value

string|null

Exceptions

PHPCRException

string|null determineDocumentId(object $document, ClassMetadata $metadata = null)

Try to determine the document id first by looking into the document, but if not mapped, look into the document id cache.

Parameters

object $document
ClassMetadata $metadata

Return Value

string|null the current or stored id, or null if nothing can be found.

initializeObject(object $obj)

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

Parameters

object $obj

clear()

Clears the UnitOfWork.

array getLocalesFor(object $document)

Get all locales in which this document currently exists in storage.

Parameters

object $document A managed document

Return Value

array list of locales of this document

Exceptions

MissingTranslationException if this document is not translatable

protected bool doLoadPendingTranslation(object $document, ClassMetadata $metadata, string $locale)

Load an in-memory bound translation if there is one in the requested locale. Does not attempt any fallback.

Parameters

object $document
ClassMetadata $metadata
string $locale

Return Value

bool whether the pending translation in language $locale was loaded or not.

See also

doLoadTranslation

protected string doLoadDatabaseTranslation(object $document, ClassMetadata $metadata, string $locale, bool $fallback, bool $refresh)

Attempt to load translation from the database.

If $fallback is true, goes over the locales as provided by the locale chooser strategy to find the best language, each time first checking for a pending translation. If no translation is found at all, the translated fields are set to null and the requested locale is considered to be the one found.

Parameters

object $document
ClassMetadata $metadata
string $locale The desired locale.
bool $fallback Whether to perform language fallback.
bool $refresh Whether to force reloading the translation.

Return Value

string The locale used

Exceptions

MissingTranslationException if the translation in $locale is not found and $fallback is false.

See also

doLoadTranslation

doLoadTranslation(object $document, ClassMetadata $metadata, string $locale = null, bool $fallback = false, bool $refresh = false)

Load the translatable fields of the document.

If locale is not set then the current locale of the document is reloaded, resetting possible changes.

If the document is not translatable, this method returns immediately and without error.

Parameters

object $document
ClassMetadata $metadata
string $locale The locale to use or null if the default locale should be used
bool $fallback Whether to do try other languages
bool $refresh

Exceptions

MissingTranslationException if the translation in $locale is not found and $fallback is false.

removeTranslation(object $document, string $locale)

Parameters

object $document
string $locale

Exceptions

MissingTranslationException
PHPCRException

string|null getCurrentLocale(object $document, ClassMetadata $metadata = null)

Determine the current locale of a managed document.

If the document is not translatable, null is returned.

If the document is translatable and the locale is mapped onto a document field, the value of that field is returned. Otherwise the UnitOfWork information on locales for documents without a locale mapping is consulted.

If nothing matches (for example when this is a detached document), the default locale of the LocaleChooserStrategy is returned.

Parameters

object $document the managed document to get the locale for
ClassMetadata $metadata document metadata, optional

Return Value

string|null the current locale of $document or null if it is not translatable

bool isDocumentTranslatable(ClassMetadata $metadata)

Determine whether this document is translatable.

To be translatable, it needs a translation strategy and have at least one translated field.

Parameters

ClassMetadata $metadata the document meta data

Return Value

bool

int setFetchDepth(int|null $fetchDepth = null)

Sets the fetch depth on the session if the PHPCR session instance supports it and returns the previous fetch depth value.

Parameters

int|null $fetchDepth

Return Value

int previous fetch depth value

array getScheduledUpdates()

Gets the currently scheduled document updates in this UnitOfWork.

Return Value

array

array getScheduledInserts()

Gets the currently scheduled document insertions in this UnitOfWork.

Return Value

array

array getScheduledMoves()

Gets the currently scheduled document moves in this UnitOfWork.

Return Value

array

array getScheduledReorders()

Gets the currently scheduled document reorders in this UnitOfWork.

Return Value

array

array getScheduledRemovals()

Gets the currently scheduled document deletions in this UnitOfWork.

Return Value

array

array processAssoc(NodeInterface $node, array $mapping, array $assoc)

Process null values in an associative array so that they can be stored in phpcr.

Stores keys and null fields in the node and returns the processed values

Parameters

NodeInterface $node the node where to store the assoc array
array $mapping the field's mapping
array $assoc the associative array

Return Value

array

array createAssoc(array $properties, array $mapping)

Create an associative array form the properties stored with the node.

Parameters

array $properties the node's properties
array $mapping the field's mapping information

Return Value

array

removeAssoc(NodeInterface $node, array $mapping)

Remove an associative array form the properties stored with the node.

Parameters

NodeInterface $node the node where to store the assoc array
array $mapping the field's mapping

invokeGlobalEvent($eventName, EventArgs $event)

To invoke a global invent without using the ListenersInvoker.

Parameters

$eventName
EventArgs $event