PHP Class Doctrine\ODM\PHPCR\UnitOfWork

Since: 1.0
Author: Jordi Boggiano ([email protected])
Author: Pascal Helfenstein ([email protected])
Author: Lukas Kahwe Smith ([email protected])
Author: Brian King ([email protected])
Author: David Buchmann ([email protected])
Author: Daniel Barsotti ([email protected])
Show file Open project: doctrine/phpcr-odm Class Usage Examples

Public Methods

Method Description
__construct ( Doctrine\ODM\PHPCR\DocumentManagerInterface $dm )
bindTranslation ( object $document, string $locale ) Bind the translatable fields of the document in the specified locale.
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.
clear ( ) Clears the UnitOfWork.
commit ( object | array | null $document = null ) Commits the UnitOfWork
computeChangeSet ( ClassMetadata $class, object $document ) Computes changeset for a given document.
computeChangeSets ( ) Detects the changes that need to be persisted
computeSingleDocumentChangeSet ( object $document ) Detects the changes for a single document
contains ( object | string $document ) : boolean
createAssoc ( array $properties, array $mapping ) : array Create an associative array form the properties stored with the node
detach ( object $document ) Detaches a document from the persistence management. It's persistence will no longer be managed by Doctrine.
determineDocumentId ( object $document, ClassMetadata $metadata = null ) : string | null Try to determine the document id first by looking into the document, but if not mapped, look into the document id cache.
doLoadTranslation ( object $document, ClassMetadata $metadata, string $locale = null, boolean $fallback = false, boolean $refresh = false ) Load the translatable fields of the document.
findVersionByName ( $className, $id, $versionName )
getAllLinearVersions ( object $document, integer $limit ) : array Get the version history information for a document
getCurrentLocale ( object $document, ClassMetadata $metadata = null ) : string | null Determine the current locale of a managed document.
getDocumentById ( string $id ) : object | false Tries to find a document with the given id in the identity map of this UnitOfWork.
getDocumentId ( object | string $document, $throw = true ) : string | null Get the object ID for the given document
getDocumentState ( object $document ) : integer Get the state of this document
getLocalesFor ( object $document ) : array Get all locales in which this document currently exists in storage.
getOrCreateDocument ( null | string $className, PHPCR\NodeInterface $node, array &$hints = [] ) : object Get the existing document or proxy of the specified class and node data or create a new one if not existing.
getOrCreateDocuments ( null | string $className, Iterato\Iterator | array $nodes, array &$hints = [] ) : array Get the existing document or proxy of the specified class and node data or create a new one if not existing.
getOrCreateProxy ( string $targetId, string $className, string $locale = null ) : object Get the existing document or proxy for this id of this class, or create a new one.
getOrCreateProxyFromNode ( PHPCR\NodeInterface $node, string $locale = null ) : object Get the existing document or proxy or create a new one for this PHPCR Node
getPrefetchHelper ( )
getScheduledInserts ( ) : array Gets the currently scheduled document insertions in this UnitOfWork.
getScheduledMoves ( ) : array Gets the currently scheduled document moves in this UnitOfWork.
getScheduledRemovals ( ) : array Gets the currently scheduled document deletions in this UnitOfWork.
getScheduledReorders ( ) : array Gets the currently scheduled document reorders in this UnitOfWork.
getScheduledUpdates ( ) : array Gets the currently scheduled document updates in this UnitOfWork.
initializeObject ( $obj ) Helper method to initialize a lazy loading proxy or persistent collection.
invokeGlobalEvent ( $eventName, Doctrine\Common\EventArgs $event ) To invoke a global invent without using the ListenersInvoker.
isDocumentTranslatable ( ClassMetadata $metadata ) : boolean Determine whether this document is translatable.
isScheduledForInsert ( object $document ) : boolean Checks whether a document is scheduled for insertion.
merge ( $document )
persistNew ( ClassMetadata $class, object $document, $overrideIdGenerator = null, $parent = null ) Persist new document, marking it managed and generating the id and the node.
processAssoc ( PHPCR\NodeInterface $node, array $mapping, array $assoc ) : array Process null values in an associative array so that they can be stored in phpcr.
refresh ( $document )
refreshDocumentForProxy ( string $className, Doctrine\Common\Proxy\Proxy $document ) Populate the proxy with actual data
registerDocument ( object $document, string $id ) : string
removeAssoc ( PHPCR\NodeInterface $node, array $mapping ) Remove an associative array form the properties stored with the node
removeTranslation ( object $document, string $locale )
removeVersion ( string $documentVersion ) Delete an old version of a document
restoreVersion ( string $documentVersion, boolean $removeExisting ) Restore the document to the state it was before
scheduleInsert ( object $document ) Schedule insertion of this document and cascade if necessary.
scheduleMove ( $document, $targetPath )
scheduleRemove ( $document )
scheduleReorder ( $document, $srcName, $targetName, $before )
setFetchDepth ( integer | null $fetchDepth = null ) : integer Sets the fetch depth on the session if the PHPCR session instance supports it and returns the previous fetch depth value
setPrefetchHelper ( $helper )
validateClassName ( object $document, string | null $className ) Validate if a document is of the specified class, if the global setting to validate is activated.

Protected Methods

Method Description
doLoadDatabaseTranslation ( object $document, ClassMetadata $metadata, string $locale, boolean $fallback, boolean $refresh ) : string Attempt to load translation from the database.
doLoadPendingTranslation ( object $document, ClassMetadata $metadata, string $locale ) : boolean Load an in-memory bound translation if there is one in the requested locale. Does not attempt any fallback.

Private Methods

Method Description
cascadeDetach ( ClassMetadata $class, object $document, array &$visited ) Cascades a detach operation to associated documents.
cascadeDoLoadTranslation ( object $document, array $mapping, string $locale )
cascadeMerge ( ClassMetadata $class, object $document, object $managedCopy, array &$visited ) Cascades a merge operation to associated entities.
cascadeMergeCollection ( $managedCol, array $mapping )
cascadeRefresh ( ClassMetadata $class, $document, &$visited )
cascadeRemove ( ClassMetadata $class, $document, &$visited )
cascadeScheduleInsert ( ClassMetadata $class, object $document, array &$visited )
cascadeScheduleParentInsert ( $class, $document, &$visited )
computeAssociationChanges ( object $document, string $class, string $oid, boolean $isNew, array $changeSet, string $assocType )
computeChildChanges ( array $mapping, mixed $child, string $parentId, string $nodename, mixed $parent = null ) : object Computes the changes of a child.
computeChildrenChanges ( object $document, string $class, string $oid, boolean $isNew, array $changeSet )
computeReferenceChanges ( array $mapping, mixed $reference ) Computes the changes of a reference.
computeReferrerChanges ( array $mapping, mixed $referrer ) Computes the changes of a referrer.
doBindTranslation ( object $document, string $locale, ClassMetadata $class )
doDetach ( object $document, array &$visited ) Executes a detach operation on the given document.
doMerge ( $document, array &$visited, $prevManagedCopy = null, $assoc = null )
doMergeSingleDocumentProperty ( $managedCopy, $document, ReflectionProperty $prop, array $mapping )
doRefresh ( $document, &$visited )
doRemove ( $document, &$visited )
doRemoveAllTranslations ( object $document, ClassMetadata $metadata )
doSaveTranslation ( $document, PHPCR\NodeInterface $node, $metadata )
doScheduleInsert ( $document, &$visited, $overrideIdGenerator = null )
executeInserts ( array $documents ) Executes all document insertions
executeMoves ( array $documents ) Executes all document moves
executeRemovals ( array $documents ) Executes all document removals
executeReorders ( $documents ) Execute reorderings
executeUpdates ( array $documents, boolean $dispatchEvents = true ) Executes all document updates
generateUuid ( ) : string
getChildNodename ( string $parentId, string $nodename, object $child, object $parent ) : mixed | string Determine the nodename of a child in a children list.
getDocumentActualData ( ClassMetadata $class, object $document ) : array Get a documents actual data, flattening all the objects to arrays.
getIdGenerator ( string $type ) : Doctrine\ODM\PHPCR\Id\IdGenerator
getReferenceManyCollectionTypeFromMetadata ( $referenceFieldMetadata ) : string Extracts ReferenceManyCollection type from field metadata
getVersionedNodePath ( $document )
isAutocreatedProperty ( ClassMetadata $class, string $fieldName ) : boolean Identify whether a PHPCR property is autocreated or not.
isTranslationRemoved ( object $document, string $locale ) : boolean Checks if the translation was removed Note it also returns true if the document isn't translated or was not translated into the given locale, ie.
objToStr ( $obj, Doctrine\ODM\PHPCR\DocumentManagerInterface $dm = null )
purgeChildren ( object $document ) recurse over all known child documents to remove them form this unit of work as their parent gets removed from phpcr. If you do not, flush will try to create orphaned nodes if these documents are modified which leads to a PHPCR exception
setDocumentState ( object | string $document, integer $state )
setLocale ( object $document, ClassMetadata $metadata, string $locale )
setMixins ( ClassMetadata $metadata, PHPCR\NodeInterface $node, object $document ) Set the mapped mixins.
unregisterDocument ( object $document ) Removes a document from the identity map. This effectively detaches the document from the persistence management of Doctrine.
validateChildClass ( PHPCR\NodeInterface $parentNode, ClassMetadata $class ) If the parent node has child restrictions, ensure that the given class name is within them.

Method Details

__construct() public method

public __construct ( Doctrine\ODM\PHPCR\DocumentManagerInterface $dm )
$dm Doctrine\ODM\PHPCR\DocumentManagerInterface

bindTranslation() public method

This method will update the field mapped to Locale if it does not match the $locale argument.
public bindTranslation ( object $document, string $locale )
$document object the document to persist a translation of
$locale string the locale this document currently has

checkin() public method

Checkin operation - Save all current changes and then check in the Node by id.
public checkin ( $document )

checkout() public method

Check out operation - Save all current changes and then check out the Node by path.
public checkout ( $document )

checkpoint() public method

Create a version of the document and check it out right again to continue editing.
public checkpoint ( $document )

clear() public method

Clears the UnitOfWork.
public clear ( )

commit() public method

Commits the UnitOfWork
public commit ( object | array | null $document = null )
$document object | array | null optionally limit to a specific document or an array of documents

computeChangeSet() public method

Computes changeset for a given document.
public computeChangeSet ( ClassMetadata $class, object $document )
$class Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$document object

computeChangeSets() public method

Detects the changes that need to be persisted
public computeChangeSets ( )

computeSingleDocumentChangeSet() public method

Detects the changes for a single document
public computeSingleDocumentChangeSet ( object $document )
$document object

contains() public method

public contains ( object | string $document ) : boolean
$document object | string document instance or document object hash
return boolean

createAssoc() public method

Create an associative array form the properties stored with the node
public createAssoc ( array $properties, array $mapping ) : array
$properties array the node's properties
$mapping array the field's mapping information
return array

detach() public method

Detaches a document from the persistence management. It's persistence will no longer be managed by Doctrine.
public detach ( object $document )
$document object The document to detach.

determineDocumentId() public method

Try to determine the document id first by looking into the document, but if not mapped, look into the document id cache.
public determineDocumentId ( object $document, ClassMetadata $metadata = null ) : string | null
$document object
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata
return string | null the current or stored id, or null if nothing can be found.

doLoadDatabaseTranslation() protected method

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.
See also: doLoadTranslation
protected doLoadDatabaseTranslation ( object $document, ClassMetadata $metadata, string $locale, boolean $fallback, boolean $refresh ) : string
$document object
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$locale string The desired locale.
$fallback boolean Whether to perform language fallback.
$refresh boolean Whether to force reloading the translation.
return string The locale used

doLoadPendingTranslation() protected method

Load an in-memory bound translation if there is one in the requested locale. Does not attempt any fallback.
See also: doLoadTranslation
protected doLoadPendingTranslation ( object $document, ClassMetadata $metadata, string $locale ) : boolean
$document object
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$locale string
return boolean whether the pending translation in language $locale was loaded or not.

doLoadTranslation() public method

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.
public doLoadTranslation ( object $document, ClassMetadata $metadata, string $locale = null, boolean $fallback = false, boolean $refresh = false )
$document object
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$locale string The locale to use or null if the default locale should be used
$fallback boolean Whether to do try other languages
$refresh boolean

findVersionByName() public method

See also: DocumentManager::findVersionByName
public findVersionByName ( $className, $id, $versionName )

getAllLinearVersions() public method

TODO: implement labels once jackalope implements them, until then labels will be an empty array. TODO: implement limit
public getAllLinearVersions ( object $document, integer $limit ) : array
$document object the document of which to get the version history
$limit integer an optional limit to only get the latest $limit information
return array of => array("name" => , "labels" => , "created" => ) oldest version first

getCurrentLocale() public method

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.
public getCurrentLocale ( object $document, ClassMetadata $metadata = null ) : string | null
$document object the managed document to get the locale for
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata document metadata, optional
return string | null the current locale of $document or null if it is not translatable

getDocumentById() public method

Tries to find a document with the given id in the identity map of this UnitOfWork.
public getDocumentById ( string $id ) : object | false
$id string The document id to look for.
return object | false Returns the document with the specified id if it exists in this UnitOfWork, FALSE otherwise.

getDocumentId() public method

Get the object ID for the given document
public getDocumentId ( object | string $document, $throw = true ) : string | null
$document object | string document instance or document object hash
return string | null

getDocumentState() public method

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
public getDocumentState ( object $document ) : integer
$document object the document to get the state of
return integer one of the STATE_* constants of this class

getLocalesFor() public method

Get all locales in which this document currently exists in storage.
public getLocalesFor ( object $document ) : array
$document object A managed document
return array list of locales of this document

getOrCreateDocument() public method

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.)
public getOrCreateDocument ( null | string $className, PHPCR\NodeInterface $node, array &$hints = [] ) : object
$className null | string
$node PHPCR\NodeInterface
$hints array
return object

getOrCreateDocuments() public method

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.)
public getOrCreateDocuments ( null | string $className, Iterato\Iterator | array $nodes, array &$hints = [] ) : array
$className null | string
$nodes Iterato\Iterator | array
$hints array
return array

getOrCreateProxy() public method

Get the existing document or proxy for this id of this class, or create a new one.
public getOrCreateProxy ( string $targetId, string $className, string $locale = null ) : object
$targetId string
$className string
$locale string
return object

getOrCreateProxyFromNode() public method

Get the existing document or proxy or create a new one for this PHPCR Node
public getOrCreateProxyFromNode ( PHPCR\NodeInterface $node, string $locale = null ) : object
$node PHPCR\NodeInterface
$locale string
return object

getPrefetchHelper() public method

public getPrefetchHelper ( )

getScheduledInserts() public method

Gets the currently scheduled document insertions in this UnitOfWork.
public getScheduledInserts ( ) : array
return array

getScheduledMoves() public method

Gets the currently scheduled document moves in this UnitOfWork.
public getScheduledMoves ( ) : array
return array

getScheduledRemovals() public method

Gets the currently scheduled document deletions in this UnitOfWork.
public getScheduledRemovals ( ) : array
return array

getScheduledReorders() public method

Gets the currently scheduled document reorders in this UnitOfWork.
public getScheduledReorders ( ) : array
return array

getScheduledUpdates() public method

Gets the currently scheduled document updates in this UnitOfWork.
public getScheduledUpdates ( ) : array
return array

initializeObject() public method

Helper method to initialize a lazy loading proxy or persistent collection.
public initializeObject ( $obj )

invokeGlobalEvent() public method

To invoke a global invent without using the ListenersInvoker.
public invokeGlobalEvent ( $eventName, Doctrine\Common\EventArgs $event )
$eventName
$event Doctrine\Common\EventArgs

isDocumentTranslatable() public method

To be translatable, it needs a translation strategy and have at least one translated field.
public isDocumentTranslatable ( ClassMetadata $metadata ) : boolean
$metadata Doctrine\ODM\PHPCR\Mapping\ClassMetadata the document meta data
return boolean

isScheduledForInsert() public method

Checks whether a document is scheduled for insertion.
public isScheduledForInsert ( object $document ) : boolean
$document object
return boolean

merge() public method

public merge ( $document )

persistNew() public method

This method is either called through DocumentManager#persist() or during DocumentManager#flush(), when persistence by reachability is applied.
public persistNew ( ClassMetadata $class, object $document, $overrideIdGenerator = null, $parent = null )
$class Doctrine\ODM\PHPCR\Mapping\ClassMetadata
$document object

processAssoc() public method

Stores keys and null fields in the node and returns the processed values
public processAssoc ( PHPCR\NodeInterface $node, array $mapping, array $assoc ) : array
$node PHPCR\NodeInterface the node where to store the assoc array
$mapping array the field's mapping
$assoc array the associative array
return array

refresh() public method

public refresh ( $document )

refreshDocumentForProxy() public method

Populate the proxy with actual data
public refreshDocumentForProxy ( string $className, Doctrine\Common\Proxy\Proxy $document )
$className string
$document Doctrine\Common\Proxy\Proxy

registerDocument() public method

public registerDocument ( object $document, string $id ) : string
$document object
$id string The document id to look for.
return string generated object hash

removeAssoc() public method

Remove an associative array form the properties stored with the node
public removeAssoc ( PHPCR\NodeInterface $node, array $mapping )
$node PHPCR\NodeInterface the node where to store the assoc array
$mapping array the field's mapping

removeTranslation() public method

public removeTranslation ( object $document, string $locale )
$document object
$locale string

removeVersion() public method

Delete an old version of a document
public removeVersion ( string $documentVersion )
$documentVersion string the version name

restoreVersion() public method

Restore the document to the state it was before
See also: VersionManager::restore
public restoreVersion ( string $documentVersion, boolean $removeExisting )
$documentVersion string the version name to restore
$removeExisting boolean how to handle identifier collisions

scheduleInsert() public method

Schedule insertion of this document and cascade if necessary.
public scheduleInsert ( object $document )
$document object

scheduleMove() public method

public scheduleMove ( $document, $targetPath )

scheduleRemove() public method

public scheduleRemove ( $document )

scheduleReorder() public method

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

setFetchDepth() public method

Sets the fetch depth on the session if the PHPCR session instance supports it and returns the previous fetch depth value
public setFetchDepth ( integer | null $fetchDepth = null ) : integer
$fetchDepth integer | null
return integer previous fetch depth value

setPrefetchHelper() public method

public setPrefetchHelper ( $helper )

validateClassName() public method

Validate if a document is of the specified class, if the global setting to validate is activated.
public validateClassName ( object $document, string | null $className )
$document object
$className string | null The class name $document must be instanceof. Pass empty to not validate anything.