PHP Класс Jackalope\Item

Jackalope Implementation: The item has a state machine to track in what state it currently is. All API exposed methods must call Item::checkState() before doing anything. Most important is that everything that is in state deleted can not be used anymore (will detect logic errors in client code) and that if the item needs to be refreshed from the backend, this can be postponed until the item is actually accessed again. Figure: workflow state transitions For the special case of Item state after a failed transaction, see Item::rollbackTransaction()
Наследование: implements PHPCR\ItemInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$available_states The states an Item can take
$depth Depth in the workspace graph
$factory The jackalope object factory for this object
$isNode Whether this item is a node (otherwise it is a property)
$keepChanges To know whether to keep changes or not when reloading in dirty state
$name the node or property name
$new false if item is read from backend, true if created locally in this session
$objectManager The object manager to get nodes and properties from
$oldPath While this item is moved but unsaved, stores the old path for refresh.
$parentPath Normalized and absolute path to the parent item for convenience.
$path Normalized and absolute path to this item.
$postDirtyState The state to take after this dirty node has been refreshed. One of the STATE_ constants
$savedState The state of the item saved when a transaction is started
$session The session this item belongs to
$state The state of the item, one of the STATE_ constants
$valueConverter PHPCR\Util\ValueConverter

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

Метод Описание
accept ( PHPCR\ItemVisitorInterface $visitor ) {@inheritDoc}
beginTransaction ( ) Manage item state when transaction starts. This method is called on every cached item by the ObjectManager.
commitTransaction ( ) Clean up state after a transaction. This method is called on every cached item by the ObjectManager.
confirmSaved ( ) notify this item that it has been saved into the backend.
getAncestor ( $depth ) {@inheritDoc}
getDepth ( ) {@inheritDoc}
getName ( ) {@inheritDoc}
getParent ( ) {@inheritDoc}
getPath ( ) {@inheritDoc}
getSession ( ) {@inheritDoc}
getState ( ) : integer Get the state of the item
isClean ( ) : boolean Whether this item is in STATE_CLEAN (meaning its data is fully synchronized with the backend)
isDeleted ( ) : boolean Whether this item has been deleted and can not be used anymore.
isDirty ( ) : boolean Whether this item is in state dirty.
isModified ( ) {@inheritDoc}
isMoved ( ) {@inheritDoc}
isNew ( ) {@inheritDoc}
isNode ( ) {@inheritDoc}
isSame ( PHPCR\ItemInterface $otherItem ) {@inheritDoc}
remove ( ) {@inheritDoc}
revert ( ) {@inheritDoc}
rollbackTransaction ( ) Adjust the correct item state after a transaction rollback. This method is called on every cached item by the ObjectManager.
setClean ( ) Tell this item it is clean (i.e. it has been refreshed after a modification)
setDeleted ( ) Tell this item it has been deleted and cannot be used anymore
setDirty ( boolean $keepChanges = false, $targetState = false ) Tell this item that it is dirty and needs to be refreshed
setModified ( ) Tell this item that it has been modified.
setPath ( string $path, boolean $move = false ) Set or update the path, depth, name and parent reference

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

Метод Описание
__construct ( jackalope\FactoryInterface $factory, string $path, jackalope\Session $session, ObjectManager $objectManager, boolean $new = false ) Initialize basic information common to nodes and properties
checkState ( ) This function will modify the state of the item as well as refresh it if necessary (i.e.
findItemDefinition ( callable $definitions ) : PHPCR\NodeType\ItemDefinitionInterface Find the matching item definition for this item.
refresh ( boolean $keepChanges ) Updates the state of the current item.

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

Метод Описание
setState ( integer $state ) Change the state of the item

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

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

Initialize basic information common to nodes and properties
protected __construct ( jackalope\FactoryInterface $factory, string $path, jackalope\Session $session, ObjectManager $objectManager, boolean $new = false )
$factory jackalope\FactoryInterface the object factory
$path string The normalized and absolute path to this item
$session jackalope\Session
$objectManager ObjectManager
$new boolean can be set to true to tell the object that it has been created locally

accept() публичный метод

{@inheritDoc}
public accept ( PHPCR\ItemVisitorInterface $visitor )
$visitor PHPCR\ItemVisitorInterface

beginTransaction() публичный метод

Saves the current item state in case a rollback occurs.
См. также: Item::rollbackTransaction
public beginTransaction ( )

checkState() защищенный метод

if it is DIRTY).
protected checkState ( )

commitTransaction() публичный метод

Clean up state after a transaction. This method is called on every cached item by the ObjectManager.
См. также: Item::rollbackTransaction
public commitTransaction ( )

confirmSaved() публичный метод

allowing it to clear the modified / new flags
public confirmSaved ( )

findItemDefinition() защищенный метод

Find the matching item definition for this item.
protected findItemDefinition ( callable $definitions ) : PHPCR\NodeType\ItemDefinitionInterface
$definitions callable Function that extracts the ItemDefinitions from a NodeType
Результат PHPCR\NodeType\ItemDefinitionInterface The definition for this item.

getAncestor() публичный метод

{@inheritDoc}
public getAncestor ( $depth )

getDepth() публичный метод

{@inheritDoc}
public getDepth ( )

getName() публичный метод

{@inheritDoc}
public getName ( )

getParent() публичный метод

{@inheritDoc}
public getParent ( )

getPath() публичный метод

{@inheritDoc}
public getPath ( )

getSession() публичный метод

{@inheritDoc}
public getSession ( )

getState() публичный метод

Get the state of the item
public getState ( ) : integer
Результат integer one of the state constants

isClean() публичный метод

Whether this item is in STATE_CLEAN (meaning its data is fully synchronized with the backend)
public isClean ( ) : boolean
Результат boolean

isDeleted() публичный метод

Whether this item has been deleted and can not be used anymore.
public isDeleted ( ) : boolean
Результат boolean

isDirty() публичный метод

Returns true if this Item has been marked dirty (i.e. being saved) and has not been refreshed since. The in-memory representation of the item in memory might not reflect the current state in the backend (for instance if mix:referenceable mixin type has been added to the item the backend creates a UUID on save).
public isDirty ( ) : boolean
Результат boolean

isModified() публичный метод

{@inheritDoc}
public isModified ( )

isMoved() публичный метод

{@inheritDoc}
public isMoved ( )

isNew() публичный метод

{@inheritDoc}
public isNew ( )

isNode() публичный метод

{@inheritDoc}
public isNode ( )

isSame() публичный метод

{@inheritDoc}
public isSame ( PHPCR\ItemInterface $otherItem )
$otherItem PHPCR\ItemInterface

refresh() абстрактный защищенный метод

In JSR-283 this was part of the interface. While JSR-333 deprecated the refresh() method and replaces it with revert(), the functionality is still needed as Session::refresh() has been kept. If keepChanges is false, this method discards all pending changes currently recorded in this Session that apply to this Item or any of its descendants (that is, the subgraph rooted at this Item) and returns all items to reflect the current saved state. Outside a transaction this state is simply the current state of persistent storage. Within a transaction, this state will reflect persistent storage as modified by changes that have been saved but not yet committed. If keepChanges is true then pending change are not discarded but items that do not have changes pending have their state refreshed to reflect the current saved state, thus revealing changes made by other sessions.
abstract protected refresh ( boolean $keepChanges )
$keepChanges boolean a boolean

remove() публичный метод

{@inheritDoc}
public remove ( )

revert() публичный метод

{@inheritDoc}
public revert ( )

rollbackTransaction() публичный метод

Item state represents the state of an in-memory item. This has nothing to do with the state of the item in the backend. Referring to the JCR spec (21.3 Save vs. Commit) a transaction rollback or commit will not change the in-memory state of items, but only the backend. When a transaction is rolled back, we try to correct the state of in-memory items so that the session could be correctly saved if no more constraint violations remain. Note that this does not fully work yet. On Item::beginTransaction() we save the current state into savedState. On a rollback, we basically go back to the saved state, with a couple of exceptions. The following table shows an ordered list of rules - the first match is used. The * denotes any state.
#$savedState$state Resulting $state
1DELETED * DELETED
2* DELETED DELETED
3NEW * NEW
4* MODIFIEDMODIFIED
5MODIFIED * MODIFIED
6CLEAN CLEAN CLEAN (if the item was not modified in the TRX)
7CLEAN CLEAN MODIFIED (if the item was modified in the TRX)
note: case 7 is handled in Item::setState() by changing $savedState to MODIFIED if $savedState is CLEAN and current state changes to MODIFIED Without this special case, we would miss the situation where a clean node is modified after transaction start and successfully saved, ending up with clean state again. it has to be modified as its different from the backend value.
8CLEAN DIRTY DIRTY
9DIRTY * DIRTY
См. также: ObjectManager::rollbackTransaction()
public rollbackTransaction ( )

setClean() публичный метод

Tell this item it is clean (i.e. it has been refreshed after a modification)
public setClean ( )

setDeleted() публичный метод

Tell this item it has been deleted and cannot be used anymore
public setDeleted ( )

setDirty() публичный метод

Tell this item that it is dirty and needs to be refreshed
public setDirty ( boolean $keepChanges = false, $targetState = false )
$keepChanges boolean whether to keep changes when reloading or not

setModified() публичный метод

This will do nothing if the node is new, to avoid duplicating store commands.
public setModified ( )

setPath() публичный метод

Set or update the path, depth, name and parent reference
public setPath ( string $path, boolean $move = false )
$path string the new path this item lives at
$move boolean whether this item is being moved in session context and should store the current path until the next save operation.

Описание свойств

$available_states защищенное свойство

The states an Item can take
protected $available_states

$depth защищенное свойство

Depth in the workspace graph
protected $depth

$factory защищенное свойство

The jackalope object factory for this object
protected $factory

$isNode защищенное свойство

Whether this item is a node (otherwise it is a property)
protected $isNode

$keepChanges защищенное свойство

To know whether to keep changes or not when reloading in dirty state
protected $keepChanges

$name защищенное свойство

the node or property name
protected $name

$new защищенное свойство

false if item is read from backend, true if created locally in this session
protected $new

$objectManager защищенное свойство

The object manager to get nodes and properties from
protected $objectManager

$oldPath защищенное свойство

While this item is moved but unsaved, stores the old path for refresh.
protected $oldPath

$parentPath защищенное свойство

Normalized and absolute path to the parent item for convenience.
protected $parentPath

$path защищенное свойство

Normalized and absolute path to this item.
protected $path

$postDirtyState защищенное свойство

The state to take after this dirty node has been refreshed. One of the STATE_ constants
protected $postDirtyState

$savedState защищенное свойство

The state of the item saved when a transaction is started
См. также: Item::rollbackTransaction()
protected $savedState

$session защищенное свойство

The session this item belongs to
protected $session

$state защищенное свойство

The state of the item, one of the STATE_ constants
protected $state

$valueConverter защищенное свойство

protected ValueConverter,PHPCR\Util $valueConverter
Результат PHPCR\Util\ValueConverter