Skip to content

Commit

Permalink
Handle the case for Selectable
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Feb 17, 2014
1 parent 067ec09 commit edfd852
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ZfrRest/Mvc/Controller/Plugin/ResourceModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

namespace ZfrRest\Mvc\Controller\Plugin;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use DoctrineModule\Paginator\Adapter\Selectable;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use ZfrRest\Mvc\Controller\AbstractRestfulController;
use ZfrRest\Mvc\Exception\RuntimeException;
Expand Down Expand Up @@ -55,6 +58,12 @@ public function __invoke($data, ResourceMetadataInterface $resourceMetadata = nu

$resourceMetadata = $resourceMetadata ?: $this->controller->getMatchedResource()->getMetadata();

// When an URI like "/users" is matched, we may receive an ObjectRepository, that is Selectable
// BUT NOT iterable. Therefore we force a match with an empty Criteria for those cases
if ($data instanceof Selectable && !$data instanceof Collection) {
$data = $data->matching(new Criteria());
}

return new ResourceViewModel(new Resource($data, $resourceMetadata));
}
}

0 comments on commit edfd852

Please sign in to comment.