示例#1
0
 /** Work out the class to instantiate a resource as
  *  @ignore
  */
 protected function classForResource($uri)
 {
     $rdfType = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type';
     if (isset($this->index[$uri][$rdfType])) {
         foreach ($this->index[$uri][$rdfType] as $type) {
             if ($type['type'] == 'uri' or $type['type'] == 'bnode') {
                 $class = TypeMapper::get($type['value']);
                 if ($class != null) {
                     return $class;
                 }
             }
         }
     }
     // Parsers don't typically add a rdf:type to rdf:List, so we have to
     // do a bit of 'inference' here using properties.
     if ($uri == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#nil' or isset($this->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#first']) or isset($this->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#rest'])) {
         return 'EasyRdf\\Collection';
     }
     return TypeMapper::getDefaultResourceClass();
 }
示例#2
0
 /**
  * @param object $entity
  * @param string $field
  * @return mixed
  */
 protected function saveField($entity, $field)
 {
     $meta = $this->getMetadata($entity);
     $propMapping = $meta->getFieldMapping($field);
     return $this->typeMapper->save($meta->getFieldValue($entity, $field), $propMapping['type']);
 }
示例#3
0
    /**
     * Sets the default resource class
     *
     * @param  string $class The resource full class name (e.g. \MyCompany\Resource)
     *
     * @throws \InvalidArgumentException
     * @return string           The default Resource class
     */
    public static function setDefaultResourceClass($class)
    {
        if (!is_string($class) or $class == null or $class == '') {
            throw new \InvalidArgumentException("\$class should be a string and cannot be null or empty");
        }
        if (!class_exists($class)) {
            throw new \InvalidArgumentException("Given class should be an existing class");
        }
        $ancestors = class_parents($class);
        if ($class != 'EasyRdf\\Resource' && (empty($ancestors) || !in_array('EasyRdf\\Resource', $ancestors))) {
            throw new \InvalidArgumentException("Given class should have EasyRdf\\Resource as an ancestor");
        }
        return self::$defaultResourceClass = $class;
    }
}
/*
   Register default set of mapped types
*/
TypeMapper::set('rdf:Alt', 'EasyRdf\\Container');
TypeMapper::set('rdf:Bag', 'EasyRdf\\Container');
TypeMapper::set('rdf:List', 'EasyRdf\\Collection');
TypeMapper::set('rdf:Seq', 'EasyRdf\\Container');