phpcr-utils/src/PHPCR/Util/NodeHelper.php
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\NodeHelper
- Author
- Daniel Barsotti
- Author
- David Buchmann
Methods
calculateOrderBefore(array $old, array $new) : array
Compare two arrays and generate a list of move operations that executed in order will transform $old into $new.
The result is an array with the keys being elements of the array to move right before the element in the value. A value of null means move to the end.
If $old contains elements not present in $new, those elements are ignored and do not show up.
Name | Type | Description |
---|---|---|
$old | array | old order |
$new | array | new order |
Type | Description |
---|---|
array | the keys are elements to move, values the destination to move before or null to move to the end. |
createPath(\PHPCR\SessionInterface $session, string $path) : \PHPCR\NodeInterface
Create a node and it's parents, if necessary.
Like mkdir -p.
Name | Type | Description |
---|---|---|
$session | \PHPCR\SessionInterface | the PHPCR session to create the path |
$path | string | full path, like /content/jobs/data |
Type | Description |
---|---|
\PHPCR\NodeInterface | the last node of the path, i.e. data |
deleteAllNodes( $session) : void
Kept as alias of purgeWorkspace for BC compatibility
Name | Type | Description |
---|---|---|
$session |
- Deprecated
generateAutoNodeName(string[] $usedNames, string[] $namespaces, string $defaultNamespace, string $nameHint = null) : string
Helper method to implement NodeInterface::addNodeAutoNamed
This method only checks for valid namespaces. All other exceptions must be thrown by the addNodeAutoNamed implementation.
Name | Type | Description |
---|---|---|
$usedNames | string[] | list of child names that is currently used and may not be chosen. |
$namespaces | string[] | namespace prefix to uri map of all currently known namespaces. |
$defaultNamespace | string | namespace prefix to use if the hint does not specify. |
$nameHint | string | the name hint according to the API definition |
Type | Description |
---|---|
string | A valid node name for this node |
Exception | Description |
---|---|
\PHPCR\NamespaceException | if a namespace prefix is provided in the $nameHint which does not exist and this implementation performs this validation immediately. |
generateWithPrefix(string[] $usedNames, string $prefix, string $namepart = '') : string
Repeatedly generate a name with a random part until we hit one that is not yet used.
Name | Type | Description |
---|---|---|
$usedNames | string[] | names that are forbidden |
$prefix | string | the prefix including the colon at the end |
$namepart | string | start for the localname |
Type | Description |
---|---|
string |
isSystemItem(\PHPCR\ItemInterface $item) : void
Determine whether this item has a namespace that is to be considered a system namespace
Name | Type | Description |
---|---|---|
$item | \PHPCR\ItemInterface |
orderBeforeArray(string $name, string $destination, array $list) : array
Move the element $name of $list to right before $destination, validating existence of all elements.
Name | Type | Description |
---|---|---|
$name | string | name of the element to move |
$destination | string | name of the element $srcChildRelPath has to be ordered before, null to move to the end |
$list | array | the array of names |
Type | Description |
---|---|
array | The updated $nodes array with new order |
Exception | Description |
---|---|
\PHPCR\ItemNotFoundException | if $srcChildRelPath or $destChildRelPath are not found in $nodes |
purgeWorkspace(\PHPCR\SessionInterface $session) : void
Delete all content in the workspace this session is bound to.
Remember to save the session after calling the purge method.
Note that if you want to delete a node under your root node, you can just use the remove method on that node. This method is just here to help you because the implementation might add nodes like jcr:system to the root node which you are not allowed to remove.
Name | Type | Description |
---|---|---|
$session | \PHPCR\SessionInterface | the session to remove all children of the root node |
- See
- \PHPCR\Util\isSystemItem