Skip to content

Commit

Permalink
JACK-40 - Partial commit - First implementation of node.getReferences
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Barsotti committed May 26, 2011
1 parent c4e96d1 commit 77050b9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Jackalope/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ public function getIndex()
*/
public function getReferences($name = null)
{
throw new NotImplementedException();
return $this->objectManager->getReferences($this->path);
}

/**
Expand Down
16 changes: 16 additions & 0 deletions src/Jackalope/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,22 @@ public function registerNodeTypes($types, $allowUpdate)
return $this->transport->registerNodeTypes($types, $allowUpdate);
}

/**
* TODO: Write comment
*/
public function getReferences($path)
{
$references = $this->transport->getReferences($path);
$props = array();

foreach($references as $path) {
// TODO: error checking
$props[] = $this->getPropertyByPath($path);
}

return new \ArrayIterator($props);
}

/**
* Implementation specific way to register node types from cnd with the backend.
*
Expand Down
26 changes: 26 additions & 0 deletions src/Jackalope/Transport/Davex/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,32 @@ public function getBinaryStream($path)
return $stream;
}

/**
* TODO: Write comment
* @param type $path
*/
public function getReferences($path)
{
$request = $this->getRequest(Request::PROPFIND, $path);
$request->setBody($this->buildPropfindRequest(array('dcr:references')));
$request->setDepth(0);
$dom = $request->executeDom();

$references = array();

foreach($dom->getElementsByTagNameNS(self::NS_DCR, 'references') as $node) {
foreach($node->getElementsByTagNameNS(self::NS_DAV, 'href') as $ref) {
$references[] = str_replace($this->workspaceUriRoot, '', urldecode($ref->textContent));
}
}

// var_dump("REQUEST " . str_repeat('-', 120), $request);
// var_dump("RESPONSE " . str_repeat('-', 120), $dom->saveXML());
// var_dump("REFERENCES " . str_repeat('-', 120), $references);

return $references;
}

/**
* Check-in item at path.
*
Expand Down

1 comment on commit 77050b9

@dbu
Copy link
Member

@dbu dbu commented on 77050b9 May 30, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not forget to add methods to Jackalope\TransportInterface when adding public methods to the transport. otherwise we will fail horribly when a different storage layer is used.

Please sign in to comment.