GithubHelp home page GithubHelp logo

jian1098 / tp-make-service Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 11 KB

thinkphp框架命令行创建Service Class(即服务层,基于controller-service-repository目录架构)

License: Apache License 2.0

PHP 100.00%

tp-make-service's Introduction

tp-make-service

thinkphp框架命令行创建Service Class(即服务层,基于controller-service-repository目录架构)

如何使用

  • 1.安装扩展

    # thinkphp5.*版本
    composer require jian1098/tp-make-service:1.0.1
    
    # thinkphp6.0+版本
    composer require jian1098/tp-make-service:2.0.1
  • 2.注册命令

    • Thinkphp5

      application/command.php文件中添加一行

      return [
          'Jian1098\TpMakeService\Command\Service',
      ];
    • Thinkphp6+

      config/console.php文件中添加一行

      return [
          // 指令定义
          'commands' => [
              'make:service' => 'Jian1098\TpMakeService\Command\Service',
          ],
      ];

      **注意事项:**该命令会替换tp6框架自带的make:service命令,如果不想替换,可以将上面的make:service改为其他你喜欢的指令

    配置完后,在命令行执行php think命令,可以看到增加了make:service命令

     ...
     make
      make:command       Create a new command class
      make:controller    Create a new resource controller class
      make:middleware    Create a new middleware class
      make:model         Create a new model class
      make:service       Create a new service class    # 新增加的命令
      make:validate      Create a validate class
    ...
  • 3.命令行创建文件

    php think make:service TestService

    执行上面的命令将创建文件application/common/service/TestService.php(thinkphp5)或app/service/TestService.php(thinkphp6+),内容如下

    <?php
    
    namespace app\common\service;
    
    use app\common\repository\TestRepository;
    
    class TestService
    {
        /**
         * 绑定仓库
         * @var TestRepository
         */
        protected $repository;
    
        public function __construct(TestRepository $repository)
        {
            $this->repository = $repository;
        }
    
    
    }

    创建其他的service以此类推

tp-make-service's People

Contributors

jian1098 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.