abstract class DocumentManagerDecorator extends ObjectManagerDecorator implements DocumentManagerInterface (View source)

Base class for DocumentManager decorators.

Properties

protected DocumentManagerInterface $wrapped

Methods

__construct(DocumentManagerInterface $wrapped)

No description

setTranslationStrategy(string $key, TranslationStrategyInterface $strategy)

Add or replace a translation strategy.

getTranslationStrategy(string $key)

Get the translation strategy based on the strategy short name.

bool
hasLocaleChooserStrategy()

Check if a language chooser strategy is set.

getLocaleChooserStrategy()

Get the assigned language chooser strategy previously set with setLocaleChooserStrategy.

setLocaleChooserStrategy(LocaleChooserInterface $strategy)

Set the locale chooser strategy for multilanguage documents.

getProxyFactory()

Gets the proxy factory used by the DocumentManager to create document proxies.

EventManager
getEventManager()

No description

SessionInterface
getPhpcrSession()

Access the underlying PHPCR session this manager is using.

getMetadataFactory()

{@inheritdoc}

getConfiguration()

No description

bool
isOpen()

Check if the Document manager is open or closed.

getClassMetadata($className)

{@inheritdoc}

find($className, $id)

{@inheritdoc}

Collection
findMany(null|string $className, array $ids)

Finds many documents by id.

object
findTranslation(null|string $className, string $id, string $locale, bool $fallback = true)

Load the document from the content repository in the given language.

getRepository($className)

{@inheritdoc}

string
quote(string $val, int $type = PropertyType::STRING)

Quote a string for inclusion in an SQL2 query.

string
escapeFullText(string $string)

Escape the illegal characters for inclusion in a fulltext statement. Escape Character is \.

QueryInterface
createPhpcrQuery(string $statement, string $language)

Create a PHPCR Query from a query string in the specified query language to be used with getDocumentsByPhpcrQuery().

createQuery(string $statement, string $language)

Create a ODM Query from a query string in the specified query language to be used with getDocumentsByPhpcrQuery().

createQueryBuilder()

Create the fluent query builder.

createPhpcrQueryBuilder()

Create lower level PHPCR query builder.

array
getDocumentsByPhpcrQuery(QueryInterface $query, string|null $className = null, string|null $primarySelector = null)

Get document results from a PHPCR query instance.

persist($document)

{@inheritdoc}

bindTranslation(object $document, string $locale)

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

removeTranslation(object $document, string $locale)

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

array
getLocalesFor(object $document, bool $includeFallbacks = false)

Get the list of locales that exist for the specified document, including those not yet flushed, but bound.

bool
isDocumentTranslatable(object $document)

Determine whether this document is translatable.

move(object $document, string $targetPath)

Move the previously persisted document and all its children in the tree.

reorder(object $document, string $srcName, string $targetName, bool $before)

Reorder a child of the given document.

remove($document)

{@inheritdoc}

merge($document)

{@inheritdoc}

detach($document)

{@inheritdoc}

refresh($document)

{@inheritdoc}

getChildren(object $document, string|array $filter = null, int $fetchDepth = null, string $locale = null)

Get the child documents of a given document using an optional filter.

getReferrers(object $document, string|null $type = null, string|null $name = null, string $locale = null, string|null $refClass = null)

Get the documents that refer a given document using an optional name.

void
flush(object|array|null $document = null)

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

mixed|object
getReference(string $documentName, string|object $id)

Gets a reference to the document identified by the given type and identifier without actually loading it.

checkin(object $document)

Create a new version of the document that has been previously persisted and flushed.

checkout(object $document)

Make a checked in document writable again.

checkpoint(object $document)

Do a checkin operation followed immediately by a checkout operation.

restoreVersion(string $documentVersion, bool $removeExisting = true)

Restores the current checked out document to the values of the given version in storage and refreshes the document object.

removeVersion(object $documentVersion)

Delete the specified version to clean up the history.

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

Get the version history information for a document.

object
findVersionByName(null|string $className, string $id, string $versionName)

Returns a read-only, detached document instance of the document at the specified path with the specified version name.

contains($document)

{@inheritdoc}

getUnitOfWork()

Client code should not access the UnitOfWork except in special circumstances. Methods on UnitOfWork might be changed without special notice.

clear($className = null)

{@inheritdoc}

close()

Closes the DocumentManager. All entities that are currently managed by this DocumentManager become detached. The DocumentManager may no longer be used after it is closed.

initializeObject($document)

{@inheritdoc}

NodeInterface
getNodeForDocument(object $document)

Return the node of the given object.

string
getDocumentId(object $document)

Get the document identifier phpcr-odm is using.

Details

__construct(DocumentManagerInterface $wrapped)

Parameters

DocumentManagerInterface $wrapped

setTranslationStrategy(string $key, TranslationStrategyInterface $strategy)

Add or replace a translation strategy.

Note that you do not need to set the default strategies attribute and child unless you want to replace them.

Parameters

string $key The name of the translation strategy.
TranslationStrategyInterface $strategy The strategy that is used with this key.

TranslationStrategyInterface getTranslationStrategy(string $key)

Get the translation strategy based on the strategy short name.

Parameters

string $key The name of the translation strategy

Return Value

TranslationStrategyInterface

Exceptions

InvalidArgumentException if there is no strategy registered with the given key

bool hasLocaleChooserStrategy()

Check if a language chooser strategy is set.

Return Value

bool

LocaleChooserInterface getLocaleChooserStrategy()

Get the assigned language chooser strategy previously set with setLocaleChooserStrategy.

Return Value

LocaleChooserInterface

setLocaleChooserStrategy(LocaleChooserInterface $strategy)

Set the locale chooser strategy for multilanguage documents.

Note that there can be only one strategy per session. This is required if you have multilanguage documents and not used if you don't have multilanguage.

Parameters

LocaleChooserInterface $strategy

ProxyFactory getProxyFactory()

Gets the proxy factory used by the DocumentManager to create document proxies.

Return Value

ProxyFactory

EventManager getEventManager()

Return Value

EventManager

SessionInterface getPhpcrSession()

Access the underlying PHPCR session this manager is using.

Return Value

SessionInterface

getMetadataFactory()

{@inheritdoc}

Configuration getConfiguration()

Return Value

Configuration

bool isOpen()

Check if the Document manager is open or closed.

Return Value

bool true if open, false if closed

getClassMetadata($className)

{@inheritdoc}

Parameters

$className

find($className, $id)

{@inheritdoc}

Parameters

$className
$id

Collection findMany(null|string $className, array $ids)

Finds many documents by id.

Parameters

null|string $className Only return documents that match the specified class. All others are treated as not found.
array $ids List of repository paths and/or uuids to find documents. Non-existing ids are ignored.

Return Value

Collection list of documents that where found with the $ids and if specified the $className.

object findTranslation(null|string $className, string $id, string $locale, bool $fallback = true)

Load the document from the content repository in the given language.

If $fallback is set to true, then the language chooser strategy is used to load the best suited language for the translatable fields.

If fallback is true and no translation is found, this method has the same behaviour as find(), all translated fields will simply be null. If fallback is false and the requested translation does not exist, a MissingTranslationException is thrown.

Note that this will be the same object as you got with a previous find/findTranslation call - we can't allow copies of objects to exist.

Parameters

null|string $className The class name to find the translation for
string $id The identifier of the class (path or uuid)
string $locale The language to try to load.
bool $fallback Set to true if the language fallback mechanism should be used.

Return Value

object the translated document.

Exceptions

PHPCRException if $className is specified and does not match the class of the document that was found at $id.
MissingTranslationException if $fallback is false and the translation was not found

getRepository($className)

{@inheritdoc}

Parameters

$className

string quote(string $val, int $type = PropertyType::STRING)

Quote a string for inclusion in an SQL2 query.

Parameters

string $val
int $type

Return Value

string

string escapeFullText(string $string)

Escape the illegal characters for inclusion in a fulltext statement. Escape Character is \.

Parameters

string $string

Return Value

string Escaped String

QueryInterface createPhpcrQuery(string $statement, string $language)

Create a PHPCR Query from a query string in the specified query language to be used with getDocumentsByPhpcrQuery().

Note that it is better to use {@link createQuery}, which returns a native ODM query object, when working with the ODM.

See \PHPCR\Query\QueryInterface for list of generally supported types and check your implementation documentation if you want to use a different language.

Parameters

string $statement The statement in the specified language
string $language The query language

Return Value

QueryInterface

Query createQuery(string $statement, string $language)

Create a ODM Query from a query string in the specified query language to be used with getDocumentsByPhpcrQuery().

See \PHPCR\Query\QueryInterface for list of generally supported types and check your implementation documentation if you want to use a different language.

Parameters

string $statement The statement in the specified language
string $language The query language

Return Value

Query

QueryBuilder createQueryBuilder()

Create the fluent query builder.

Query returned by QueryBuilder::getQuery()

Return Value

QueryBuilder

QueryBuilder createPhpcrQueryBuilder()

Create lower level PHPCR query builder.

NOTE: The ODM QueryBuilder (@link createQueryBuilder) is prefered over the PHPCR QueryBuilder when working with the ODM.

Return Value

QueryBuilder

array getDocumentsByPhpcrQuery(QueryInterface $query, string|null $className = null, string|null $primarySelector = null)

Get document results from a PHPCR query instance.

Parameters

QueryInterface $query The query instance as acquired through createPhpcrQuery().
string|null $className Document class.
string|null $primarySelector Name of the selector for the document to return in case of a join query.

Return Value

array of document instances

persist($document)

{@inheritdoc}

Parameters

$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

InvalidArgumentException if $document is not an object or not managed.
PHPCRException if the document is not translatable

removeTranslation(object $document, string $locale)

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

Parameters

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

Exceptions

InvalidArgumentException if $document is not an object.

array getLocalesFor(object $document, bool $includeFallbacks = false)

Get the list of locales that exist for the specified document, including those not yet flushed, but bound.

Parameters

object $document The document to get the locales for.
bool $includeFallbacks Whether to include the available language fallbacks.

Return Value

array of strings with all locales existing for this particular document

Exceptions

InvalidArgumentException if $document is not an object.
MissingTranslationException if the document is not translatable

bool isDocumentTranslatable(object $document)

Determine whether this document is translatable.

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

Parameters

object $document The document to get the locales for.

Return Value

bool

move(object $document, string $targetPath)

Move the previously persisted document and all its children in the tree.

Note that this does not update the Id fields of child documents and neither fields with Child/Children mappings. If you want to continue working with the manager after a move, you are probably safest calling DocumentManager::clear and re-loading the documents you need to use.

Parameters

object $document An already registered document.
string $targetPath The target path including the nodename.

Exceptions

InvalidArgumentException if $document is not an object.

reorder(object $document, string $srcName, string $targetName, bool $before)

Reorder a child of the given document.

Note that this does not update the fields with Child/Children mappings. If you want to continue working with the manager after a reorder, you are probably safest calling DocumentManager::clear and re-loading the documents you need to use.

Parameters

object $document The parent document which must be persisted already.
string $srcName The nodename of the child to be reordered.
string $targetName The nodename of the target of the reordering.
bool $before Whether to move before or after the target.

Exceptions

InvalidArgumentException if $document is not an object.

remove($document)

{@inheritdoc}

Parameters

$document

merge($document)

{@inheritdoc}

Parameters

$document

detach($document)

{@inheritdoc}

Parameters

$document

refresh($document)

{@inheritdoc}

Parameters

$document

ChildrenCollection getChildren(object $document, string|array $filter = null, int $fetchDepth = null, string $locale = null)

Get the child documents of a given document using an optional filter.

This methods gets all child nodes as a collection of documents that matches a given filter (same as PHPCR Node::getNodes)

Note that this method only returns children that have been flushed.

Parameters

object $document Document instance which children should be loaded.
string|array $filter Optional filter to filter on children names.
int $fetchDepth Optional fetch depth.
string $locale The locale to use during the loading of this collection.

Return Value

ChildrenCollection collection of child documents

Exceptions

InvalidArgumentException if $document is not an object.

ReferrersCollection getReferrers(object $document, string|null $type = null, string|null $name = null, string $locale = null, string|null $refClass = null)

Get the documents that refer a given document using an optional name.

This methods gets a collection of documents that have references to the given document, optionally only hard or weak references, optionally filtered by the referring PHPCR property name.

Multilingual documents are loaded in the default locale, unless a locale preference is explicitly specified.

Note that this method only returns referrers that have been flushed.

Parameters

object $document The target of the references to be loaded.
string|null $type The reference type, null|'weak'|'hard'.
string|null $name Optional PHPCR property name that holds the reference.
string $locale The locale to use during the loading of this collection.
string|null $refClass Class the referrer document must be instanceof.

Return Value

ReferrersCollection collection of referrer documents

Exceptions

InvalidArgumentException if $document is not an object.

void flush(object|array|null $document = null)

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.

This is different from the ObjectManager in that it accepts an optional argument to limit the flush to one or more specific documents.

Parameters

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

Return Value

void

Exceptions

InvalidArgumentException if $document is neither null nor a document or an array of documents

mixed|object getReference(string $documentName, string|object $id)

Gets a reference to the document identified by the given type and identifier without actually loading it.

If partial objects are allowed, this method will return a partial object that only has its identifier populated. Otherwise a proxy is returned that automatically loads itself on first access.

Parameters

string $documentName
string|object $id

Return Value

mixed|object The document reference.

checkin(object $document)

Create a new version of the document that has been previously persisted and flushed.

The state that is stored is the one from the last flush, not from the current document state.

The document is made read only until you call checkout again.

Parameters

object $document

Exceptions

InvalidArgumentException if $document is not an object.

checkout(object $document)

Make a checked in document writable again.

Parameters

object $document

Exceptions

InvalidArgumentException if $document is not an object.

checkpoint(object $document)

Do a checkin operation followed immediately by a checkout operation.

A new version is created and the writable document stays in checked out state

Parameters

object $document

Exceptions

InvalidArgumentException if $document is not an object.

restoreVersion(string $documentVersion, bool $removeExisting = true)

Restores the current checked out document to the values of the given version in storage and refreshes the document object.

Note that this does not change anything on the version history.

The restore is immediately propagated to the backend.

Parameters

string $documentVersion The version to be restored.
bool $removeExisting How to handle conflicts with unique identifiers. If true, existing documents with the identical identifier will be replaced, otherwise an exception is thrown.

removeVersion(object $documentVersion)

Delete the specified version to clean up the history.

Note that you can not remove the currently active version, only old versions.

Parameters

object $documentVersion The version document as returned by findVersionByName.

Exceptions

RepositoryException when trying to remove the root version or the last version

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

Get the version history information for a document.

labels will be an empty array.

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

Exceptions

InvalidArgumentException if $document is not an object.

object findVersionByName(null|string $className, string $id, string $versionName)

Returns a read-only, detached document instance of the document at the specified path with the specified version name.

The id of the returned document representing this version is not the id of the original document.

Parameters

null|string $className
string $id Id of the document.
string $versionName The version name as given by getLinearPredecessors.

Return Value

object the detached document or null if the document is not found

Exceptions

InvalidArgumentException if there is a document with $id but no version with $name
UnsupportedRepositoryOperationException if the implementation does not support versioning

contains($document)

{@inheritdoc}

Parameters

$document

UnitOfWork getUnitOfWork()

Client code should not access the UnitOfWork except in special circumstances. Methods on UnitOfWork might be changed without special notice.

Return Value

UnitOfWork

clear($className = null)

{@inheritdoc}

Parameters

$className

close()

Closes the DocumentManager. All entities that are currently managed by this DocumentManager become detached. The DocumentManager may no longer be used after it is closed.

initializeObject($document)

{@inheritdoc}

Parameters

$document

NodeInterface getNodeForDocument(object $document)

Return the node of the given object.

Parameters

object $document

Return Value

NodeInterface

Exceptions

InvalidArgumentException if $document is not an object.
PHPCRException if $document is not managed

string getDocumentId(object $document)

Get the document identifier phpcr-odm is using.

Parameters

object $document A managed document

Return Value

string

Exceptions

PHPCRException if $document is not managed