phpcr-utils/src/PHPCR/Util/TraversingItemVisitor.php
Copyright 2008-2011 Karsten Dambekalns karsten@typo3.org
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
\PHPCR\Util\TraversingItemVisitor
TraversingItemVisitor is an abstract utility class which allows to easily traverse an Item hierarchy. You overwrite entering and leaving methods that get called for all properties encountered
TraversingItemVisitor makes use of the Visitor Pattern as described in the book 'Design Patterns' by the Gang Of Four (Gamma et al.). Tree traversal is done observing the left-to-right order of child Items if such an order is supported and exists.
- Implements
- \PHPCR\ItemVisitorInterface
- Api
- Author
- Karsten Dambekalns
- Author
- Day Management AG, Switzerland
Properties
boolean $breadthFirst = false
false
Details- Type
- boolean
integer $currentDepth
- Type
- integer
integer $maxDepth = -1
-1
Details- Type
- integer
Methods
__construct(boolean $breadthFirst = false, integer $maxDepth = -1) : void
Constructs a new instance of this class.
Name | Type | Description |
---|---|---|
$breadthFirst | boolean | if $breadthFirst is true then traversal is done in a breadth-first manner; otherwise it is done in a depth-first manner (which is the default behavior). |
$maxDepth | integer | the 0-based depth relative to the root node up to which the hierarchy should be traversed (if it's -1, the hierarchy will be traversed until there are no more children of the current item). |
- Api
entering(\PHPCR\ItemInterface $item, integer $depth) : void
Implement this method to add behavior performed before a Property is visited.
Name | Type | Description |
---|---|---|
$item | \PHPCR\ItemInterface | the Item that is accepting this visitor. |
$depth | integer | hierarchy level of this node (the root node starts at depth 0). |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api
leaving(\PHPCR\ItemInterface $item, integer $depth) : void
Implement this method to add behavior performed after a Property is visited.
Name | Type | Description |
---|---|---|
$item | \PHPCR\ItemInterface | the Item that is accepting this visitor. |
$depth | integer | hierarchy level of this property (the root node starts at depth 0). |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api
setLevel(int $level) : void
Update the current depth level for indention
Name | Type | Description |
---|---|---|
$level | int |
visit(\PHPCR\ItemInterface $item) : void
Called when the Visitor is passed to an Item.
It calls TraversingItemVisitor::entering() followed by TraversingItemVisitor::leaving(). Implement these abstract methods to specify behavior on 'arrival at' and 'after leaving' the $item.
If this method throws, the visiting process is aborted.
Name | Type | Description |
---|---|---|
$item | \PHPCR\ItemInterface | the Node or Property that is accepting this visitor. |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if an error occurs. |
- Api