Advertisement
Guest User

Untitled

a guest
Nov 1st, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.16 KB | None | 0 0
  1. <?php
  2.  
  3. abstract class AbstactEntityFactory
  4. {
  5.     /**
  6.      * @param mixed[] $state
  7.      */
  8.     abstract public function createEntity(array $state): EntityInterface;
  9.  
  10.     /**
  11.      * @param mixed[] $state
  12.      */
  13.     abstract public function createEntityCollection(array $states): EntityCollectionInterface;
  14. }
  15.  
  16. class FooEntityFactory extends AbstactEntityFactory
  17. {
  18.     /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function createEntity(array $state): EntityInterface
  22.     {
  23.         return Foo::fromState($state);
  24.     }
  25.  
  26.     /**
  27.      * {@inheritdoc}
  28.      */
  29.     public function createEntityCollection(array $states): EntityCollectionInterface
  30.     {
  31.         return new FooCollection(array_map('Foo::fromState', $states));
  32.     }
  33. }
  34.  
  35. class BarEntityFactory extends AbstactEntityFactory
  36. {
  37.     /**
  38.      * {@inheritdoc}
  39.      */
  40.     public function createEntity(array $state): EntityInterface
  41.     {
  42.         return Bar::fromState($state);
  43.     }
  44.  
  45.     /**
  46.      * {@inheritdoc}
  47.      */
  48.     public function createEntityCollection(array $states): EntityCollectionInterface
  49.     {
  50.         return new BarCollection(array_map('Bar::fromState', $states));
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement