Skip to content

Commit

Permalink
Merge branch 'master' of github.com:jackalope/jackalope
Browse files Browse the repository at this point in the history
  • Loading branch information
ebi committed Mar 18, 2010
2 parents 1e4884c + 802f41d commit a284bb0
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 65 deletions.
18 changes: 9 additions & 9 deletions src/jackalope/Item.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
<?php
class jackalope_Item implements PHPCR_ItemInterface {

protected $session;

protected $new = true;
protected $modified = false;

protected $path;
protected $name;
protected $parent;
protected $depth;
protected $isNode = false;
protected $uuid = null;

public function __construct($rawData, $path, $session, $objectManager) {
$this->path = $path;
$this->session = $session;

$path = explode('/', $path);
$this->depth = count($path) - 1;
$this->name = array_pop($path);
$this->parent = implode('/', $path);

if (isset($rawData->{'jcr:uuid'})) {
$this->uuid = $rawData->{'jcr:uuid'};
unset($rawData->{'jcr:uuid'});
}
}

/**
* Returns the normalized absolute path to this item.
*
Expand Down Expand Up @@ -233,7 +233,7 @@ public function accept(PHPCR_ItemVisitorInterface $visitor) {
* @api
*/
public function refresh($keepChanges) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand All @@ -258,6 +258,6 @@ public function refresh($keepChanges) {
* @api
*/
public function remove() {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}
}
4 changes: 2 additions & 2 deletions src/jackalope/NamespaceRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(jackalope_TransportInterface $transport) {
*/
public function registerNamespace($prefix, $uri) {
$this->checkPrefix($prefix);
throw new jackalope_NotImplementedException('Level 2');
throw new jackalope_NotImplementedException('Write');
//first try putting the stuff in backend, and only afterwards update lokal info
//validation happens on the server, see second request trace below
/*
Expand Down Expand Up @@ -123,7 +123,7 @@ public function unregisterNamespace($prefix) {
//defaultNamespaces would throw an exception in checkPrefix already
throw new PHPCR_NamespaceException("Prefix $prefix is not currently registered");
}
throw new jackalope_NotImplementedException('Level 2');
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down
38 changes: 19 additions & 19 deletions src/jackalope/Node.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php

class jackalope_Node extends jackalope_Item implements PHPCR_NodeInterface {

protected $index = 1;
protected $primaryType;

protected $properties = array();
protected $nodes = array();

public function __construct($rawData, $path, $session, $objectManager) {
parent::__construct($rawData, $path, $session, $objectManager);
$this->isNode = true;

foreach ($rawData as $key => $value) {
if (is_object($value)) {
array_push($this->nodes, $key);
} else {
if ( 0 === strpos($key, ':')) continue; //It's a property type

switch ($key) {
case 'jcr:index':
$this->index = $value;
Expand All @@ -29,7 +29,7 @@ public function __construct($rawData, $path, $session, $objectManager) {
}
}
}

/**
* Creates a new node at $relPath.
*
Expand Down Expand Up @@ -65,7 +65,7 @@ public function __construct($rawData, $path, $session, $objectManager) {
* @api
*/
public function addNode($relPath, $primaryNodeTypeName = NULL, $identifier = NULL) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ public function addNode($relPath, $primaryNodeTypeName = NULL, $identifier = NUL
* @api
*/
public function orderBefore($srcChildRelPath, $destChildRelPath) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ public function orderBefore($srcChildRelPath, $destChildRelPath) {
* @api
*/
public function setProperty($name, $value, $type = NULL) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -377,7 +377,7 @@ public function getReferences($name = NULL) {
* If the name parameter is null then all referring WEAKREFERENCE are returned
* regardless of name.
*
* Some level 2 implementations may only return properties that have been
* Some write implementations may only return properties that have been
* saved (in a transactional setting this includes both those properties that
* have been saved but not yet committed, as well as properties that have
* been committed). Other level 2 implementations may additionally return
Expand Down Expand Up @@ -516,7 +516,7 @@ public function isNodeType($nodeTypeName) {
* @api
*/
public function setPrimaryType($nodeTypeName) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -550,7 +550,7 @@ public function setPrimaryType($nodeTypeName) {
* @api
*/
public function addMixin($mixinName) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand All @@ -569,7 +569,7 @@ public function addMixin($mixinName) {
* @api
*/
public function removeMixin($mixinName) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand All @@ -593,7 +593,7 @@ public function removeMixin($mixinName) {
* @api
*/
public function canAddMixin($mixinName) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -639,7 +639,7 @@ public function getDefinition() {
* @api
*/
public function update($srcWorkspace) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -690,7 +690,7 @@ public function getSharedSet() {
* @api
*/
public function removeSharedSet() {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand All @@ -708,7 +708,7 @@ public function removeSharedSet() {
* @api
*/
public function removeShare() {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand Down Expand Up @@ -758,7 +758,7 @@ public function isLocked() {
* @api
*/
public function followLifecycleTransition($transition) {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}

/**
Expand All @@ -770,6 +770,6 @@ public function followLifecycleTransition($transition) {
* @api
*/
public function getAllowedLifecycleTransitions() {
throw new jackalope_NotImplementedException();
throw new jackalope_NotImplementedException('Write');
}
}
16 changes: 16 additions & 0 deletions src/jackalope/NodeIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Allows easy iteration through a list of Nodes with nextNode as well as a skip method
* inherited from RangeIterator.
*/
class jackalope_NodeIterator extends jackalope_RangeIterator implements PHPCR_NodeIteratorInterface {
/**
* Returns the next Node in the iteration.
*
* @return PHPCR_NodeInterface
* @throws OutOfBoundsException if the iterator contains no more elements.
*/
public function nextNode() {
return $this->next();
}
}
17 changes: 12 additions & 5 deletions src/jackalope/ObjectManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
class jackalope_ObjectManager {
protected $session;
protected $transport;

protected $objectsByPath;
protected $objectsByUuid;

public function __construct(jackalope_TransportInterface $transport, PHPCR_SessionInterface $session) {

public function __construct(jackalope_TransportInterface $transport,
PHPCR_SessionInterface $session) {
$this->transport = $transport;
$this->session = $session;
}


/**
* Get the node identified by an absolute path.
* Uses the factory to instantiate Node
*
* @param string $path The absolute path of the node to create
* @return jackalope_Node
*/
public function getNodeByPath($path) {
if (empty($this->objectsByPath[$path])) {
$data = $this->transport->getItem($path);
$this->objectsByPath[$path] = jackalope_Factory::get(
'Node',
array(
Expand Down
16 changes: 16 additions & 0 deletions src/jackalope/PropertyIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* Allows easy iteration through a list of Properties with nextProperty as well as a skip method
* inherited from RangeIterator.
*/
class jackalope_PropertyIterator extends jackalope_RangeIterator implements PHPCR_PropertyIteratorInterface {
/**
* Returns the next Property in the iteration.
*
* @return PHPCR_PropertyInterface
* @throws OutOfBoundsException if the iterator contains no more elements.
*/
public function nextProperty() {
return $this->next();
}
}
65 changes: 65 additions & 0 deletions src/jackalope/RangeIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Extends Iterator with the skip, getSize and getPosition methods. The base
* iterator of all type-specific iterators in the JCR and its sub packages.
*/
class jackalope_RangeIterator implements PHPCR_RangeIteratorInterface {
protected $items;
protected $pos;
public function __construct($items) {
$this->items = $items;
$this->pos = 0;
}

/**
* Skip a number of elements in the iterator.
*
* @param integer $skipNum the non-negative number of elements to skip
* @throws OutOfBoundsException if skipped past the last element in the iterator.
*/
public function skip($skipNum) {
if ($this->pos + $skipNum >= $this->getSize()) {
throw new OutOfBoundsException('skipping past end');
}
$this->pos += $skipNum;
}

/**
* Returns the total number of of items available through this iterator.
*
* For example, for some node $n, $n->getNodes()->getSize() returns the
* number of child nodes of $n visible through the current Session.
*
* In some implementations precise information about the number of elements may
* not be available. In such cases this method must return -1. API clients will
* then be able to use RangeIterator->getNumberRemaining() to get an
* estimate on the number of elements.
*
* @return integer
*/
public function getSize() {
return size($this->items);
}

/**
* Returns the current position within the iterator. The number
* returned is the 0-based index of the next element in the iterator,
* i.e. the one that will be returned on the subsequent next() call.
*
* Note that this method does not check if there is a next element,
* i.e. an empty iterator will always return 0.
*
* @return integer
*/
public function getPosition() {
return $this->pos;
}

/** php has no strong typing, so we can just do this here */
protected function next() {
if ($this->pos >= $this->getSize()) {
throw new OutOfBoundsException('skipping past end');
}
return $this->items[$this->pos++];
}
}
Loading

0 comments on commit a284bb0

Please sign in to comment.