Ejemplo n.º 1
0
 /**
  * Get's the possible key used in the typemap for the type
  *
  * @param TypeInterface $type
  * @return string
  */
 protected function getTypeMapKey(TypeInterface $type)
 {
     list($prefix, $shortname) = explode(':', $type->getRdfType());
     $ns = $type->getVocabularies();
     $ns = $ns[$prefix];
     return $ns . $shortname;
 }
Ejemplo n.º 2
0
 /**
  * {@inheritDoc}
  *
  * Create the object if a class is defined in the typeMap. This class
  * can not know how to set the parent, so if you ever create collection
  * entries, your extending class should handle the parent - it can still
  * call this method to create the basic object, just omit the parent
  * parameter and then set the parent on the returned value. For an example,
  * see DoctrinePhpcrOdmMapper.
  *
  * Just overwrite if you use a different concept.
  */
 public function prepareObject(TypeInterface $type, $parent = null)
 {
     if ($parent !== null) {
         throw new \Exception('Parent is not null, please extend this method to configure the parent');
     }
     list($prefix, $shortname) = explode(':', $type->getRdfType());
     $ns = $type->getVocabularies();
     $ns = $ns[$prefix];
     $name = $ns.$shortname;
     if (isset($this->typeMap[$name])) {
         $class = $this->typeMap[$name];
         return new $class;
     }
     throw new \Exception('No information on ' . $name);
 }
Ejemplo n.º 3
0
 /**
  * Expand a property name to use full namespace instead of short name,
  * as used in reference fields. Additionally jsonld-encodes that link.
  *
  * @param string $name the name to expand, including namespace
  * @param TypeInterface $type the type context for the vocabulary
  *
  * @return string the jsonld-encoded expanded name
  *
  * @throws \RuntimeException if the prefix is not in the vocabulary of
  *      $type
  */
 private function _expandPropertyName($name, TypeInterface $type)
 {
     $parts = explode(":", $name);
     $vocabularies = $type->getVocabularies();
     if (!isset($vocabularies[$parts[0]])) {
         throw new \RuntimeException('Undefined namespace prefix \'' . $parts[0] . "' in '{$name}'");
     }
     return $this->jsonldEncode($vocabularies[$parts[0]] . $parts[1]);
 }
Ejemplo n.º 4
0
 /**
  * Build the attributes from the property|rel field and any custom attributes
  *
  * @param mixed $child the child element to parse
  * @param \ArrayAccess $childData the child to read field from
  * @param string $field the field to be read, property for properties, rel for collections
  * @param string $identifier to be used in case there is no property field in $child
  * @param TypeInterface $parentType the parent object, i.e. for namespaces
  * @param boolean $add_default_vocabulary flag to tell whether to add vocabulary for
  *      the default namespace.
  *
  * @return array properties
  */
 protected function parseChild($child, $childData, $identifier, TypeInterface $parentType, &$add_default_vocabulary)
 {
     if ($child instanceof PropertyDefinitionInterface) {
         /** @var $child PropertyDefinitionInterface */
         $child->setProperty($this->buildInformation($childData, $identifier, 'property', $add_default_vocabulary));
     } elseif ($child instanceof CollectionDefinitionInterface) {
         /** @var $child CollectionDefinitionInterface */
         $child->setRel($this->buildInformation($childData, $identifier, 'rel', $add_default_vocabulary));
         $child->setRev($this->buildInformation($childData, $identifier, 'rev', $add_default_vocabulary));
         if (isset($childData['childtypes'])) {
             foreach ($childData['childtypes'] as $type) {
                 $expanded = NamespaceHelper::expandNamespace($type, $parentType->getVocabularies());
                 $child->addTypeName($expanded);
             }
         }
     }
     if ($child instanceof NodeInterface) {
         $this->parseNodeInfo($child, $childData);
     }
 }