Skip to content

Commit

Permalink
Merge branch '8.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 18, 2023
2 parents 71eeed8 + f61e840 commit cad7594
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Commands/GeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ protected function viewPath($path = '')
{
return $this->viewPathUsingCanvas($path);
}

/**
* Get a list of possible model names.
*
* @return array<int, string>
*/
protected function possibleModels()
{
return $this->possibleModelsUsingCanvas();
}

/**
* Get a list of possible event names.
*
* @return array<int, string>
*/
protected function possibleEvents()
{
return $this->possibleEventsUsingCanvas();
}
}
39 changes: 39 additions & 0 deletions src/Concerns/UsesGeneratorOverrides.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Orchestra\Canvas\Core\Concerns;

use Illuminate\Support\Str;
use Symfony\Component\Finder\Finder;

trait UsesGeneratorOverrides
{
Expand Down Expand Up @@ -57,4 +58,42 @@ protected function viewPathUsingCanvas(string $path = ''): string

return $views.($path ? DIRECTORY_SEPARATOR.$path : $path);
}

/**
* Get a list of possible model names.
*
* @return array<int, string>
*/
protected function possibleModelsUsingCanvas(): array
{
$sourcePath = $this->generatorPreset()->sourcePath();

$modelPath = is_dir("{$sourcePath}/Models") ? "{$sourcePath}/Models" : $sourcePath;

return collect((new Finder)->files()->depth(0)->in($modelPath))
->map(fn ($file) => $file->getBasename('.php'))
->sort()
->values()
->all();
}

/**
* Get a list of possible event names.
*
* @return array<int, string>
*/
protected function possibleEventsUsingCanvas(): array
{
$eventPath = sprintf('%s/Events', $this->generatorPreset()->sourcePath());

if (! is_dir($eventPath)) {
return [];
}

return collect((new Finder)->files()->depth(0)->in($eventPath))
->map(fn ($file) => $file->getBasename('.php'))
->sort()
->values()
->all();
}
}

0 comments on commit cad7594

Please sign in to comment.