/** * @param object $object * @param Metadata $metadata * @return Collection */ public function createCollectionFromMetadata($object, Metadata $metadata) { $jsonLDCollection = new Collection($object); $jsonLDCollection->setCollectionName($metadata->getCollectionName()); $jsonLDCollection->setCollectionRoute($metadata->getRoute()); $jsonLDCollection->setEntityRoute($metadata->getEntityRoute()); $jsonLDCollection->setRouteIdentifierName($metadata->getRouteIdentifierName()); $jsonLDCollection->setEntityIdentifierName($metadata->getEntityIdentifierName()); $properties = $jsonLDCollection->getProperties(); $this->marshalMetadataProperties($metadata, $properties); $forceFullUriID = $metadata->getForceFullUriID(); if ($forceFullUriID && !$properties->has('id') && ($metadata->hasUrl() || $metadata->hasRoute())) { $property = $this->marshalPropertyFromMetadata($metadata, $object); $properties->add($property); } return $jsonLDCollection; }
public function setUpChildCollection() { $children = [['luke', 'Luke Skywalker'], ['leia', 'Leia Organa']]; $collection = []; foreach ($children as $info) { $collection[] = call_user_func_array([$this, 'setUpChildEntity'], $info); } $collection = new Collection($collection); $collection->setCollectionRoute('parent/child'); $collection->setEntityRoute('parent/child'); $collection->setPage(1); $collection->setPageSize(10); $collection->setCollectionName('child'); $property = new Property('id'); $property->setRoute('parent/child'); $collection->getProperties()->add($property); return $collection; }
public function testCollectionNameIsMutable() { $jsonLD = new Collection([], 'item/route'); $jsonLD->setCollectionName('records'); $this->assertEquals('records', $jsonLD->getCollectionName()); }
/** * @group 14 */ public function testRenderingNonPaginatorCollectionRendersCountOfTotalItems() { $embedded = new Entity((object) ['id' => 'foo', 'name' => 'foo'], 'foo'); $properties = $embedded->getProperties(); $self = new Property('self'); $self->setRoute('hostname/users', ['id' => 'foo']); $properties->add($self); $collection = new Collection([$embedded]); $collection->setCollectionName('users'); $self = new Property('id'); $self->setRoute('hostname/users'); $collection->getProperties()->add($self); $rendered = $this->plugin->renderCollection($collection); $expectedKeys = ['id', 'users', 'totalItems', '@context', '@type']; $this->assertEquals($expectedKeys, array_keys($rendered)); }