PHP Class Jackalope\Transport\Jackrabbit\Client

This class handles the communication between Jackalope and Jackrabbit over Davex. Once the login method has been called, the workspace is set and can not be changed anymore. We make one exception to the rule that nothing may be cached in the transport: Repository descriptors are considered immutable and cached (because they are also used in startup to check the backend version is compatible).
Author: Christian Stocker ([email protected])
Author: David Buchmann ([email protected])
Author: Tobias Ebnöther ([email protected])
Author: Roland Schilter ([email protected])
Author: Uwe Jäger ([email protected])
Author: Lukas Kahwe Smith ([email protected])
Author: Daniel Barsotti ([email protected])
Author: Markus Schmucker ([email protected])
Inheritance: extends Jackalope\Transport\BaseTransport, implements Jackalope\Transport\QueryInterface, implements Jackalope\Transport\PermissionInterface, implements Jackalope\Transport\WritingInterface, implements Jackalope\Transport\VersioningInterface, implements Jackalope\Transport\NodeTypeCndManagementInterface, implements Jackalope\Transport\LockingInterface, implements Jackalope\Transport\ObservationInterface, implements Jackalope\Transport\WorkspaceManagementInterface
显示文件 Open project: jackalope/jackalope-jackrabbit Class Usage Examples

Protected Properties

Property Type Description
$checkLoginOnServer boolean Check if an initial PROPFIND should be send to check if repository exists This is according to the JCR specifications and set to true by default
$credentials PHPCR\SimpleCredentials Set once login() has been executed and may not be changed later on.
$curl Jackalope\Transport\Jackrabbit\curl The cURL resource handle
$defaultHeaders array[]string A list of additional HTTP headers to be sent on each request
$descriptors This is our exception to the rule that nothing may be cached in transport.
$factory Jackalope\FactoryInterface The factory to instantiate objects
$jsopBody
$nodeTypeManager Jackalope\NodeType\NodeTypeManager
$sendExpect Send Expect: 100-continue header
$server string i.e http://localhost:8080/server/ constructor ensures the trailing slash /
$typeXmlConverter Jackalope\NodeType\NodeTypeXmlConverter
$userData
$valueConverter PHPCR\Util\ValueConverter
$workspace string Set once login() has been executed and may not be changed later on.
$workspaceUri string "$server/$workspace" without trailing slash
$workspaceUriRoot string "$server/$workspace/jcr%3aroot (make sure you never hardcode the jcr%3aroot, its ugly)

Public Methods

Method Description
__construct ( Jackalope\FactoryInterface $factory, string $serverUri ) Create a transport pointing to a server url.
__destruct ( ) Tidies up the current cUrl connection.
addCurlOptions ( array $options ) : array Add global curl-options.
addDefaultHeader ( string $header ) Add a HTTP header which is sent on each Request.
addVersionLabel ( $versionPath, $label, $moveLabel )
checkinItem ( $path ) {@inheritDoc}
checkoutItem ( $path ) {@inheritDoc}
cloneFrom ( $srcWorkspace, $srcAbsPath, $destAbsPath, $removeExisting ) {@inheritDoc}
copyNode ( $srcAbsPath, $dstAbsPath, $srcWorkspace = null ) {@inheritDoc}
createWorkspace ( $name, $srcWorkspace = null ) {@inheritDoc}
deleteNodeImmediately ( $path ) {@inheritDoc}
deleteNodes ( array $operations ) {@inheritDoc}
deleteProperties ( array $operations ) {@inheritDoc}
deletePropertyImmediately ( $path ) {@inheritDoc}
deleteWorkspace ( $name )
fetchEventData ( $date ) : array Internal method to fetch event data.
finishSave ( ) {@inheritDoc}
forceHttpVersion10 ( $forceHttpVersion10 = true ) Set to true to force HTTP version 1.0
getAccessibleWorkspaceNames ( ) {@inheritDoc}
getBinaryStream ( $path ) {@inheritDoc}
getEvents ( $date, PHPCR\Observation\EventFilterInterface $filter, PHPCR\SessionInterface $session ) {@inheritDoc}
getNamespaces ( ) {@inheritDoc}
getNode ( $path ) {@inheritDoc}
getNodeByIdentifier ( $uuid ) {@inheritDoc}
getNodePathForIdentifier ( $uuid, $workspace = null ) {@inheritDoc}
getNodeTypes ( $nodeTypes = [] ) {@inheritDoc}
getNodes ( $paths, $query = ':include' ) {@inheritDoc}
getNodesByIdentifier ( $identifiers ) {@inheritDoc}
getPermissions ( $path ) {@inheritDoc}
getProperty ( $path ) {@inheritDoc}
getReferences ( $path, $name = null ) {@inheritDoc}
getRepositoryDescriptors ( ) {@inheritDoc}
getSupportedQueryLanguages ( ) {@inheritDoc}
getUserData ( ) : mixed
getWeakReferences ( $path, $name = null ) {@inheritDoc}
getWorkspaceUri ( ) : null | string Return the URL to the workspace determined during login
isLocked ( $absPath ) {@inheritDoc}
lockNode ( $absPath, $isDeep, $isSessionScoped, $timeoutHint = PHP_INT_MAX, $ownerInfo = null ) {@inheritDoc}
login ( PHPCR\CredentialsInterface $credentials = null, $workspaceName = null ) {@inheritDoc}
logout ( ) {@inheritDoc}
moveNodeImmediately ( $srcAbsPath, $dstAbsPath ) {@inheritDoc}
moveNodes ( array $operations ) {@inheritDoc}
prepareSave ( ) {@inheritDoc}
query ( Query $query ) {@inheritDoc}
registerNamespace ( $prefix, $uri ) {@inheritDoc}
registerNodeTypesCnd ( $cnd, $allowUpdate ) {@inheritDoc}
removeVersion ( $versionPath, $versionName ) {@inheritDoc}
removeVersionLabel ( $versionPath, $label )
reorderChildren ( Node $node ) {@inheritDoc}
restoreItem ( $removeExisting, $versionPath, $path ) {@inheritDoc}
rollbackSave ( ) {@inheritDoc}
sendExpect ( boolean $send = true ) If you want to send the "Expect: 100-continue" header on larger PUT and POST requests, set this to true.
setCheckLoginOnServer ( $bool ) Configure whether to check if we are logged in before doing a request.
setNodeTypeManager ( $nodeTypeManager ) {@inheritDoc}
setUserData ( $userData ) {@inheritDoc}
storeNodes ( array $operations ) {@inheritDoc}
unlock ( $absPath, $lockToken ) {@inheritDoc}
unregisterNamespace ( $prefix ) {@inheritDoc}
updateNode ( Node $node, $srcWorkspace ) {@inheritDoc}
updateProperties ( Node $node ) {@inheritDoc}

Protected Methods

Method Description
addWorkspacePathToUri ( string $uri ) : string Prepends the workspace root to the uris that contain an absolute path
buildLocateRequest ( string $uuid ) : string Build REPORT XML request for locating a node path by uuid
buildNodeTypesRequest ( array $nodeTypes ) : string Returns the XML required to request nodetypes
buildPropfindRequest ( array $properties ) : string Build PROPFIND request XML for the specified property names
buildRegisterNamespaceRequest ( array $mappings ) Build the xml to update the namespaces
buildRegisterNodeTypeRequest ( string $cnd, $allowUpdate ) : string Build the xml required to register node types
buildReportRequest ( string $name ) : string Build a REPORT XML request string
checkForExistingNode ( $srcWorkspace, $srcAbsPath, $destAbsPath ) Prevent accidental creation of same name siblings during clone operation.
createNodeJsop ( string $path, array $properties ) : string create the node markup and a list of value dispatches for multivalue properties
deleteItem ( string $path ) Record that we need to delete the item at $path
encodeAndValidatePathForDavex ( string $path ) : string Checks if the path is absolute and valid, and properly urlencodes special characters
generateLockFromDavResponse ( DOMElement $response, boolean $sessionOwning = false, string $path = null ) : Lock Extract the information from a LOCK DAV response and create the corresponding Lock object.
getCurl ( )
getMimePart ( $name, $value, $mime_boundary )
getNodeReferences ( string $path, string $name = null, boolean $weak_reference = false ) : array
getRequest ( $method, $uri, $addWorkspacePathToUri = true ) : Request Makes sure there is an open curl connection.
getRequiredDomElementByTagNameNS ( DOMNode $dom, string $namespace, string $element, string $errorMessage = '' ) : boolean | DOMNode Retrieve a child DOM element from a DOM element.
isStringValid ( $string ) : boolean Checks for occurrence of invalid UTF characters, that can not occur in valid XML document.
parseTimeout ( string $timeoutValue ) : integer Parse the timeout value from a WebDAV response and calculate the expire timestamp.
propertyToJsopString ( Property $property ) : mixed | string This method is used when building a JSOP of the properties
setJsopBody ( $value, $key = ":diff", $type = null )
stripServerRootFromUri ( string $uri ) : string remove the server and workspace part from an uri, leaving the absolute path inside the current workspace
updateLastModified ( Node $node ) Update the lastModified fields if they where not set manually.

Private Methods

Method Description
copyNodeOtherWorkspace ( string $srcAbsPath, $dstAbsPath, string $srcWorkspace ) For copy from a different workspace, needs to be a JSOP.
copyNodeSameWorkspace ( string $srcAbsPath, $dstAbsPath ) For copy within the same workspace, this is a COPY request.
decodeBinaryDom ( string $xml ) : array parse the multivalue binary response (a list of base64 encoded values)
getDcrValue ( DOMElement $node ) : mixed Get the value of a dcr:value node in the right format specified by the dcr type.
removeTrailingSlash ( string $path ) : string Remove the trailing slash if present. Used for backend responses when jackrabbit is sloppy
storeProperty ( Property $property )

Method Details

__construct() public method

Create a transport pointing to a server url.
public __construct ( Jackalope\FactoryInterface $factory, string $serverUri )
$factory Jackalope\FactoryInterface the object factory
$serverUri string location of the server

__destruct() public method

Tidies up the current cUrl connection.
public __destruct ( )

addCurlOptions() public method

This options will be used foreach curl-request.
public addCurlOptions ( array $options ) : array
$options array
return array all curl-options

addDefaultHeader() public method

This is used for example for a session identifier header to help a proxy to route all requests from the same session to the same server. This is a Jackrabbit Davex specific option called from the repository factory.
public addDefaultHeader ( string $header )
$header string a valid HTTP header to add to each request

addVersionLabel() public method

public addVersionLabel ( $versionPath, $label, $moveLabel )

addWorkspacePathToUri() protected method

Prepends the workspace root to the uris that contain an absolute path
protected addWorkspacePathToUri ( string $uri ) : string
$uri string The absolute path in the current workspace or server uri
return string The server uri with this path

buildLocateRequest() protected method

Build REPORT XML request for locating a node path by uuid
protected buildLocateRequest ( string $uuid ) : string
$uuid string Unique identifier of the node to be asked for.
return string XML sring representing the content of the request.

buildNodeTypesRequest() protected method

Returns the XML required to request nodetypes
protected buildNodeTypesRequest ( array $nodeTypes ) : string
$nodeTypes array
return string XML with the request information.

buildPropfindRequest() protected method

Build PROPFIND request XML for the specified property names
protected buildPropfindRequest ( array $properties ) : string
$properties array names of the properties to search for
return string XML to post in the body

buildRegisterNamespaceRequest() protected method

You need to repeat all existing node type plus add your new ones
protected buildRegisterNamespaceRequest ( array $mappings )
$mappings array hashmap of prefix => uri for all existing and new namespaces

buildRegisterNodeTypeRequest() protected method

Build the xml required to register node types
Author: david at liip.ch
protected buildRegisterNodeTypeRequest ( string $cnd, $allowUpdate ) : string
$cnd string the node type definition
return string XML with register request

buildReportRequest() protected method

Build a REPORT XML request string
protected buildReportRequest ( string $name ) : string
$name string Name of the resource to be requested.
return string XML string representing the head of the request.

checkForExistingNode() protected method

Jackrabbit supports them, but jackalope does not.
protected checkForExistingNode ( $srcWorkspace, $srcAbsPath, $destAbsPath )
$srcWorkspace
$srcAbsPath
$destAbsPath

checkinItem() public method

{@inheritDoc}
public checkinItem ( $path )

checkoutItem() public method

{@inheritDoc}
public checkoutItem ( $path )

cloneFrom() public method

{@inheritDoc}
public cloneFrom ( $srcWorkspace, $srcAbsPath, $destAbsPath, $removeExisting )

copyNode() public method

{@inheritDoc}
public copyNode ( $srcAbsPath, $dstAbsPath, $srcWorkspace = null )

createNodeJsop() protected method

create the node markup and a list of value dispatches for multivalue properties
protected createNodeJsop ( string $path, array $properties ) : string
$path string path to the current node with the last path segment being the node name
$properties array of this node
return string the xml for the node

createWorkspace() public method

{@inheritDoc}
public createWorkspace ( $name, $srcWorkspace = null )

deleteItem() protected method

Record that we need to delete the item at $path
protected deleteItem ( string $path )
$path string path to node or property

deleteNodeImmediately() public method

{@inheritDoc}
public deleteNodeImmediately ( $path )

deleteNodes() public method

{@inheritDoc}
public deleteNodes ( array $operations )
$operations array

deleteProperties() public method

{@inheritDoc}
public deleteProperties ( array $operations )
$operations array

deletePropertyImmediately() public method

{@inheritDoc}
public deletePropertyImmediately ( $path )

deleteWorkspace() public method

public deleteWorkspace ( $name )

encodeAndValidatePathForDavex() protected method

This is to be used in the Davex headers. The XML requests can cope with unencoded stuff
protected encodeAndValidatePathForDavex ( string $path ) : string
$path string to check
return string the cleaned path

fetchEventData() public method

Internal method to fetch event data.
public fetchEventData ( $date ) : array
$date
return array hashmap with 'data' containing unfiltered DOM of xml atom feed of events, 'nextMillis' is the next timestamp if there are more events to be found, false otherwise.

finishSave() public method

{@inheritDoc}
public finishSave ( )

forceHttpVersion10() public method

Set to true to force HTTP version 1.0
Deprecation: use addCurlOptions([CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0]) instead
public forceHttpVersion10 ( $forceHttpVersion10 = true )

generateLockFromDavResponse() protected method

Extract the information from a LOCK DAV response and create the corresponding Lock object.
protected generateLockFromDavResponse ( DOMElement $response, boolean $sessionOwning = false, string $path = null ) : Lock
$response DOMElement
$sessionOwning boolean whether the current session is owning the lock (aka we created it in this request)
$path string the owning node path, if we created this node
return Jackalope\Lock\Lock

getAccessibleWorkspaceNames() public method

{@inheritDoc}

getBinaryStream() public method

{@inheritDoc}
public getBinaryStream ( $path )

getCurl() protected method

protected getCurl ( )

getEvents() public method

{@inheritDoc}
public getEvents ( $date, PHPCR\Observation\EventFilterInterface $filter, PHPCR\SessionInterface $session )
$filter PHPCR\Observation\EventFilterInterface
$session PHPCR\SessionInterface

getMimePart() protected method

protected getMimePart ( $name, $value, $mime_boundary )

getNamespaces() public method

{@inheritDoc}
public getNamespaces ( )

getNode() public method

{@inheritDoc}
public getNode ( $path )

getNodeByIdentifier() public method

{@inheritDoc}
public getNodeByIdentifier ( $uuid )

getNodePathForIdentifier() public method

{@inheritDoc}
public getNodePathForIdentifier ( $uuid, $workspace = null )

getNodeReferences() protected method

protected getNodeReferences ( string $path, string $name = null, boolean $weak_reference = false ) : array
$path string the path for which we need the references
$name string the name of the referencing properties or null for all
$weak_reference boolean whether to get weak or strong references
return array list of paths to nodes that reference $path

getNodeTypes() public method

{@inheritDoc}
public getNodeTypes ( $nodeTypes = [] )

getNodes() public method

{@inheritDoc}
public getNodes ( $paths, $query = ':include' )

getNodesByIdentifier() public method

{@inheritDoc}
public getNodesByIdentifier ( $identifiers )

getPermissions() public method

{@inheritDoc}
public getPermissions ( $path )

getProperty() public method

{@inheritDoc}
public getProperty ( $path )

getReferences() public method

{@inheritDoc}
public getReferences ( $path, $name = null )

getRepositoryDescriptors() public method

{@inheritDoc}

getRequest() protected method

Makes sure there is an open curl connection.
protected getRequest ( $method, $uri, $addWorkspacePathToUri = true ) : Request
return Request The Request

getRequiredDomElementByTagNameNS() protected method

If the element is not found and $errorMessage is set, then a RepositoryException is thrown. If the element is not found and $errorMessage is empty, then false is returned.
protected getRequiredDomElementByTagNameNS ( DOMNode $dom, string $namespace, string $element, string $errorMessage = '' ) : boolean | DOMNode
$dom DOMNode The DOM element which content should be searched
$namespace string The namespace of the searched element
$element string The name of the searched element
$errorMessage string The error message in case the element is not found
return boolean | DOMNode

getSupportedQueryLanguages() public method

{@inheritDoc}

getUserData() public method

public getUserData ( ) : mixed
return mixed null or string

getWeakReferences() public method

{@inheritDoc}
public getWeakReferences ( $path, $name = null )

getWorkspaceUri() public method

Return the URL to the workspace determined during login
public getWorkspaceUri ( ) : null | string
return null | string

isLocked() public method

{@inheritDoc}
public isLocked ( $absPath )

isStringValid() protected method

If occurrence is found, returns false, otherwise true. Invalid characters were taken from this list: http://en.wikipedia.org/wiki/Valid_characters_in_XML#XML_1.0 Uses regexp mentioned here: http://stackoverflow.com/a/961504
protected isStringValid ( $string ) : boolean
$string string value
return boolean true if string is OK, false otherwise.

lockNode() public method

{@inheritDoc}
public lockNode ( $absPath, $isDeep, $isSessionScoped, $timeoutHint = PHP_INT_MAX, $ownerInfo = null )

login() public method

{@inheritDoc}
public login ( PHPCR\CredentialsInterface $credentials = null, $workspaceName = null )
$credentials PHPCR\CredentialsInterface

logout() public method

{@inheritDoc}
public logout ( )

moveNodeImmediately() public method

{@inheritDoc}
public moveNodeImmediately ( $srcAbsPath, $dstAbsPath )

moveNodes() public method

{@inheritDoc}
public moveNodes ( array $operations )
$operations array

parseTimeout() protected method

The timeout value follows the syntax defined in RFC2518: Timeout Header. Here we just parse the values in the form "Second-XXXX" or "Infinite". Any other value will produce an error. The function returns the unix epoch timestamp for the second when this lock will expire in case of normal timeout, or PHP_INT_MAX in case of an "Infinite" timeout.
protected parseTimeout ( string $timeoutValue ) : integer
$timeoutValue string The timeout in seconds or PHP_INT_MAX for infinite
return integer the expire timestamp to be used with Lock::setExpireTime, that is when this lock expires in seconds since 1970 or null for inifinite

prepareSave() public method

{@inheritDoc}
public prepareSave ( )

propertyToJsopString() protected method

This method is used when building a JSOP of the properties
protected propertyToJsopString ( Property $property ) : mixed | string
$property Jackalope\Property
return mixed | string

query() public method

{@inheritDoc}
public query ( Query $query )
$query Jackalope\Query\Query

registerNamespace() public method

{@inheritDoc}
public registerNamespace ( $prefix, $uri )

registerNodeTypesCnd() public method

{@inheritDoc}
public registerNodeTypesCnd ( $cnd, $allowUpdate )

removeVersion() public method

{@inheritDoc}
public removeVersion ( $versionPath, $versionName )

removeVersionLabel() public method

public removeVersionLabel ( $versionPath, $label )

reorderChildren() public method

{@inheritDoc}
public reorderChildren ( Node $node )
$node Jackalope\Node

restoreItem() public method

{@inheritDoc}
public restoreItem ( $removeExisting, $versionPath, $path )

rollbackSave() public method

{@inheritDoc}
public rollbackSave ( )

sendExpect() public method

This is a Jackrabbit Davex specific option.
public sendExpect ( boolean $send = true )
$send boolean Whether to send the header or not

setCheckLoginOnServer() public method

Will improve error reporting at the cost of some round trips.
public setCheckLoginOnServer ( $bool )

setJsopBody() protected method

protected setJsopBody ( $value, $key = ":diff", $type = null )

setNodeTypeManager() public method

{@inheritDoc}
public setNodeTypeManager ( $nodeTypeManager )

setUserData() public method

{@inheritDoc}
public setUserData ( $userData )

storeNodes() public method

{@inheritDoc}
public storeNodes ( array $operations )
$operations array

stripServerRootFromUri() protected method

remove the server and workspace part from an uri, leaving the absolute path inside the current workspace
protected stripServerRootFromUri ( string $uri ) : string
$uri string a full uri including the server path, workspace and jcr%3aroot
return string absolute path in the current work space

unlock() public method

{@inheritDoc}
public unlock ( $absPath, $lockToken )

unregisterNamespace() public method

{@inheritDoc}
public unregisterNamespace ( $prefix )

updateLastModified() protected method

Note that we can drop this if this jackrabbit issue ever gets implemented https://issues.apache.org/jira/browse/JCR-2233
protected updateLastModified ( Node $node )
$node Jackalope\Node

updateNode() public method

{@inheritDoc}
public updateNode ( Node $node, $srcWorkspace )
$node Jackalope\Node

updateProperties() public method

{@inheritDoc}
public updateProperties ( Node $node )
$node Jackalope\Node

Property Details

$checkLoginOnServer protected_oe property

Check if an initial PROPFIND should be send to check if repository exists This is according to the JCR specifications and set to true by default
See also: setCheckLoginOnServer
protected bool $checkLoginOnServer
return boolean

$credentials protected_oe property

Set once login() has been executed and may not be changed later on.
protected SimpleCredentials,PHPCR $credentials
return PHPCR\SimpleCredentials

$curl protected_oe property

The cURL resource handle
protected curl,Jackalope\Transport\Jackrabbit $curl
return Jackalope\Transport\Jackrabbit\curl

$defaultHeaders protected_oe property

A list of additional HTTP headers to be sent on each request
protected array[]string $defaultHeaders
return array[]string

$descriptors protected_oe property

This is our exception to the rule that nothing may be cached in transport.
protected $descriptors

$factory protected_oe property

The factory to instantiate objects
protected FactoryInterface,Jackalope $factory
return Jackalope\FactoryInterface

$jsopBody protected_oe property

protected $jsopBody

$nodeTypeManager protected_oe property

protected NodeTypeManager,Jackalope\NodeType $nodeTypeManager
return Jackalope\NodeType\NodeTypeManager

$sendExpect protected_oe property

Send Expect: 100-continue header
protected $sendExpect

$server protected_oe property

i.e http://localhost:8080/server/ constructor ensures the trailing slash /
protected string $server
return string

$typeXmlConverter protected_oe property

protected NodeTypeXmlConverter,Jackalope\NodeType $typeXmlConverter
return Jackalope\NodeType\NodeTypeXmlConverter

$userData protected_oe property

protected $userData

$valueConverter protected_oe property

protected ValueConverter,PHPCR\Util $valueConverter
return PHPCR\Util\ValueConverter

$workspace protected_oe property

Set once login() has been executed and may not be changed later on.
protected string $workspace
return string

$workspaceUri protected_oe property

"$server/$workspace" without trailing slash
protected string $workspaceUri
return string

$workspaceUriRoot protected_oe property

"$server/$workspace/jcr%3aroot (make sure you never hardcode the jcr%3aroot, its ugly)
protected string $workspaceUriRoot
return string