diff --git a/src/Services/ExecutorService.php b/src/Services/ExecutorService.php index b70670c..d36ca7b 100644 --- a/src/Services/ExecutorService.php +++ b/src/Services/ExecutorService.php @@ -40,37 +40,29 @@ protected function prepareExecutors() { $db = Executor::all()->keyBy('executor'); - $collectExecutors = collect([]); + return collect(array_map(function ($file) use ($db) { + $class = new ReflectionClass(include $file); + $name = basename($class->getFileName(), '.php'); + $executor = [ + 'name' => $name, + 'type' => $class->getProperty('type')->getDefaultValue(), + 'tag' => $class->getProperty('tag')->getDefaultValue(), + 'path' => $class->getFileName(), + 'model' => $db[$name] ?? null + ]; + + if ($executor['model']) { + $executor['model']->fill([ + 'type' => $executor['type'], + 'tag' => $executor['tag'], + ]); - foreach (ExecutorPool::getPaths() as $path) { - $executors = collect(array_map(function ($file) use ($db) { - $class = new ReflectionClass(include $file); - $name = basename($class->getFileName(), '.php'); - $executor = [ - 'name' => $name, - 'type' => $class->getProperty('type')->getDefaultValue(), - 'tag' => $class->getProperty('tag')->getDefaultValue(), - 'path' => $class->getFileName(), - 'model' => $db[$name] ?? null - ]; - - if ($executor['model']) { - $executor['model']->fill([ - 'type' => $executor['type'], - 'tag' => $executor['tag'], - ]); - - if ($executor['model']->isDirty()) { - $executor['model']->save(); - } + if ($executor['model']->isDirty()) { + $executor['model']->save(); } - return $executor; - }, File::glob($path . '/*')))->keyBy('name'); - - $collectExecutors = $collectExecutors->merge($executors->all()); - } - - return $collectExecutors; + } + return $executor; + }, $this->collectAllPaths()))->keyBy('name'); } @@ -111,4 +103,15 @@ protected function getNextBatch() { return (Executor::orderBy('batch', 'desc')->first()?->batch ?? 0) + 1; } + + private function collectAllPaths() + { + $collectPath = collect([]); + + foreach (ExecutorPool::getPaths() as $path) { + $collectPath = $collectPath->merge(File::glob($path . '/*')); + } + + return $collectPath->all(); + } }