/** * Never call this method directly, but use createWithParent on your CollectionDefinition * to get a collection tied to concrete data. * * @private * * @param EntityInterface $parent */ public function loadFromParent(EntityInterface $parent) { $this->_children = array(); $object = $parent->getObject(); $parentMapper = $parent->getMapper(); $children = $parentMapper->getChildren($object, $this); // create entities for children foreach ($children as $child) { if (count($this->_typenames) === 1) { $type = $this->_typeFactory->getTypeByRdf(current($this->_typenames)); } else { $type = $this->_typeFactory->getTypeByObject($child); } foreach ($type->getVocabularies() as $prefix => $uri) { $this->setAttribute('xmlns:' . $prefix, $uri); } $this->_children[] = $type->createWithObject($child); } if ($this->_parent->isEditable($object) && sizeof($this->_children) == 0 && count($this->_typenames) == 1) { // create an empty element to allow adding new elements to an empty editable collection $type = $this->_typeFactory->getTypeByRdf(reset($this->_typenames)); $mapper = $type->getMapper(); $object = $mapper->prepareObject($type, $object); $entity = $type->createWithObject($object); if ($entity instanceof NodeInterface) { /** @var $entity NodeInterface */ $entity->setAttribute('style', 'display:none'); } $this->_children[] = $entity; } }
/** * Get the bound entity for this object. The type is determined with * get_class(), unless you explicitly overwrite it by specifying the * identifier parameter. * * @param mixed $object your domain object to wrap into the rdf type * @param string $identifier optional identifier name to override the * class name of your object. * * @return \Midgard\CreatePHP\Entity\EntityInterface|null the bound type of * null if no type is found */ public function getEntity($object, $identifier = null) { if (null == $identifier) { $identifier = get_class($object); } $type = $this->_metadata->getTypeByName($identifier); return $type->createWithObject($object); }
/** * Handle document POST (creation) * * @param Request $request * * @return Response * * @throws AccessDeniedException If the action is not allowed by the access * checker. */ public function postDocumentAction(Request $request) { if (!$this->accessChecker->check($request)) { throw new AccessDeniedException(); } $rdfType = trim($request->request->get('@type'), '<>'); $type = $this->typeFactory->getTypeByRdf($rdfType); $result = $this->restHandler->run($request->request->all(), $type, null, RestService::HTTP_POST); if (!is_null($result)) { $view = View::create($result)->setFormat('json'); return $this->viewHandler->handle($view, $request); } return Response::create('The document was not created', 500); }
public function test_get_setController() { $controller = new Controller(new MockMapper()); $this->factoryMock->expects($this->once())->method('getTypeByName')->with('test')->will($this->returnValue($controller)); $this->assertEquals($controller, $this->manager->getType('test')); }