/** * Creates a proxy object for a Everyman node or relationship. * * This creates a proxy object for a Everyman relationship, given the meta repository and class name * * @param \Everyman\Neo4j\Node|\Everyman\Neo4j\Relationship $entity The entity to create a proxy of. * @param string $class The class name. * @param \LRezek\Arachnid\Meta\Repository $repository The meta repository. * @param null $callback The load callback to use for start/end nodes. * @return mixed The proxy object. */ function fromEntity($entity, $class, $repository, $callback = null) { $meta = $repository->fromClass($class); //Create the proxy object and set the meta, node, and load callback $proxy = $this->createProxy($meta); $proxy->__setMeta($meta); $proxy->__setEntity($entity); $proxy->__setLoadCallback($callback); $proxy->__setEntity($entity); //Set the primary key property in the object to the node id. $pk = $meta->getPrimaryKey(); $pk->setValue($proxy, $entity->getId()); $proxy->__addHydrated($pk->getName()); //Set the properties foreach ($meta->getProperties() as $property) { $name = $property->getName(); //If the value isn't null in the DB, set the property to the correct value if ($value = $entity->getProperty($name)) { $property->setValue($proxy, $value); $proxy->__addHydrated($name); } } return $proxy; }
function testObjectProperty() { $repo = new MetaRepository(); $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats'); $usr = new Entity\UserDifferentPropertyFormats(); $testClass = new ClassParamTestClass(1); $usr->setClass($testClass); $encoded = serialize($testClass); foreach ($meta->getProperties() as $prop) { if ($prop->getFormat() == "object") { //Test the get if ($prop->getValue($usr) != $encoded) { $this->fail(); } //Test the set $tc = serialize(new ClassParamTestClass(2)); $prop->setValue($usr, $tc); if ($usr->getClass() != unserialize($tc)) { $this->fail(); } return; } } $this->fail(); }