Initialize basic information common to nodes and properties
protected __construct ( jackalope\FactoryInterface $factory, string $path, jackalope\Session $session, |
||
$factory | jackalope\FactoryInterface | the object factory |
$path | string | The normalized and absolute path to this item |
$session | jackalope\Session | |
$objectManager | ||
$new | boolean | can be set to true to tell the object that it has been created locally |
/** * 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; } } } }
/** * Create a property, either from server data or locally * * To indicate a property has newly been created locally, make sure to pass * true for the $new parameter. In that case, you should pass an empty array * for $data and use setValue afterwards to let the type magic be handled. * Then multivalue is determined on setValue * * For binary properties, the value is the length of the data(s), not the * data itself. * * @param FactoryInterface $factory the object factory * @param array $data array with fields <tt>type</tt> (integer or string * from PropertyType) and <tt>value</tt> (data for creating the * property value - array for multivalue property) * @param string $path the absolute path of this item * @param Session $session the session instance * @param ObjectManager $objectManager the objectManager instance - the caller has to take * care of registering this item with the object manager * @param boolean $new optional: set to true to make this property aware * its not yet existing on the server. defaults to false */ public function __construct(FactoryInterface $factory, array $data, $path, Session $session, ObjectManager $objectManager, $new = false) { parent::__construct($factory, $path, $session, $objectManager, $new); $this->wrapBinaryStreams = $session->getRepository()->getDescriptor(Repository::JACKALOPE_OPTION_STREAM_WRAPPER); if (empty($data) && $new) { return; } if (!isset($data['value'])) { throw new InvalidArgumentException("Can't create property at {$path} without any data"); } if (isset($data['type']) && PropertyType::UNDEFINED !== $data['type']) { $type = $data['type']; if (is_string($type)) { $type = PropertyType::valueFromName($type); } elseif (!is_numeric($type)) { // @codeCoverageIgnoreStart throw new RepositoryException("INTERNAL ERROR -- No valid type specified ({$type})"); // @codeCoverageIgnoreEnd } else { //sanity check. this will throw InvalidArgumentException if $type is not a valid type PropertyType::nameFromValue($type); } } else { // we are creating a node $type = PropertyType::determineType(is_array($data['value']) ? reset($data['value']) : $data['value']); } $this->type = $type; if ($type == PropertyType::BINARY && !$new) { // reading a binary property from backend, we do not get the stream immediately but just the size if (is_array($data['value'])) { $this->isMultiple = true; } $this->length = $data['value']; $this->value = null; return; } if (is_array($data['value'])) { $this->isMultiple = true; $this->value = array(); foreach ($data['value'] as $value) { $this->value[] = PropertyType::convertType($value, $type); } } elseif (null !== $data['value']) { $this->value = PropertyType::convertType($data['value'], $type); } else { // @codeCoverageIgnoreStart throw new RepositoryException('INTERNAL ERROR -- data[value] may not be null'); // @codeCoverageIgnoreEnd } }
/** * Create a new node instance with data from the storage layer * * This is only to be called by the Factory::get() method even inside the * Jackalope implementation to allow for custom implementations of Nodes. * * @param FactoryInterface $factory the object factory * @param array $rawData in the format as returned from TransportInterface::getNode * @param string $path the absolute path of this node * @param Session $session * @param ObjectManager $objectManager * @param boolean $new set to true if this is a new node being created. * Defaults to false which means the node is loaded from storage. * * @see TransportInterface::getNode() * * @private */ public function __construct(FactoryInterface $factory, $rawData, $path, Session $session, ObjectManager $objectManager, $new = false) { parent::__construct($factory, $path, $session, $objectManager, $new); $this->isNode = true; $this->parseData($rawData, false); }
/** * Create a property, either from server data or locally * * To indicate a property has newly been created locally, make sure to pass * true for the $new parameter. In that case, you should pass an empty array * for $data and use setValue afterwards to let the type magic be handled. * Then multivalue is determined on setValue * * For binary properties, the value is the length of the data(s), not the * data itself. * * @param FactoryInterface $factory the object factory * @param array $data array with fields <tt>type</tt> * (integer or string from PropertyType) and <tt>value</tt> (data for * creating the property value - array for multivalue property) * @param string $path the absolute path of this item * @param Session $session the session instance * @param ObjectManager $objectManager the objectManager instance - the * caller has to take care of registering this item with the object * manager * @param boolean $new optional: set to true to make this property aware * its not yet existing on the server. defaults to false * * @throws RepositoryException * @throws \InvalidArgumentException */ public function __construct(FactoryInterface $factory, array $data, $path, Session $session, ObjectManager $objectManager, $new = false) { parent::__construct($factory, $path, $session, $objectManager, $new); $this->wrapBinaryStreams = $session->getRepository()->getDescriptor(Repository::JACKALOPE_OPTION_STREAM_WRAPPER); if (null === $data && $new) { return; } if (!isset($data['value'])) { throw new InvalidArgumentException("Can't create property at {$path} without any data"); } $this->_setValue($data['value'], isset($data['type']) ? $data['type'] : PropertyType::UNDEFINED, true); }