/**
  * Construct the resource representation object.
  *
  * @param ResourceInterface $resource
  * @param AdapterInterface $adapter
  */
 public function __construct(ResourceInterface $resource, AdapterInterface $adapter)
 {
     // Set the service locator first.
     $this->setServiceLocator($adapter->getServiceLocator());
     $this->setId($resource->getId());
     $this->setAdapter($adapter);
     $this->resource = $resource;
 }
Ejemplo n.º 2
0
 /**
  * Compose a resource representation object.
  *
  * This version simply proxies to the "real" getRepresentation for each resource's adapter.
  *
  * @param string|int $id The unique identifier of the resource
  * @param mixed $data Whatever data is needed to compose the representation.
  * @return RepresentationInterface|null
  */
 public function getRepresentation(ResourceInterface $data = null)
 {
     if (!$data instanceof ResourceEntity) {
         // Do not attempt to compose a null representation.
         return null;
     }
     $adapter = $this->getAdapter($data->getResourceName());
     return $adapter->getRepresentation($data);
 }