У меня есть сущность «Пользователь» на платформе API, и я создал специальную операцию для возврата информации о вошедшем в систему пользователе с использованием поставщика состояний.
Тег ApiResource:
У меня есть сущность «Пользователь» на платформе API, и я создал специальную операцию для возврата информации о вошедшем в систему пользователе с использованием поставщика состояний. Тег ApiResource: [code]#[ApiResource( operations: [ new Get( uriTemplate: '/user', normalizationContext: ['groups' => ['user:read']], security: self::SECURITY_GET, provider: UserStateProvider::class ) ] [/code] UserStateProvider: [code]class UserStateProvider implements ProviderInterface { public function __construct( private readonly Security $security, ) {}
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null { return $this->security->getUser(); } } [/code] Проблема: [b]Эта конечная точка возвращает IRI без идентификатора, который выглядит следующим образом[/b]: [code]"@context": "/api/contexts/User", "@id": "/api/user", "@type": "User", [/code] Я попытался получить пользователя из репозитория в UserStateProvider, но это не решило проблему: [code]$user = $this->security->getUser(); return $user ? $this->userRepository->find($user->getId()) : null; [/code] Ресурс пользователя:
public function __construct() { $this->createdAt = new \DateTimeImmutable(); $this->updatedAt = new \DateTimeImmutable(); $this->userChanges = new ArrayCollection(); $this->channels = new ArrayCollection(); $this->moderateChannels = new ArrayCollection(); $this->comments = new ArrayCollection(); $this->purchasedTickets = new ArrayCollection(); $this->cartItems = new ArrayCollection(); $this->subscriptions = new ArrayCollection(); $this->purchasedVideoContents = new ArrayCollection(); }
public function getId(): ?int { return $this->id; }
/** * A visual identifier that represents this user. * * @see UserInterface */ public function getUserIdentifier(): string { return (string) $this->id; }
/** * @see UserInterface * * @return list */ public function getRoles(): array { $roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER';
return array_unique($roles); }
/** * @param list $roles */ public function setRoles(array $roles): static { $this->roles = $roles;
return $this; }
/** * @see PasswordAuthenticatedUserInterface */ public function getPassword(): string { return $this->password; }
public function setPassword(string $password): static { $this->password = $password;
return $this; }
/** * @see UserInterface */ public function eraseCredentials(): void { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; }
public function getNickname(): ?string { return $this->nickname; }
public function setNickname(string $nickname): static { $this->nickname = $nickname;
return $this; }
public function getCreatedAt(): ?\DateTimeImmutable { return $this->createdAt; }
public function setCreatedAt(\DateTimeImmutable $createdAt): static { $this->createdAt = $createdAt;
return $this; }
public function getUpdatedAt(): ?\DateTimeImmutable { return $this->updatedAt; }
public function setUpdatedAt(\DateTimeImmutable $updatedAt): static { $this->updatedAt = $updatedAt;
return $this; }
public function getEmail(): ?string { return $this->email; }
public function setEmail(string $email): static { $this->email = $email;
return $this; }
public function getUserData(): ?UserData { return $this->userData; }
public function setUserData(UserData $userData): static { // set the owning side of the relation if necessary if ($userData->getUser() !== $this) { $userData->setUser($this); }
$this->userData = $userData;
return $this; }
/** * @return Collection */ public function getUserChanges(): Collection { return $this->userChanges; }
public function addUserChange(UserChange $userChange): static { if (!$this->userChanges->contains($userChange)) { $this->userChanges->add($userChange); $userChange->setUser($this); }
return $this; }
public function removeUserChange(UserChange $userChange): static { if ($this->userChanges->removeElement($userChange)) { // set the owning side to null (unless already changed) if ($userChange->getUser() === $this) { $userChange->setUser(null); } }
return $this; }
/** * @return Collection */ public function getChannels(): Collection { return $this->channels; }
public function addChannel(Channel $channel): static { if (!$this->channels->contains($channel)) { $this->channels->add($channel); $channel->setUser($this); }
return $this; }
public function removeChannel(Channel $channel): static { if ($this->channels->removeElement($channel)) { // set the owning side to null (unless already changed) if ($channel->getUser() === $this) { $channel->setUser(null); } }
return $this; }
/** * @return Collection */ public function getModerateChannels(): Collection { return $this->moderateChannels; }
public function addModerateChannel(Channel $moderateChannel): static { if (!$this->moderateChannels->contains($moderateChannel)) { $this->moderateChannels->add($moderateChannel); $moderateChannel->addModerator($this); }
return $this; }
public function removeModerateChannel(Channel $moderateChannel): static { if ($this->moderateChannels->removeElement($moderateChannel)) { $moderateChannel->removeModerator($this); }
return $this; }
/** * @return Collection */ public function getComments(): Collection { return $this->comments; }
public function addComment(Comment $comment): static { if (!$this->comments->contains($comment)) { $this->comments->add($comment); $comment->setAuthor($this); }
return $this; }
public function removeComment(Comment $comment): static { if ($this->comments->removeElement($comment)) { // set the owning side to null (unless already changed) if ($comment->getAuthor() === $this) { $comment->setAuthor(null); } }
return $this; }
/** * @return Collection */ public function getPurchasedTickets(): Collection { return $this->purchasedTickets; }
public function addPurchasedTicket(PurchasedTicket $purchasedTicket): static { if (!$this->purchasedTickets->contains($purchasedTicket)) { $this->purchasedTickets->add($purchasedTicket); $purchasedTicket->setUser($this); }
return $this; }
public function removePurchasedTicket(PurchasedTicket $purchasedTicket): static { if ($this->purchasedTickets->removeElement($purchasedTicket)) { // set the owning side to null (unless already changed) if ($purchasedTicket->getUser() === $this) { $purchasedTicket->setUser(null); } }
return $this; }
/** * @return Collection */ public function getCartItems(): Collection { return $this->cartItems; }
public function addCartItem(CartItem $cartItem): static { if (!$this->cartItems->contains($cartItem)) { $this->cartItems->add($cartItem); $cartItem->setUser($this); }
return $this; }
public function removeCartItem(CartItem $cartItem): static { if ($this->cartItems->removeElement($cartItem)) { // set the owning side to null (unless already changed) if ($cartItem->getUser() === $this) { $cartItem->setUser(null); } }
return $this; }
public function getName(): ?string { return $this->getNickname(); }
/** * @return Collection */ public function getSubscriptions(): Collection { return $this->subscriptions; }
public function addSubscription(Subscription $subscription): static { if (!$this->subscriptions->contains($subscription)) { $this->subscriptions->add($subscription); $subscription->setUser($this); }
return $this; }
public function removeSubscription(Subscription $subscription): static { if ($this->subscriptions->removeElement($subscription)) { // set the owning side to null (unless already changed) if ($subscription->getUser() === $this) { $subscription->setUser(null); } }
return $this; }
/** * @return Collection */ public function getPurchasedVideoContents(): Collection { return $this->purchasedVideoContents; }
public function addPurchasedVideoContent(PurchasedVideoContent $purchasedVideoContent): static { if (!$this->purchasedVideoContents->contains($purchasedVideoContent)) { $this->purchasedVideoContents->add($purchasedVideoContent); $purchasedVideoContent->setUser($this); }
return $this; }
public function removePurchasedVideoContent(PurchasedVideoContent $purchasedVideoContent): static { if ($this->purchasedVideoContents->removeElement($purchasedVideoContent)) { // set the owning side to null (unless already changed) if ($purchasedVideoContent->getUser() === $this) { $purchasedVideoContent->setUser(null); } }
У меня есть сущность «Пользователь» на платформе API, и я создал специальную операцию для возврата информации о вошедшем в систему пользователе с использованием поставщика состояний.
Тег ApiResource:
#[ApiResource(
operations: [
new Get(...
Работа с переводами в Symfony 5 + ApiPlatform v2.6 с использованием мутации GraphQl с клиентом Angular 11 (Apollo). Я представляю следующий рабочий процесс:
Необходимо сохранить объекты RecipeStepsTranslation, чтобы получить IRI
Необходимо...
Я должен мигрировать API, разработанный на Apiplatform V2 в Apiplatform V3. reactivated:
security_post_denormalize: 'is_granted( OT , object)'
security_post_denormalize_message: Vous n'avez pas l'accès à cette ressource.
method: PATCH
path:...
Я должен мигрировать API, разработанный на Apiplatform V2 в Apiplatform V3. reactivated:
security_post_denormalize: 'is_granted( OT , object)'
security_post_denormalize_message: Vous n'avez pas l'accès à cette ressource.
method: PATCH
path:...
Я использую EF Core и написал запрос, как это:
public async Task GetByIdsAsync(List ids)
{
return await _dbContext.Entities
.Include(e => e.RelatedEntities)
.Where(e => ids.Contains(e.Id))
.ToListAsync();
}