Skip to content

Commit

Permalink
Bring more flexibility to the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Mar 17, 2014
1 parent bd072e6 commit f941caf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
13 changes: 10 additions & 3 deletions src/ZfrRest/View/Renderer/DefaultResourceRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,14 @@ public function render($nameOrModel, $values = null)
throw new RuntimeException('Resource renderer expect a ResourceModel instance');
}

$resource = $nameOrModel->getResource();
return $this->renderResource($nameOrModel->getResource());
}

/**
* {@inheritDoc}
*/
public function renderResource(ResourceInterface $resource)
{
$data = $resource->getData();
$resourceMetadata = $resource->getMetadata();

Expand Down Expand Up @@ -156,7 +163,7 @@ public function render($nameOrModel, $values = null)
* @param ResourceMetadataInterface $resourceMetadata
* @return array
*/
public function renderItem($object, ResourceMetadataInterface $resourceMetadata)
protected function renderItem($object, ResourceMetadataInterface $resourceMetadata)
{
/** @var \Zend\Stdlib\Hydrator\HydratorInterface $hydrator */
$hydrator = $this->hydratorPluginManager->get($resourceMetadata->getHydratorName());
Expand Down Expand Up @@ -261,7 +268,7 @@ protected function renderAssociation($object, $targetClass, $extractionStrategy,

foreach ($object as $datum) {
$associationResource = new Resource($datum, $associationResourceMetadata);
$embedded[] = $this->render(new ResourceModel($associationResource));
$embedded[] = $this->renderResource($associationResource);
}

$association = $embedded;
Expand Down
8 changes: 4 additions & 4 deletions src/ZfrRest/View/Renderer/ResourceRendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use Zend\View\Renderer\RendererInterface;
use ZfrRest\Resource\Metadata\ResourceMetadataInterface;
use ZfrRest\Resource\ResourceInterface;

/**
* Interface for all resource renderers
Expand All @@ -30,11 +31,10 @@
interface ResourceRendererInterface extends RendererInterface
{
/**
* Render a single item
* Render a resource
*
* @param object $object
* @param ResourceMetadataInterface $resourceMetadata
* @param ResourceInterface $resource
* @return array
*/
public function renderItem($object, ResourceMetadataInterface $resourceMetadata);
public function renderResource(ResourceInterface $resource);
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,10 @@ public function testCanMatchAssociation($subPath, $associationPath, $propertyNam

$associationMetadata = $this->getMock('ZfrRest\Resource\Metadata\ResourceMetadataInterface');

$classHierarchy = $this->getMock('Metadata\ClassHierarchyMetadata');
$classHierarchy->expects($this->once())->method('getOutsideClassMetadata')->will($this->returnValue($associationMetadata));

$this->metadataFactory->expects($this->once())
->method('getMetadataForClass')
->with('ZfrRestTest\Asset\Router\AssociationMatcherEntity')
->will($this->returnValue($classHierarchy));
->will($this->returnValue($associationMetadata));

$metadata->expects($this->once())
->method('getReflectionClass')
Expand Down

0 comments on commit f941caf

Please sign in to comment.