Skip to content

Commit

Permalink
chore: add uses replcaement in make:model command
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Sep 20, 2024
1 parent 75466dc commit 1632601
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/devtool/src/Generator/ModelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ public function execute(InputInterface $input, OutputInterface $output): int
return 0;
}

/**
* Replace the class name for the given stub.
*/
protected function replaceClass(string $stub, string $name): string
{
$stub = parent::replaceClass($stub, $name);

$uses = $this->getConfig()['uses'] ?? \SwooleTW\Hyperf\Database\Eloquent\Model::class;

return str_replace('%USES%', $uses, $stub);
}

protected function getStub(): string
{
return $this->getConfig()['stub'] ?? __DIR__ . '/stubs/model.stub';
Expand Down
2 changes: 1 addition & 1 deletion src/devtool/src/Generator/stubs/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare(strict_types=1);

namespace %NAMESPACE%;

use SwooleTW\Hyperf\Database\Eloquent\Model;
use %USES%;

class %CLASS% extends Model
{
Expand Down

0 comments on commit 1632601

Please sign in to comment.