Factory.php 592 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace Modules\Common\Repository\Options;
  3. use Exception;
  4. use Illuminate\Support\Str;
  5. class Factory
  6. {
  7. /**
  8. * make
  9. * @param string $optionName
  10. * @return OptionInterface
  11. * @throws Exception
  12. */
  13. public function make(string $optionName): OptionInterface
  14. {
  15. $className = __NAMESPACE__.'\\'.Str::of($optionName)->ucfirst()->toString();
  16. $class = new $className();
  17. if (! $class instanceof OptionInterface) {
  18. throw new Exception('option must be implement [OptionInterface]');
  19. }
  20. return $class;
  21. }
  22. }