/** * Proxy creation to a cypher query that does what we want * * @param Client $client * @param Node $node * @param array $labels * @param boolean $remove */ public function __construct(Client $client, Node $node, $labels, $remove = false) { if (!$client->hasCapability(Client::CapabilityLabel)) { throw new \RuntimeException('The connected Neo4j version does not have label capability'); } $nodeId = $node->getId(); if (!is_numeric($nodeId)) { throw new \InvalidArgumentException("Cannot set labels on an unsaved node"); } if (!$labels) { throw new \InvalidArgumentException("No labels given to set on node"); } $labelSet = implode(':', array_map(function ($label) { if (!$label instanceof Label) { throw new \InvalidArgumentException("Cannot set a non-label"); } $name = str_replace('`', '``', $label->getName()); return "`{$name}`"; }, $labels)); $setCommand = $remove ? 'REMOVE' : 'SET'; $query = "START n=node({nodeId}) {$setCommand} n:{$labelSet} RETURN labels(n) AS labels"; $params = array('nodeId' => $nodeId); $cypher = new Query($client, $query, $params); parent::__construct($client, $cypher); }
/** * @param Node $node * @param Repository $repository * @param callable $loadCallback * @return mixed */ function fromNode(Node $node, Repository $repository, \Closure $loadCallback) { $class = $node->getProperty('class'); $meta = $repository->fromClass($class); $proxyClass = $meta->getProxyClass(); $proxy = $this->createProxy($meta); $proxy->__setMeta($meta); $proxy->__setNode($node); $proxy->__setLoadCallback($loadCallback); $pk = $meta->getPrimaryKey(); $pk->setValue($proxy, $node->getId()); $proxy->__addHydrated($pk->getName()); foreach ($meta->getProperties() as $property) { $name = $property->getName(); if (null !== ($value = $node->getProperty($name))) { $property->setValue($proxy, $value); $proxy->__addHydrated($name); } } foreach ($meta->getManyToManyRelations() as $property) { if ($property->isWriteOnly()) { $proxy->__addHydrated($property->getName()); } } return $proxy; }
public function getByClientNode(Neo4j\Node $client_node) { foreach ($client_node->getLabels() as $label) { if ($this->hasNode($label->getName())) { return $this->getNode($label->getName()); } } }
public static function label_names(Everyman\Neo4j\Node $node) { $label_names = array(); foreach ($node->getLabels() as $label) { array_push($label_names, $label->getName()); } return $label_names; }
public static function fromArray(Node $node) { $tag = new Tag(); $tag->id = $node->getId(); $tag->tagcontent = $node->getProperty('tagcontent'); $tag->node = $node; return $user; }
public function envelopes(Neo4j\Node $client_node) { $schema_name = $this->getName(); // Check that the client node matches the schema. foreach ($client_node->getLabels() as $label) { if ($label->getName() === $schema_name) { return true; } } return false; }
/** * Gather the properties of a Node including its id. * * @param \Everyman\Neo4j\Node $node * @return array */ public function getNodeAttributes(Node $node) { // Extract the properties of the node $attributes = $node->getProperties(); // Add the node id to the attributes since \Everyman\Neo4j\Node // does not consider it to be a property, it is treated differently // and available through the getId() method. $attributes[$this->model->getKeyName()] = $node->getId(); return $attributes; }
/** * @param Node $node * @return Node */ public function load($node) { if (!isset($this->loadedNodes[$node->getId()])) { $em = $this; $entity = $this->proxyFactory->fromNode($node, $this->metaRepository, function ($node) use($em) { return $em->load($node); }); $this->loadedNodes[$node->getId()] = $entity; $this->nodes[$this->getHash($entity)] = $node; } return $this->loadedNodes[$node->getId()]; }
/** * Loads a node using a proxy. * * Loads a node using a proxy, and stores it in the appropriate places in the entity manager. * * @param \Everyman\Neo4J\Node $node The node to load. * @return mixed The entity itself. */ public function loadNode($node) { //If the node isn't already loaded if (!isset($this->nodeProxyCache[$node->getId()])) { //Get the nodes class name (from label) $labels = $this->client->getLabels($node); $class = $labels[0]->getName(); //Create a proxy entity $entity = $this->proxyFactory->fromNode($node, $this->metaRepository, $class); $this->nodeProxyCache[$node->getId()] = $entity; $this->everymanNodeCache[$this->getHash($entity)] = $node; } return $this->nodeProxyCache[$node->getId()]; }
/** * Hydrate a Collection from an Neo4J Node * * @param \Everyman\Neo4j\Node $row a single row from result set to map. * @return Collection */ protected function nodeToCollection(\EveryMan\Neo4j\Node $row) { // Or we map a single record to a Spider Record $collection = new Collection(); foreach ($row->getProperties() as $key => $value) { $collection->add($key, $value); } //handle labels $labels = $row->getLabels(); if (!empty($labels)) { $collection->add(['meta.label' => $labels[0]->getName(), 'label' => $labels[0]->getName()]); } $collection->add(['meta.id' => $row->getId(), 'id' => $row->getId()]); $collection->protect('meta'); $collection->protect('id'); $collection->protect('label'); return $collection; }
/** * Create User object from Node * * @param Node $node User node * @return User */ protected static function fromNode(Node $node) { $user = new User(); $user->id = $node->getId(); $user->username = $node->getProperty('username'); $user->firstname = $node->getProperty('firstname'); $user->lastname = $node->getProperty('lastname'); $user->node = $node; return $user; }
/** * Creates Content instance from a content node * * @param Node $node Content node * @param string $username Username for post * @param string $owner Content owner * @return Content */ protected static function createFromNode(Node $node, $username = null, $owner = false) { $content = new Content(); $content->node = $node; $content->nodeId = $node->getId(); $content->contentId = $node->getProperty('contentId'); $content->title = $node->getProperty('title'); $content->url = $node->getProperty('url'); $content->tagstr = $node->getProperty('tagstr'); $content->timestamp = gmdate("F j, Y g:i a", $node->getProperty('timestamp')); $content->owner = $owner; $content->userNameForPost = $username; return $content; }