Advertisement
Guest User

Untitled

a guest
May 21st, 2020
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.91 KB | None | 0 0
  1. <?php
  2.  
  3. class Post
  4. {
  5.     public $title;
  6.     public $description;
  7. }
  8.  
  9. class Post
  10. {
  11.     public string $title;
  12.     public string $description;
  13. }
  14.  
  15. class Post
  16. {
  17.     private array $data;
  18.  
  19.     public function __construct(array $data)
  20.     {
  21.         $this->validateData($data);
  22.         $this->data = $data;
  23.     }
  24.  
  25.     public function getData(): array
  26.     {
  27.         return $this->data;
  28.     }
  29. }
  30.  
  31. class Post
  32. {
  33.     private string $title;
  34.     private string $description;
  35.  
  36.     public function __construct(string $title, string $description)
  37.     {
  38.         $this->validateTitle($title);
  39.         $this->validateDescription($description);
  40.  
  41.         $this->title = $title;
  42.         $this->description = $description;
  43.     }
  44.  
  45.     public function getTitle(): string
  46.     {
  47.         return $this->title;
  48.     }
  49.  
  50.     public function getDescription(): string
  51.     {
  52.         return $this->description;
  53.     }
  54. }
  55.  
  56. class Post
  57. {
  58.     private string $title;
  59.     private string $description;
  60.  
  61.     public function setTitle(string $title)
  62.     {
  63.         $this->validateTitle($title);
  64.         $this->title = $title;
  65.     }
  66.  
  67.     public function setDescription(string $description)
  68.     {
  69.         $this->validateDescription($description);
  70.         $this->description = $description;
  71.     }
  72.  
  73.     public function getTitle(): string
  74.     {
  75.         return $this->title;
  76.     }
  77.  
  78.     public function getDescription(): string
  79.     {
  80.         return $this->description;
  81.     }
  82. }
  83.  
  84. class Post
  85. {
  86.     // bla-bla
  87.    
  88.     public function fromRequest(ServerRequestInterface $request)
  89.     {
  90.         // ...
  91.     }
  92. }
  93.  
  94. // See https://github.com/fireproofsocks/dto
  95. class Post extends Dto\Dto
  96. {
  97.     protected $schema = [
  98.         'type' => 'object',
  99.         'properties' => [
  100.             'title' => ['type' => 'string'],
  101.             'description' => ['type' => 'string']
  102.         ],
  103.         'additionalProperties' => false
  104.     ];
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement