-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a68e0de
commit 26ec420
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/Sulu/Bundle/CoreBundle/Serializer/Exclusion/FieldsExclusionStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sulu\Bundle\CoreBundle\Serializer\Exclusion; | ||
|
||
use JMS\Serializer\Context; | ||
use JMS\Serializer\Exclusion\ExclusionStrategyInterface; | ||
use JMS\Serializer\Metadata\ClassMetadata; | ||
use JMS\Serializer\Metadata\PropertyMetadata; | ||
|
||
class FieldsExclusionStrategy implements ExclusionStrategyInterface | ||
{ | ||
/** @var array<int, string> */ | ||
private array $requestedFields; | ||
|
||
/** @param array<int, string> $requestedFields */ | ||
public function __construct(array $requestedFields) | ||
{ | ||
$this->requestedFields = $requestedFields; | ||
} | ||
|
||
public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext): bool | ||
{ | ||
return false; | ||
} | ||
|
||
public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext): bool | ||
{ | ||
if (count($this->requestedFields) === 0) { | ||
return false; | ||
} | ||
|
||
return !in_array($property->serializedName, $this->requestedFields, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters