Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php declare(strict_types=1);
  2.  
  3. namespace App\Model;
  4.  
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use App\Entity\BusinessPartner;
  7. use App\Entity\Product;
  8. use App\Entity\Vendor\Manufacturer;
  9. use Ramsey\Uuid\UuidInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11.  
  12. class ProductDTO
  13. {
  14.     public function __toString()
  15.     {
  16.         return $this->name;
  17.     }
  18.  
  19.     /**
  20.      * @var UuidInterface
  21.      */
  22.     public $id;
  23.  
  24.     /**
  25.      * @var Manufacturer|null the manufacturer of the product
  26.      *
  27.      * @Assert\NotNull
  28.      */
  29.     public $manufacturer;
  30.  
  31.     /**
  32.      * @var string|null The model of the product. Use with the URL of a ProductModel or a textual representation of the model identifier.
  33.      * The URL of the ProductModel can be from an external source. It is recommended to additionally provide strong product identifiers
  34.      * via the gtin8/gtin13/gtin14 and mpn properties.
  35.      *
  36.      * @Assert\Type(type="string")
  37.      * @Assert\NotBlank()
  38.      * @Assert\Length(min=3,max=80)
  39.      */
  40.     public $model;
  41.  
  42.     /**
  43.      * @var string|null The identifier property represents any kind of identifier for any kind of \[\[Thing\]\], such as ISBNs, GTIN codes,
  44.      * UUIDs etc. Schema.org provides dedicated properties for representing many of these, either as textual strings or as URL (URI) links.
  45.      * See \[background notes\](/docs/datamodel.html#identifierBg) for more details.
  46.      *
  47.      * @Assert\Type(type="string")
  48.      * @Assert\NotNull
  49.      */
  50.     public $identifier;
  51.  
  52.     /**
  53.      * @var string|null URL of the item
  54.      *
  55.      * @Assert\Url
  56.      */
  57.     public $url;
  58.  
  59.     /**
  60.      * @var BusinessPartner|null a BusinessPartner to which this Produc belongs
  61.      */
  62.     public $ownership;
  63.  
  64.     /**
  65.      * @var string|null $name
  66.      */
  67.     public $name;
  68.  
  69.     /**
  70.      * @var string|null $description
  71.      */
  72.     public $description;
  73.  
  74.     /**
  75.      * @var Product $productEntity
  76.      */
  77.     public $productEntity;
  78.  
  79.     public function setEntity(Product $product): void
  80.     {
  81.         $this->id = $product->getId();
  82.         $this->manufacturer = $product->getManufacturer();
  83.         $this->model = $product->getModel();
  84.         $this->identifier = $product->getIdentifier();
  85.         $this->url = $product->getUrl();
  86.         $this->ownership = $product->getOwnership();
  87.         $this->name = $product->getName();
  88.         $this->description = $product->getDescription();
  89.  
  90.         $this->productEntity = $product;
  91.     }
  92.  
  93.     public function commit(): Product
  94.     {
  95.  
  96.         if (null === $this->productEntity) {
  97.             $this->productEntity = new Product($this->manufacturer, $this->model, $this->identifier);
  98.         } else {
  99.             $this->productEntity->setManufacturer($this->manufacturer);
  100.             $this->productEntity->setModel($this->model);
  101.         }
  102.  
  103.         $this->productEntity->setUrl($this->url);
  104.         $this->productEntity->setOwnership($this->ownership);
  105.         $this->productEntity->setDescription($this->description);
  106.  
  107.         return $this->productEntity;
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement