我正在尝试创建自定义标准化器,但无法使用 API Platform 访问当前用户。
当我尝试加载我的 Client 类时,它是空的。我尝试使用 API 平台的文档进行方法,但检索到的令牌也是空的。
您有什么建议可以获取我当前的用户吗?谢谢
<?php
namespace App\Serializer;
use App\Entity\Stock;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class StockAttributeNormalizer implements ContextAwareNormalizerInterface
{
private $router;
private $normalizer;
public function __construct(UrlGeneratorInterface $router, ObjectNormalizer $normalizer)
{
$this->router = $router;
$this->normalizer = $normalizer;
}
public function normalize($topic, $format = null, array $context = [])
{
$data = $this->normalizer->normalize($topic, $format, $context);
var_dump($data);
return $data;
}
public function supportsNormalization($data, $format = null, array $context = [])
{
return $data instanceof Stock;
}
}
叮当猫咪