phpcr-utils/src/PHPCR/Util/PathHelper.php

Show: PublicProtectedPrivateinherited
Table of Contents
This file is part of the PHPCR Utils

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.

License
Apache Software License 2.0  
Link
http://phpcr.github.com/  

\PHPCR\Util\PathHelper

Package: Default
Static methods to handle path operations for PHPCR implementations
Author
David Buchmann  

Methods

methodprivate__construct() : void

Do not create an instance of this class

methodpublicabsolutizePath(string $path, string $context, bool $destination = false, bool $throw = true) : string
static

In addition to normalizing and validating, this method combines the path with a context if it is not absolute.

Parameters
NameTypeDescription
$pathstring

A relative or absolute path

$contextstring

The absolute path context to make $path absolute if needed

$destinationbool

whether this is a destination path (by copy or move), meaning [] is not allowed in validation.

$throwbool

whether to throw an exception if validation fails or just to return false.

Returns
TypeDescription
stringThe normalized, absolute path or false if $throw was false and the path invalid
Throws
ExceptionDescription
\PHPCR\RepositoryExceptionif the path can not be made into a valid absolute path and $throw is true
methodpublicassertValidAbsolutePath(string $path, bool $destination = false, bool $throw = true) : bool
static

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

Parameters
NameTypeDescription
$pathstring

The path to validate

$destinationbool

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

$throwbool

whether to throw an exception on validation errors

Returns
TypeDescription
booltrue if valid, false if not valid and $throw was false
Throws
ExceptionDescription
\PHPCR\RepositoryExceptionif the path contains invalid characters and $throw is true
methodpublicassertValidLocalName(string $name,  $throw = true) : bool
static

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.

Parameters
NameTypeDescription
$namestring

The name to check

$throw
Returns
TypeDescription
booltrue if valid, false if not valid and $throw was false
Throws
ExceptionDescription
\PHPCR\RepositoryExceptionif the name is invalid and $throw is true
Details
See
\PHPCR\Util\http://www.day.com/specs/jcr/2.0/3_Repository_Model.html#3.2.2%20Local%20Names  
methodpublicgetNodeName(string $path) : string
static

Get the name from the path, including eventual namespace prefix.

You must make sure to only pass valid paths to this method.

Parameters
NameTypeDescription
$pathstring

a valid absolute path, like /content/jobs/data

Returns
TypeDescription
stringthe name, that is the string after the last "/"
methodpublicgetParentPath(string $path) : string
static

Get the parent path of a valid absolute path.

Parameters
NameTypeDescription
$pathstring

the path to get the parent from

Returns
TypeDescription
stringthe path with the last segment removed
methodpublicnormalizePath(string $path, bool $destination = false, bool $throw = true) : string
static

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.

Parameters
NameTypeDescription
$pathstring

The path to normalize.

$destinationbool

whether this is a destination path (by copy or move), meaning [] is not allowed in validation.

$throwbool

whether to throw an exception if validation fails or just to return false.

Returns
TypeDescription
stringThe normalized path or false if $throw was false and the path invalid
Throws
ExceptionDescription
\PHPCR\RepositoryExceptionif the path is not a valid absolute path and $throw is true
Documentation was generated by phpDocumentor 2.0.0a12.