Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Module/src/Command/Creater/CreateFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CreateFormRequest extends MineCommand

protected string $module;

public function configure()
public function configure(): void
{
parent::configure();
$this->setHelp('run "php bin/hyperf.php mine:module <module_name> <name>"');
Expand All @@ -46,7 +46,7 @@ public function configure()
);
}

public function handle()
public function handle(): int
{
$this->module = ucfirst(trim($this->input->getArgument('module_name')));
$this->name = ucfirst(trim($this->input->getArgument('name')));
Expand All @@ -61,11 +61,12 @@ public function handle()
);
} catch (FileNotFoundException $e) {
$this->error($e->getMessage());
exit;
return MineCommand::FAILURE;
}

$fs->put($this->getModulePath() . $this->name . 'FormRequest.php', $content);

$this->info('<info>[INFO] Created request:</info> ' . $this->name . 'FormRequest.php');
return MineCommand::SUCCESS;
}
}
1 change: 1 addition & 0 deletions src/Module/src/Command/Creater/CreateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public function handle()
}
}
}
return MineCommand::SUCCESS;
}

protected function getOptions(): array
Expand Down
17 changes: 6 additions & 11 deletions src/Module/src/Command/Migrate/MineMigrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,13 @@ class MineMigrate extends BaseCommand
{
protected $module;

/**
* The migration creator instance.
*
* @var MineMigrationCreator
*/
protected $creator;

/**
* Create a new migration install command instance.
*/
public function __construct(MineMigrationCreator $creator)
public function __construct(protected MineMigrationCreator $creator)
{
parent::__construct('mine:migrate-gen');
$this->setDescription('Generate a new MineAdmin module migration file');
$this->creator = $creator;
}

/**
Expand All @@ -58,6 +50,7 @@ public function handle()

if (empty($this->module)) {
$this->error('<--module module_name> required');
return BaseCommand::FAILURE;
exit;
}

Expand Down Expand Up @@ -86,7 +79,7 @@ public function handle()
// Now we are ready to write the migration out to disk. Once we've written
// the migration out, we will dump-autoload for the entire framework to
// make sure that the migrations are registered by the class loaders.
$this->writeMigration($name, $table, $create);
return $this->writeMigration($name, $table, $create);
}

protected function getArguments(): array
Expand All @@ -110,7 +103,7 @@ protected function getOptions(): array
/**
* Write the migration file to disk.
*/
protected function writeMigration(string $name, ?string $table, bool $create): void
protected function writeMigration(string $name, ?string $table, bool $create): int
{
try {
$file = pathinfo($this->creator->create(
Expand All @@ -120,8 +113,10 @@ protected function writeMigration(string $name, ?string $table, bool $create): v
$create
), PATHINFO_FILENAME);
$this->info("<info>[INFO] Created Migration:</info> {$file}");
return BaseCommand::SUCCESS;
} catch (\Throwable $e) {
$this->error("<error>[ERROR] Created Migration:</error> {$e->getMessage()}");
return BaseCommand::FAILURE;
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/Module/src/Command/Migrate/MineMigrateRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,15 @@ class MineMigrateRollback extends BaseCommand
*/
protected string $description = 'Run rollback the database migrations';

/**
* The migrator instance.
*
* @var Migrator
*/
protected $migrator;

protected $module;

/**
* Create a new migration command instance.
*/
public function __construct(Migrator $migrator)
public function __construct(protected Migrator $migrator)
{
parent::__construct();

$this->migrator = $migrator;

$this->setDescription('The run migrate rollback class of MineAdmin module');
}

Expand Down
16 changes: 4 additions & 12 deletions src/Module/src/Command/Migrate/MineMigrateRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,34 +34,25 @@ class MineMigrateRun extends BaseCommand
*/
protected string $description = 'Run the database migrations';

/**
* The migrator instance.
*
* @var Migrator
*/
protected $migrator;

protected $module;

/**
* Create a new migration command instance.
*/
public function __construct(Migrator $migrator)
public function __construct(protected Migrator $migrator)
{
parent::__construct();

$this->migrator = $migrator;

$this->setDescription('The run migrate class of MineAdmin module');
}

/**
* Execute the console command.
*/
public function handle()
public function handle(): int
{
if (! $this->confirmToProceed()) {
return;
return BaseCommand::FAILURE;
}

$this->module = trim($this->input->getArgument('name'));
Expand All @@ -83,6 +74,7 @@ public function handle()
if ($this->input->getOption('seed') && ! $this->input->getOption('pretend')) {
$this->call('db:seed', ['--force' => true]);
}
return BaseCommand::SUCCESS;
}

protected function getOptions(): array
Expand Down
17 changes: 6 additions & 11 deletions src/Module/src/Command/Seeder/MineSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,33 @@
#[Command]
class MineSeeder extends BaseCommand
{
/**
* The seeder creator instance.
*/
protected SeederCreator $creator;

protected string $module;

/**
* Create a new seeder generator command instance.
*/
public function __construct(SeederCreator $creator)
public function __construct(protected SeederCreator $creator)
{
parent::__construct('mine:seeder-gen');
$this->setDescription('Generate a new MineAdmin module seeder class');

$this->creator = $creator;
$this->setDescription('Generate a new MineAdmin module seeder class');
}

/**
* Handle the current command.
*/
public function handle()
public function handle(): int
{
$this->module = ucfirst(trim($this->input->getOption('module')));
$name = Str::snake(trim($this->input->getArgument('name')));

$this->writeMigration($name);
return $this->writeMigration($name);
}

/**
* Write the seeder file to disk.
*/
protected function writeMigration(string $name)
protected function writeMigration(string $name): int
{
$path = $this->ensureSeederDirectoryAlreadyExist(
$this->getSeederPath()
Expand All @@ -66,6 +60,7 @@ protected function writeMigration(string $name)
$file = pathinfo($this->creator->create($name, $path), PATHINFO_FILENAME);

$this->info("<info>[INFO] Created Seeder:</info> {$file}");
return BaseCommand::SUCCESS;
}

protected function ensureSeederDirectoryAlreadyExist(string $path): string
Expand Down
14 changes: 4 additions & 10 deletions src/Module/src/Command/Seeder/MineSeederRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,32 +37,25 @@ class MineSeederRun extends BaseCommand
*/
protected string $description = 'Seed the database with records';

/**
* The seed instance.
*/
protected Seed $seed;

protected string $module;

/**
* Create a new seed command instance.
*/
public function __construct(Seed $seed)
public function __construct(protected Seed $seed)
{
parent::__construct();

$this->seed = $seed;

$this->setDescription('The run seeder class of MineAdmin module');
}

/**
* Handle the current command.
*/
public function handle()
public function handle(): int
{
if (! $this->confirmToProceed()) {
return;
return BaseCommand::FAILURE;
}

$this->module = ucfirst(trim($this->input->getArgument('name')));
Expand All @@ -74,6 +67,7 @@ public function handle()
}

$this->seed->run([$this->getSeederPath()]);
return BaseCommand::SUCCESS;
}

protected function getArguments(): array
Expand Down
1 change: 1 addition & 0 deletions src/jwt-auth/src/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function checkToken(?string $token = null, ?string $scene = null, $valida
/**
* 刷新token.
* @return Token
* @throws \RuntimeException
*/
public function refreshToken(?string $token = null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/mine-generator/src/CodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

interface CodeGenerator
{
public function generator();
public function generator(): void;

public function preview();
public function preview(): string;
}
5 changes: 1 addition & 4 deletions src/mine-generator/src/MineGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@ abstract class MineGenerator

protected string $namespace;

protected ContainerInterface $container;

/**
* MineGenerator constructor.
*/
public function __construct(ContainerInterface $container)
public function __construct(protected ContainerInterface $container)
{
$this->setStubDir(
realpath(
Expand All @@ -39,7 +37,6 @@ public function __construct(ContainerInterface $container)
)
) . DIRECTORY_SEPARATOR . 'Stubs' . DIRECTORY_SEPARATOR
);
$this->container = $container;
}

public function getStubDir(): string
Expand Down
3 changes: 1 addition & 2 deletions src/mine-generator/src/ModuleGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class ModuleGenerator extends MineGenerator

/**
* 设置模块信息.
* @return $this
*/
public function setModuleInfo(array $moduleInfo): ModuleGenerator
public function setModuleInfo(array $moduleInfo): static
{
$this->moduleInfo = $moduleInfo;
return $this;
Expand Down
19 changes: 14 additions & 5 deletions src/mine-helpers/src/AppVerify.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class AppVerify
*/
public function __construct(string $scene = 'api')
{
/* @var JWT $this->jwt */
$this->jwt = make(JWT::class)->setScene($scene);
$this->request = make(RequestInterface::class);
/* @var JWT $this ->jwt */
$this->jwt = static::getJwtGivenScene($scene);
$this->request = static::getRequest();
}

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ public function getAppInfo(): array
*/
public function getApiId(): string
{
$accessToken = $this->request->getQueryParams()['access_token'] ?? null;
$accessToken = $this->request->query('access_token') ?? null;
return (string) $this->jwt->getParserData($accessToken)['id'];
}

Expand All @@ -98,11 +98,20 @@ public function getToken(array $apiInfo): string

/**
* 刷新token.
* @throws InvalidArgumentException
*/
public function refresh(): string
{
$accessToken = $this->request->getQueryParams()['access_token'] ?? null;
return $this->jwt->refreshToken($accessToken);
}

protected static function getRequest(): RequestInterface
{
return make(RequestInterface::class);
}

protected static function getJwtGivenScene(string $scene): JWT
{
return make(JWT::class)->setScene($scene);
}
}
Loading