Skip to content

Commit

Permalink
Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Mar 19, 2014
1 parent 7bce3d0 commit 3df1b95
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
8 changes: 6 additions & 2 deletions docs/07. Cookbook.md
Expand Up @@ -56,7 +56,11 @@ class UserHydrator extends ClassMethods
parent::__construct();

// Add a filter so that "getPassword" is not called, hence "password" is not outputted
$this->filterComposite->addFilter("password", new MethodMatchFilter('getPassword'), FilterComposite::CONDITION_AND);
$this->filterComposite->addFilter(
"password",
new MethodMatchFilter('getPassword'),
FilterComposite::CONDITION_AND
);
}
}
```
Expand Down Expand Up @@ -165,7 +169,7 @@ class User
Now, the hydrator:

```php
class CustomUserHydrator extends ClassMethods
class CustomUserHydrator extends \Zend\Stdlib\Hydrator\ClassMethods
{
protected $friendsService;

Expand Down
4 changes: 3 additions & 1 deletion src/ZfrRest/Resource/Metadata/Annotation/Association.php
Expand Up @@ -18,6 +18,8 @@

namespace ZfrRest\Resource\Metadata\Annotation;

use ZfrRest\Resource\Metadata\ResourceMetadataInterface;

/**
* @Annotation
* @Target({"PROPERTY"})
Expand All @@ -39,7 +41,7 @@ final class Association implements AnnotationInterface
*
* @Enum({"NONE", "EMBED", "ID"})
*/
public $extraction = 'ID';
public $extraction = ResourceMetadataInterface::ASSOCIATION_EXTRACTION_ID;

/**
* {@inheritDoc}
Expand Down
7 changes: 7 additions & 0 deletions src/ZfrRest/Resource/Metadata/ResourceMetadataInterface.php
Expand Up @@ -25,6 +25,13 @@
*/
interface ResourceMetadataInterface
{
/**
* Extraction constants that define how extraction associations are rendered
*/
const ASSOCIATION_EXTRACTION_NONE = 'NONE';
const ASSOCIATION_EXTRACTION_EMBED = 'EMBED';
const ASSOCIATION_EXTRACTION_ID = 'ID';

/**
* Create a new resource from the metadata
*
Expand Down
9 changes: 1 addition & 8 deletions src/ZfrRest/Resource/ResourceInterface.php
Expand Up @@ -26,17 +26,10 @@
*/
interface ResourceInterface
{
/**
* Extraction constants that define how extraction associations are rendered
*/
const ASSOCIATION_EXTRACTION_NONE = 'NONE';
const ASSOCIATION_EXTRACTION_EMBED = 'EMBED';
const ASSOCIATION_EXTRACTION_ID = 'ID';

/**
* Get the resource metadata
*
* @return Metadata\ResourceMetadataInterface
* @return Metadata\ResourceMetadataInterface|\Metadata\ClassMetadata
*/
public function getMetadata();

Expand Down
15 changes: 6 additions & 9 deletions src/ZfrRest/View/Renderer/DefaultResourceRenderer.php
Expand Up @@ -134,7 +134,7 @@ public function renderResource(ResourceInterface $resource)
$resourceMetadata = $resource->getMetadata();

// We start a new extraction context, to avoid circular extraction
$extractedClass = $resourceMetadata->getReflectionClass()->getName();
$extractedClass = $resourceMetadata->name;
$this->circularChecker[$extractedClass] = true;

$payload = [];
Expand Down Expand Up @@ -168,10 +168,7 @@ protected function renderItem($object, ResourceMetadataInterface $resourceMetada
/** @var \Zend\Stdlib\Hydrator\HydratorInterface $hydrator */
$hydrator = $this->hydratorPluginManager->get($resourceMetadata->getHydratorName());

$data = $hydrator->extract($object);
$data = $this->renderAssociations($data, $resourceMetadata);

return $data;
return $this->renderAssociations($hydrator->extract($object), $resourceMetadata);
}

/**
Expand Down Expand Up @@ -206,7 +203,7 @@ protected function renderAssociations(array $data, ResourceMetadataInterface $re
$extractionStrategy = $associationMetadata['extraction'];

// If set to NONE, we don't even want the association to be in the payload
if ($extractionStrategy === ResourceInterface::ASSOCIATION_EXTRACTION_NONE) {
if ($extractionStrategy === ResourceMetadataInterface::ASSOCIATION_EXTRACTION_NONE) {
unset($data[$association]);
continue;
}
Expand Down Expand Up @@ -246,13 +243,13 @@ protected function renderAssociation($object, $targetClass, $extractionStrategy,

// Avoid circular extraction
if (isset($this->circularChecker[$targetClass])) {
$extractionStrategy = ResourceInterface::ASSOCIATION_EXTRACTION_ID;
$extractionStrategy = ResourceMetadataInterface::ASSOCIATION_EXTRACTION_ID;
}

$association = null;

switch($extractionStrategy) {
case ResourceInterface::ASSOCIATION_EXTRACTION_ID:
case ResourceMetadataInterface::ASSOCIATION_EXTRACTION_ID:
$identifiers = [];

foreach ($object as $datum) {
Expand All @@ -263,7 +260,7 @@ protected function renderAssociation($object, $targetClass, $extractionStrategy,
$association = $identifiers;
break;

case ResourceInterface::ASSOCIATION_EXTRACTION_EMBED:
case ResourceMetadataInterface::ASSOCIATION_EXTRACTION_EMBED:
$embedded = [];

foreach ($object as $datum) {
Expand Down

0 comments on commit 3df1b95

Please sign in to comment.