/**
  * @throws \Twig_Error_Loader
  */
 public function testLoad()
 {
     $loader = new JsonLdFrameLoader();
     $loader->addPath(__DIR__ . '/Fixtures', 'namespace');
     $expected = array('@id' => 'http://example.org/test#example');
     // Twig-style
     $this->assertEquals($expected, $loader->load('@namespace/frame.jsonld'));
 }
Example #2
0
 /**
  * @throws \Twig_Error_Loader
  */
 public function testSerialize()
 {
     $loader = new JsonLdFrameLoader();
     $loader->addPath(__DIR__ . '/Fixtures', 'namespace');
     $registry = new RdfNamespaceRegistry();
     $foaf = new Graph('http://njh.me/foaf.rdf');
     $foaf->parseFile(__DIR__ . '/Fixtures/foaf.rdf');
     $graphProvider = new SimpleGraphProvider();
     $metadataFactory = $this->getMockBuilder('Metadata\\MetadataFactory')->disableOriginalConstructor()->getMock();
     // new MetadataFactory();
     $resource = $foaf->primaryTopic();
     $serializer = new JsonLdSerializer($registry, $loader, $graphProvider, $metadataFactory);
     $serialized = $serializer->serialize($resource, '@namespace/frame.jsonld');
     $decoded = json_decode($serialized, true);
     $this->assertEquals($resource->get('foaf:name'), $decoded['@graph'][0]['foaf:name']);
 }
Example #3
0
 /**
  * Load the frame.
  * @param string|null $frame
  * @param string|null $parentClass
  * @return array
  */
 protected function loadFrame($frame = null, $type, $includeParentClassFrames)
 {
     // load the frame
     if ($frame) {
         $frame = $this->loader->load($frame, $type, $includeParentClassFrames);
     } else {
         $frame = array();
     }
     // merge context from namespace registry
     $namespaces = $this->nsRegistry->namespaces();
     if (isset($frame['@context'])) {
         $frame['@context'] = array_merge($frame['@context'], $namespaces);
     } else {
         $frame['@context'] = $namespaces;
     }
     return $frame;
 }
Example #4
0
 /**
  * @param $name
  * @param null $parentClass
  * @param bool $includeSubFrames
  * @param bool $assoc
  * @param bool $getTypeFromFrame
  */
 public function load($name, $type = null, $includeSubFrames = true, $assoc = true, $findTypeInFrames = false)
 {
     $frame = parent::load($name, $type, $includeSubFrames, $assoc, $findTypeInFrames);
     return $this->addMissingProperties($frame);
 }