Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Api平台非规范化自定义操作与关系_Php_Symfony_Api Platform.com_Denormalization - Fatal编程技术网

Php Api平台非规范化自定义操作与关系

Php Api平台非规范化自定义操作与关系,php,symfony,api-platform.com,denormalization,Php,Symfony,Api Platform.com,Denormalization,我有两个实体凭证和客户机(扩展用户实体),具有OneToOne关系,我在凭证实体中有一个自定义操作,我想在此操作中对客户机实体进行非规范化(以便以后能够验证属性),但它不会显示在swagger文档中 凭证主体: <?php /** * @ApiResource( * collectionOperations={ * "add_voucher"={ * "access_control"

我有两个实体凭证和客户机(扩展用户实体),具有OneToOne关系,我在凭证实体中有一个自定义操作,我想在此操作中对客户机实体进行非规范化(以便以后能够验证属性),但它不会显示在swagger文档中

凭证主体:

<?php

/**
 * @ApiResource(
 *     collectionOperations={
 *          "add_voucher"={
 *                 "access_control"="is_granted('ROLE_COMMERCIAL')",
 *                 "method"="POST",
 *                 "path"="/vouchers/add-new",
 *                 "controller"=AddVoucherAction::class,
 *                 "security_post_denormalize_message"="Sorry, Only Commercials can Generate Vouchers",
 *                  "denormalization_context"={
 *                      "groups"={"add_new_voucher"}
 *               },
 *                  "validation_groups"={"Default", "add_voucher_validation"}
 *         },
 *     }
 * )
 * @ORM\Entity(repositoryClass="App\Repository\VoucherRepository", repositoryClass=VoucherRepository::class)
 */
class Voucher
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @Groups("add_new_voucher")
     * @ORM\Column(type="string", length=255, unique=true)
     */
    private $code;

    /**
     * @Groups("add_new_voucher")
     * @ORM\Column(type="integer")
     */
    private $discount;

    /**
     * @Groups("add_new_voucher")
     * @OneToOne(targetEntity="App\Entity\Client")
     * @JoinColumn(name="client_id", referencedColumnName="id")
     */
    private $client;

    public function getDiscount()
    {
        return $this->discount;
    }

    public function setDiscount($discount): void
    {
        $this->discount = $discount;
    }

    public function getClient()
    {
        return $this->client;
    }

    public function setClient($client): void
    {
        $this->client = $client;
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCode(): ?string
    {
        return $this->code;
    }

    public function setCode(string $code): self
    {
        $this->code = $code;

        return $this;
    }

}

<?php

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\ClientRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use App\Entity\Language;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ApiResource(
 *     collectionOperations={
 *              "post"={
 *                      "method"="POST",
 *                      "validation_groups"={"registerValidation"},
 *                  }
 *     },
 *     denormalizationContext={"groups"={"register"}}
 * )
 * @ORM\Entity(repositoryClass=ClientRepository::class)
 */
class Client extends User
{
    /**
     * @Groups("register")
     * @ORM\ManyToOne(targetEntity=Language::class, inversedBy="client")
     */
    private $language;
    /**
     * @Groups({"register","add_new_voucher"})
     * @Assert\NotBlank(groups="registerValidation")
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $country;

    /**
     * @Groups("register")
     * @Assert\NotBlank(groups="registerValidation")
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $currency;

    /**
     * @Groups("register")
     * @Assert\NotBlank(groups="registerValidation")
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $timezone;

    /**
     * @Groups("register")
     * @Assert\NotBlank(groups="registerValidation")
     * @ORM\Column(type="integer", nullable=true)
     */
    private $phone;

    /**
     * Client constructor.
     * @param $language
     * @param $country
     * @param $currency
     * @param $timezone
     * @param $phone
     */
    public function __construct($language, $country, $currency, $timezone, $phone)
    {
        parent:: __construct();
        $this->language = $language;
        $this->country = $country;
        $this->currency = $currency;
        $this->timezone = $timezone;
        $this->phone = $phone;
    }

    public function getLanguage()
    {
        return $this->language;
    }

    public function setLanguage($language): void
    {
        $this->language = $language;
    }


    public function getCountry(): ?string
    {
        return $this->country;
    }

    public function setCountry(?string $country): self
    {
        $this->country = $country;

        return $this;
    }

    public function getCurrency(): ?string
    {
        return $this->currency;
    }

    public function setCurrency(?string $currency): self
    {
        $this->currency = $currency;

        return $this;
    }

    public function getTimezone(): ?string
    {
        return $this->timezone;
    }

    public function setTimezone(?string $timezone): self
    {
        $this->timezone = $timezone;

        return $this;
    }

    public function getPhone(): ?int
    {
        return $this->phone;
    }

    public function setPhone(?int $phone): self
    {
        $this->phone = $phone;

        return $this;
    }

}