Пример #1
0
 /**
  * @param $className
  * @param $uri
  *
  * @return Resource
  *
  * @throws Exception
  */
 public function constructUri($uri, $className = null)
 {
     $uri = $this->_rm->getNamespaceRegistry()->expand($uri);
     $body = '<' . $uri . '>' . ($className !== null ? ' a ' . $className . ';' : '') . ' ?p ?q';
     /** @var QueryBuilder $qb */
     $qb = $this->_rm->getQueryBuilder();
     $qb->construct($body)->where($body);
     $result = $qb->getQuery()->execute();
     if ($result instanceof Result) {
         $result = $this->resultToGraph($result);
     }
     if (!$this->isEmpty($result)) {
         $resourceClass = null;
         foreach ($result->all($uri, 'rdf:type') as $type) {
             $resourceClass = TypeMapper::get($type->getUri());
             if ($resourceClass !== null) {
                 break;
             }
         }
         if (empty($resourceClass)) {
             $resourceClass = 'Conjecto\\Nemrod\\Resource';
         }
         $resource = $this->resultToResource($uri, $result, $resourceClass);
         if ($resource) {
             $this->registerResource($resource);
         }
         return $resource;
     }
     return;
 }
 /**
  * Transform a resource to an elastica document.
  *
  * @param $uri
  * @param $index
  * @param $type
  *
  * @return Document|null
  */
 public function transform($uri, $index, $type)
 {
     if ($index && $this->serializerHelper->isTypeIndexed($index, $type)) {
         $frame = $this->serializerHelper->getTypeFramePath($index, $type);
         $phpClass = TypeMapper::get($type);
         if (!$phpClass) {
             $phpClass = "EasyRdf\\Resource";
         }
         $jsonLd = $this->jsonLdSerializer->serialize(new $phpClass($uri), $frame, array("includeParentClassFrame" => true));
         $graph = json_decode($jsonLd, true);
         if (!isset($graph['@graph'][0])) {
             return;
         }
         $resource = $graph['@graph'][0];
         $resource['@id'] = $uri;
         $json = json_encode($resource);
         $json = str_replace('@id', '_id', $json);
         $json = str_replace('@type', '_type', $json);
         $index = $this->configManager->getIndexConfiguration($index)->getElasticSearchName();
         return new Document($uri, $json, $type, $index);
     }
     return;
 }
Пример #3
0
 /**
  * @param $type
  *
  * @return BaseResource
  */
 public function create($type = null)
 {
     $className = null;
     if ($type) {
         $className = TypeMapper::get($type);
     }
     if (!$className) {
         $className = TypeMapper::getDefaultResourceClass();
     }
     /** @var BaseResource $resource */
     $resource = new $className($this->nextBNode(), new Graph());
     $resource->addType($type);
     $resource->setRm($this->_rm);
     //storing resource in temp resources array
     $this->tempResources[$resource->getUri()] = $resource;
     $this->evd->dispatch(Events::PostCreate, new ResourceLifeCycleEvent(array('resources' => array($resource))));
     return $resource;
 }
Пример #4
0
 /**
  * @param $phpClass
  */
 public function getRdfClass($phpClass)
 {
     $class = TypeMapper::get($phpClass);
     return $class;
 }
Пример #5
0
 /**
  * @param $type
  *
  * @return string
  */
 public function get($type)
 {
     return TypeMapper::get($type);
 }
Пример #6
0
 /**
  * Search parent frame pathes
  * @param $parentClass
  * @param array $parentFrames
  * @return array
  */
 public function getParentFrames($type)
 {
     $parentClasses = $this->filiationBuilder->getParentTypes($type);
     $parentFrames = array();
     if (!$parentClasses || empty($parentClasses)) {
         return $parentFrames;
     }
     foreach ($parentClasses as $parentClass) {
         $phpClass = TypeMapper::get($parentClass);
         if ($phpClass) {
             $metadata = $this->metadataFactory->getMetadataForClass($phpClass);
             $frame = $metadata->getFrame();
             if ($frame) {
                 $parentFrames[] = $metadata->getFrame();
             }
         }
     }
     return $parentFrames;
 }