Skip to content

Commit

Permalink
Feat: improve all path collection
Browse files Browse the repository at this point in the history
  • Loading branch information
komtcho committed Jul 28, 2024
1 parent c9b6b80 commit b9feb7b
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/Services/ExecutorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}


Expand Down Expand Up @@ -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();
}
}

0 comments on commit b9feb7b

Please sign in to comment.