Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion Rest/Metadata/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,27 @@ final class Reference
* @var string
*/
public $field = 'id';
}

/**
* @var string[]
*/
public $groups;

/**
* @param array $data
*
* @throws InvalidArgumentException
*/
public function __construct(array $data)
{
$groups = isset($data['groups']) ? (array) $data['groups'] : [];

foreach ($groups as $group) {
if (!\is_string($group)) {
throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', \get_class($this)));
}
}

$this->groups = $groups;
}
}
8 changes: 7 additions & 1 deletion Serializer/Normalizer/AttributeExtractionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public function getValue($object, $attribute, $format = null, array $context = a

$property = $referenceMetadata->field;

if (isset($context['groups']) && is_array($context['groups'])) {
if (count(array_intersect($context['groups'], $referenceMetadata->groups)) > 0) {
return $propertyValue;
}
}

if ($propertyValue instanceof \Traversable) {
$value = [];

Expand Down Expand Up @@ -97,4 +103,4 @@ private function isExpand($attribute, $context)

return false;
}
}
}