我试图加载api_platform.iri_converter
但得到一个错误:
在编译容器时,\"api_platform.iri_converter\" 服务或别名已被删除或内联。您应该将其公开,或者直接停止使用容器并改用依赖注入。
这是代码:
declare(strict_types=1);
namespace App\Security\Authorization\Voter;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class BaseVoter extends Voter
{
public ContainerInterface $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
}
declare(strict_types=1);
namespace App\Security\Authorization\Voter;
class VenueVoter extends BaseVoter
{
protected function voteOnAttribute(): bool
{
/** @var User $tokenUser */
$tokenUser = $token->getUser();
if (self::VENUE_CREATE === $attribute) {
$iri = $this->container->get('api_platform.iri_converter')->getItemFromIri($valueWithIri);
}
}
}