¨4.0.1¨
This commit is contained in:
@@ -3,101 +3,103 @@
|
||||
namespace FleetCart\Scaffold\Module\Generators;
|
||||
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
|
||||
abstract class Generator
|
||||
{
|
||||
/**
|
||||
* The instance of Filesystem.
|
||||
*
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
* @var Filesystem
|
||||
*/
|
||||
protected $finder;
|
||||
protected Filesystem $finder;
|
||||
|
||||
/**
|
||||
* Name of the module.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
protected string $name;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param \Illuminate\Filesystem\Filesystem $finder
|
||||
* @param Filesystem $finder
|
||||
*/
|
||||
public function __construct(Filesystem $finder)
|
||||
{
|
||||
$this->finder = $finder;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate the given files.
|
||||
*
|
||||
* @param array $files
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
abstract public function generate(array $files);
|
||||
abstract public function generate(array $files): void;
|
||||
|
||||
|
||||
/**
|
||||
* Set the module name.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function module($name)
|
||||
public function module(string $name): static
|
||||
{
|
||||
$this->name = ucfirst($name);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current module path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
protected function getModulesPath($path = '')
|
||||
{
|
||||
return config('modules.paths.modules') . "/{$this->name}/{$path}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Create directory if not exists.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function createDirectory($path)
|
||||
protected function createDirectory($path): string
|
||||
{
|
||||
$path = $this->getModulesPath($path);
|
||||
|
||||
if (! $this->finder->isDirectory($path)) {
|
||||
if (!$this->finder->isDirectory($path)) {
|
||||
$this->finder->makeDirectory($path, 0755, true);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stub path for the given stub file.
|
||||
* Return the current module path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
protected function getStubPath($filename)
|
||||
protected function getModulesPath(string $path = ''): string
|
||||
{
|
||||
return __DIR__ . "/../stubs/{$filename}";
|
||||
return config('modules.paths.modules') . "/{$this->name}/{$path}";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get content of the given stub.
|
||||
*
|
||||
* @param string $stub
|
||||
* @param string $class
|
||||
*
|
||||
* @return string
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
protected function getContentForStub($stub, $class = '')
|
||||
protected function getContentForStub(string $stub, string $class = ''): string
|
||||
{
|
||||
$stub = $this->finder->get($this->getStubPath($stub));
|
||||
|
||||
@@ -131,4 +133,17 @@ abstract class Generator
|
||||
kebab_case(str_plural($class)),
|
||||
], $stub);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get stub path for the given stub file.
|
||||
*
|
||||
* @param string $filename
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStubPath($filename)
|
||||
{
|
||||
return __DIR__ . "/../stubs/{$filename}";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user