Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.20 KB | None | 0 0
  1. <?php
  2. declare(strict_types=1);
  3.  
  4. /**
  5.  * Interface IPayload
  6.  */
  7. interface IPayload {
  8.     public function toArray(): array;
  9. }
  10.  
  11. /**
  12.  * Interface ChildPayloadInterface
  13.  */
  14. interface ChildPayloadInterface {
  15.     public function setVar(string $var);
  16. }
  17.  
  18. /**
  19.  * Interface GenericPayload
  20.  */
  21. interface GenericPayload extends IPayload, ChildPayloadInterface {
  22.  
  23. }
  24.  
  25. /**
  26.  * Interface IPayloadFactory
  27.  */
  28. interface IPayloadFactory {
  29.     public function create(): IPayload;
  30. }
  31.  
  32. /**
  33.  * Interface IChildPayloadFactory
  34.  */
  35. interface IChildPayloadFactory {
  36.     public function create(): GenericPayload;
  37. }
  38.  
  39. /**
  40.  * Class Payload
  41.  */
  42. class Payload implements IPayload {
  43.     public function toArray(): array {
  44.         return ['hello' => 'world'];
  45.     }
  46. }
  47.  
  48. /**
  49.  * Class ChildPayload
  50.  */
  51. class ChildPayload extends Payload implements GenericPayload {
  52.     public function setVar(string $var)  {
  53.         $this->var = $var;
  54.     }
  55. }
  56.  
  57. /**
  58.  * Class ChildPayloadFactory
  59.  */
  60. class ChildPayloadFactory implements IChildPayloadFactory {
  61.     public function create(): GenericPayload  {
  62.         return new ChildPayload();
  63.     }
  64. }
  65.  
  66.  
  67. $factory = new ChildPayloadFactory();
  68.  
  69. var_dump($factory->create());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement