/**
* Create a new node item.
*
* Parameters are identical to \jackalope\Item
*
* @param array $rawData TODO: document the format of this
*/
public function __construct($factory, $rawData, $path, $session, $objectManager, $new = false)
{
parent::__construct($factory, $path, $session, $objectManager, $new);
$this->isNode = true;
//TODO: determine the index if != 1
foreach ($rawData as $key => $value) {
if (is_object($value)) {
$this->nodes[] = $key;
} else {
// It's probably a property type
if (0 === strpos($key, ':')) {
// It's a binary property and we just got its length
if (is_int($value)) {
$key = substr($key, 1);
$this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::BINARY, 'value' => (string) $value), $this->getChildPath($key), $this->session, $this->objectManager));
}
continue;
}
switch ($key) {
case 'jcr:index':
$this->index = $value;
break;
case 'jcr:primaryType':
$this->primaryType = $value;
$this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::NAME, 'value' => $value), $this->getChildPath('jcr:primaryType'), $this->session, $this->objectManager));
break;
case 'jcr:mixinTypes':
$this->properties[$key] = $this->factory->get('Property', array(array('type' => \PHPCR\PropertyType::NAME, 'value' => $value), $this->getChildPath($key), $this->session, $this->objectManager));
break;
case 'jcr:uuid':
$this->uuid = $value;
break;
//TODO: more special information?
//OPTIMIZE: do not instantiate properties unless needed
//TODO: more special information?
//OPTIMIZE: do not instantiate properties unless needed
default:
//TODO: if we create node locally, $rawData might be a plain array. So far this is not triggered, but its a bit flaky
// parsing of types done according to: http://jackrabbit.apache.org/api/2.1/org/apache/jackrabbit/server/remoting/davex/JcrRemotingServlet.html
$type = isset($rawData->{':' . $key}) ? $rawData->{':' . $key} : Helper::determineType(is_array($value) ? reset($value) : $value);
$this->properties[$key] = $this->factory->get('Property', array(array('type' => $type, 'value' => $value), $this->getChildPath($key), $this->session, $this->objectManager));
break;
}
}
}
}