public function testSplitUriNonString()
 {
     $this->setExpectedException('InvalidArgumentException', '$uri should be a string or EasyRdf_Resource');
     EasyRdf_Namespace::splitUri($this);
 }
Example #2
0
 /**
  * Return a SPARQL representation of another resource
  * We have to do this because other resource does not always extend the EasySpinRdf_Resource element
  * @param $resource
  * @param $concat
  * @return string
  * @todo Change the EasyRdf type mapper to define a default resource class and use a default getSparql method
  */
 public function resourceToSparql($resource, $concat = " ")
 {
     // if the resource is a collection, we concat sparql with the $concat param
     if (is_a($resource, 'EasyRdf_Collection')) {
         $resources = array();
         foreach ($resource as $item) {
             $resources[] = $this->resourceToSparql($item);
         }
         return join($concat, $resources);
     }
     // if the resource implement getSparql method, just use it
     if (method_exists($resource, 'getSparql')) {
         return $resource->getSparql();
     }
     // if the resource is a literal return its value
     if (is_a($resource, 'EasyRdf_Literal')) {
         $value = $resource->getValue();
         return is_int($value) ? $value : '"' . $value . '"';
     }
     // if the resource has a sp:varName property, use it as a variable
     if ($varName = $resource->get('sp:varName')) {
         return "?" . $varName->getValue();
     }
     // if the resource is a bnode, lets adapt it to SPIN specifications
     if ($resource->isBNode()) {
         return '?' . substr($resource->getUri(), 2);
     }
     list($prefix, $suffix) = \EasyRdf_Namespace::splitUri($resource);
     if (in_array($prefix, array('sp', 'spin')) && $suffix[0] == "_") {
         $resource = '?' . substr($suffix, 1);
     } elseif (\EasyRdf_Namespace::shorten($resource)) {
         $resource = \EasyRdf_Namespace::shorten($resource);
     } else {
         $resource = "<" . $resource . ">";
     }
     return $resource;
 }