Advertisement
Guest User

Untitled

a guest
May 8th, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.62 KB | None | 0 0
  1. <?php
  2.  
  3. // config.php
  4. return {
  5.     'types' => [
  6.         OrderType::ACTIVE => \App\ActiveOrder::class,
  7.         OrderType::NEW => \App\NewOrder::class,
  8.         OrderType::DISABLED => \App\DisabledOrder::class,
  9.     ]
  10. }
  11.  
  12. // OrderFactory.php
  13. class OrderFactory {
  14.    
  15.     public function getOrder(int $type): Order {
  16.        
  17.         if (
  18.             config()->has('types.' . $type) &&
  19.             class_exist(config()->get('types.' . $type))
  20.         ) {
  21.             return new (config()->get('types.' . $type));  
  22.         }
  23.        
  24.         throw new \InvalidArgumentException('Undefined order type');
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement