IntegrateJob.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs;
  3. class IntegrateJob extends Job
  4. {
  5. protected $module = null;
  6. protected $service = null;
  7. protected $method = null;
  8. protected $params = null;
  9. /**
  10. * Create a new job instance.
  11. *
  12. * @return void
  13. */
  14. public function __construct($params)
  15. {
  16. $this->module = $params['module'] ?? '';
  17. $this->service = $params['service'] ?? '';
  18. $this->method = $params['method'] ?? '';
  19. $this->params = $params['params'] ?? [];
  20. }
  21. /**
  22. * Execute the job.
  23. *
  24. * @return mixed
  25. */
  26. public function handle()
  27. {
  28. try {
  29. if($this->module && $this->method){
  30. $this->module = ucfirst(convertUnderline($this->module));
  31. $this->method = convertUnderline($this->method);
  32. $this->service = ucfirst(convertUnderline($this->service));
  33. $reflection = new \ReflectionClass('App\\'.$this->module.'\\Services\\'.$this->service);
  34. $service = $reflection->newInstanceWithoutConstructor();
  35. if($reflection->hasMethod($this->method)){
  36. $method = $this->method;
  37. if(!empty($this->params)){
  38. return $service->$method(...$this->params);
  39. } else {
  40. return $service->$method();
  41. }
  42. }
  43. }
  44. } catch (\Exception $e){
  45. return $e->getMessage();
  46. }
  47. }
  48. }