Commit 6dc6b0b2 authored by wmm387's avatar wmm387
Browse files

添加repository生成器命令行

parent 66b698fb
Loading
Loading
Loading
Loading
+7 −1
Original line number Original line Diff line number Diff line
@@ -12,7 +12,8 @@
  "require": {
  "require": {
    "ext-json": "*",
    "ext-json": "*",
    "hyperf/db-connection": "^1.1@dev",
    "hyperf/db-connection": "^1.1@dev",
    "hyperf/validation": "^1.1@dev"
    "hyperf/validation": "^1.1@dev",
    "hyperf/command": "^1.1@dev"
  },
  },
  "minimum-stability": "dev",
  "minimum-stability": "dev",
  "autoload": {
  "autoload": {
@@ -22,5 +23,10 @@
    "files": [
    "files": [
      "src/functions.php"
      "src/functions.php"
    ]
    ]
  },
  "extra": {
    "hyperf": {
      "config": "Meibuyu\\Micro\\ConfigProvider"
    }
  }
  }
}
}
+48 −0
Original line number Original line Diff line number Diff line
<?php

/**
 * Created by PhpStorm.
 * User: zero
 * Date: 2020/2/11
 * Time: 11:59
 */

namespace Meibuyu\Micro\Command;

use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Meibuyu\Micro\Generator\FileAlreadyExistsException;
use Meibuyu\Micro\Generator\RepositoryEloquentGenerator;
use Symfony\Component\Console\Input\InputArgument;

/**
 * @Command()
 */
class RepositoryCommand extends HyperfCommand
{

    protected $name = 'gen:repository';

    /**
     * Handle the current command.
     */
    public function handle()
    {
        try {
            $name = $this->input->getArgument('name');
            $createValidator = $this->output->confirm('同时创建验证器?', true);
            (new RepositoryEloquentGenerator([
                'name' => $name,
                'validator' => $createValidator,
            ]))->run();
            $this->info("Repository created successfully.");
        } catch (FileAlreadyExistsException $e) {
            $this->error($e->getMessage() . ' already exists!');
        }
    }

    public function getArguments()
    {
        return [['name', InputArgument::REQUIRED, '名称']];
    }
}
 No newline at end of file
+45 −0
Original line number Original line Diff line number Diff line
<?php

/**
 * Created by PhpStorm.
 * User: wangy
 * Date: 2020/2/12
 * Time: 10:49
 */

namespace Meibuyu\Micro\Command;

use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Meibuyu\Micro\Generator\FileAlreadyExistsException;
use Meibuyu\Micro\Generator\ValidatorGenerator;
use Symfony\Component\Console\Input\InputArgument;

/**
 * @Command()
 */
class ValidatorCommand extends HyperfCommand
{

    protected $name = 'gen:validator';

    /**
     * Handle the current command.
     */
    public function handle()
    {
        try {
            $name = $this->input->getArgument('name');
            (new ValidatorGenerator(['name' => $name]))->run();
            $this->info("Validator created successfully.");
        } catch (FileAlreadyExistsException $e) {
            $this->error($e->getMessage() . ' already exists!');
        }
    }

    public function getArguments()
    {
        return [['name', InputArgument::REQUIRED, '名称']];
    }

}
 No newline at end of file

src/ConfigProvider.php

0 → 100644
+25 −0
Original line number Original line Diff line number Diff line
<?php

/**
 * Created by PhpStorm.
 * User: zero
 * Date: 2020/2/11
 * Time: 11:49
 */

namespace Meibuyu\Micro;


class ConfigProvider
{
    public function __invoke(): array
    {
        return [
            'commands' => [
                \Meibuyu\Micro\Command\RepositoryCommand::class,
                \Meibuyu\Micro\Command\ValidatorCommand::class,
            ],
        ];
    }

}
 No newline at end of file
+15 −0
Original line number Original line Diff line number Diff line
<?php

/**
 * Created by PhpStorm.
 * User: zero
 * Date: 2020/2/11
 * Time: 15:23
 */

namespace Meibuyu\Micro\Generator;


class FileAlreadyExistsException extends \Exception
{
}
 No newline at end of file
Loading