Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php declare(strict_types=1);
- namespace App\Model;
- use ApiPlatform\Core\Annotation\ApiProperty;
- use App\Entity\BusinessPartner;
- use App\Entity\Product;
- use App\Entity\Vendor\Manufacturer;
- use Ramsey\Uuid\UuidInterface;
- use Symfony\Component\Validator\Constraints as Assert;
- class ProductDTO
- {
- public function __toString()
- {
- return $this->name;
- }
- /**
- * @var UuidInterface
- */
- public $id;
- /**
- * @var Manufacturer|null the manufacturer of the product
- *
- * @Assert\NotNull
- */
- public $manufacturer;
- /**
- * @var string|null The model of the product. Use with the URL of a ProductModel or a textual representation of the model identifier.
- * The URL of the ProductModel can be from an external source. It is recommended to additionally provide strong product identifiers
- * via the gtin8/gtin13/gtin14 and mpn properties.
- *
- * @Assert\Type(type="string")
- * @Assert\NotBlank()
- * @Assert\Length(min=3,max=80)
- */
- public $model;
- /**
- * @var string|null The identifier property represents any kind of identifier for any kind of \[\[Thing\]\], such as ISBNs, GTIN codes,
- * UUIDs etc. Schema.org provides dedicated properties for representing many of these, either as textual strings or as URL (URI) links.
- * See \[background notes\](/docs/datamodel.html#identifierBg) for more details.
- *
- * @Assert\Type(type="string")
- * @Assert\NotNull
- */
- public $identifier;
- /**
- * @var string|null URL of the item
- *
- * @Assert\Url
- */
- public $url;
- /**
- * @var BusinessPartner|null a BusinessPartner to which this Produc belongs
- */
- public $ownership;
- /**
- * @var string|null $name
- */
- public $name;
- /**
- * @var string|null $description
- */
- public $description;
- /**
- * @var Product $productEntity
- */
- public $productEntity;
- public function setEntity(Product $product): void
- {
- $this->id = $product->getId();
- $this->manufacturer = $product->getManufacturer();
- $this->model = $product->getModel();
- $this->identifier = $product->getIdentifier();
- $this->url = $product->getUrl();
- $this->ownership = $product->getOwnership();
- $this->name = $product->getName();
- $this->description = $product->getDescription();
- $this->productEntity = $product;
- }
- public function commit(): Product
- {
- if (null === $this->productEntity) {
- $this->productEntity = new Product($this->manufacturer, $this->model, $this->identifier);
- } else {
- $this->productEntity->setManufacturer($this->manufacturer);
- $this->productEntity->setModel($this->model);
- }
- $this->productEntity->setUrl($this->url);
- $this->productEntity->setOwnership($this->ownership);
- $this->productEntity->setDescription($this->description);
- return $this->productEntity;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement