Simple problems require simple solutions
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
529 B

  1. <?php
  2. namespace App\Traits;
  3. trait Invokable
  4. {
  5. /**
  6. * Invoke the given service.
  7. *
  8. * @see __invoke()
  9. */
  10. public static function invoke(...$arguments)
  11. {
  12. return app(static::class)(...$arguments);
  13. }
  14. /**
  15. * Invoke the given service if the boolean argument is truthy.
  16. *
  17. * @see __invoke()
  18. */
  19. public static function invokeIf($boolean, ...$arguments)
  20. {
  21. if (!$boolean) {
  22. return;
  23. }
  24. return static::invoke(...$arguments);
  25. }
  26. }