phpcr-utils/src/PHPCR/Util/PathHelper.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\PathHelper
- Author
- David Buchmann
Methods
absolutizePath(string $path, string $context, bool $destination = false, bool $throw = true) : string
In addition to normalizing and validating, this method combines the path with a context if it is not absolute.
Name | Type | Description |
---|---|---|
$path | string | A relative or absolute path |
$context | string | The absolute path context to make $path absolute if needed |
$destination | bool | whether this is a destination path (by copy or move), meaning [] is not allowed in validation. |
$throw | bool | whether to throw an exception if validation fails or just to return false. |
Type | Description |
---|---|
string | The normalized, absolute path or false if $throw was false and the path invalid |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if the path can not be made into a valid absolute path and $throw is true |
assertValidAbsolutePath(string $path, bool $destination = false, bool $throw = true) : bool
Check whether this is a syntactically valid absolute path.
The JCR specification is posing few limits on valid paths, your implementation probably wants to provide its own code based on this one
Non-normalized paths are considered invalid, i.e. /node/. is /node and /my/node/.. is /my
Name | Type | Description |
---|---|---|
$path | string | The path to validate |
$destination | bool | whether this is a destination path (by copy or move), meaning [] is not allowed. If your implementation does not support same name siblings, just always pass true for this |
$throw | bool | whether to throw an exception on validation errors |
Type | Description |
---|---|
bool | true if valid, false if not valid and $throw was false |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if the path contains invalid characters and $throw is true |
assertValidLocalName(string $name, $throw = true) : bool
Minimal check to see if this local node name conforms to the jcr specification for a name without the namespace.
Note that the empty string is actually a valid node name (the root node)
If it can't be avoided, implementations may restrict validity further, but this will reduce interchangeability, thus it is better to properly encode and decode characters that are not natively allowed by a storage engine.
Name | Type | Description |
---|---|---|
$name | string | The name to check |
$throw |
Type | Description |
---|---|
bool | true if valid, false if not valid and $throw was false |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if the name is invalid and $throw is true |
- See
- \PHPCR\Util\http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.2.2%20Local%20Names
getNodeName(string $path) : string
Get the name from the path, including eventual namespace prefix.
You must make sure to only pass valid paths to this method.
Name | Type | Description |
---|---|---|
$path | string | a valid absolute path, like /content/jobs/data |
Type | Description |
---|---|
string | the name, that is the string after the last "/" |
getParentPath(string $path) : string
Get the parent path of a valid absolute path.
Name | Type | Description |
---|---|---|
$path | string | the path to get the parent from |
Type | Description |
---|---|
string | the path with the last segment removed |
normalizePath(string $path, bool $destination = false, bool $throw = true) : string
Normalize path according to JCR's spec (3.4.5) and then validates it using the assertValidAbsolutePath method.
- All self segments(.) are removed.
- All redundant parent segments(..) are collapsed.
Note: A well-formed input path implies a well-formed and normalized path returned.
Name | Type | Description |
---|---|---|
$path | string | The path to normalize. |
$destination | bool | whether this is a destination path (by copy or move), meaning [] is not allowed in validation. |
$throw | bool | whether to throw an exception if validation fails or just to return false. |
Type | Description |
---|---|
string | The normalized path or false if $throw was false and the path invalid |
Exception | Description |
---|---|
\PHPCR\RepositoryException | if the path is not a valid absolute path and $throw is true |