-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internal: set user full name by NameConvention service when normalizi…
…ng user data
- Loading branch information
Showing
3 changed files
with
49 additions
and
53 deletions.
There are no files selected for viewing
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
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,49 @@ | ||
<?php | ||
|
||
/* For licensing terms, see /license.txt */ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chamilo\CoreBundle\Serializer\Normalizer; | ||
|
||
use Chamilo\CoreBundle\Component\Utils\NameConvention; | ||
use Chamilo\CoreBundle\Entity\User; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
class UserNormalizer implements NormalizerInterface, NormalizerAwareInterface | ||
{ | ||
use NormalizerAwareTrait; | ||
|
||
private const ALREADY_CALLED = 'USER_NORMALIZER_ALREADY_CALLED'; | ||
|
||
public function __construct( | ||
private readonly NameConvention $nameConvention, | ||
) {} | ||
|
||
public function normalize($object, ?string $format = null, array $context = []): array | ||
{ | ||
$context[self::ALREADY_CALLED] = true; | ||
|
||
$data = $this->normalizer->normalize($object, $format, $context); | ||
|
||
$data['fullName'] = $this->nameConvention->getPersonName($object); | ||
|
||
return $data; | ||
} | ||
|
||
public function supportsNormalization($data, ?string $format = null, array $context = []): bool | ||
{ | ||
if (isset($context[self::ALREADY_CALLED])) { | ||
return false; | ||
} | ||
|
||
return $data instanceof User; | ||
} | ||
|
||
public function getSupportedTypes(?string $format): array | ||
{ | ||
return [User::class => false]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.