| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\File;
- define("ROOT_PATH",dirname(dirname(dirname(__DIR__))));
- class createModule extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'module:create {name} {module?} {app?}';
- protected $root=ROOT_PATH;
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'create module or model or controller or lib ';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $proj=$this->argument('name');
- switch($proj){
- case "module":
- $this->cdir();
- break;
- case "controller":
- $this->cController();
- break;
- case "model":
- $this->cModel();
- break;
- case "lib":
- $this->cLib();
- break;
- default:
- break;
- }
-
- }
- protected function cLib(){
- $app=$this->argument('module');
- $app=ucfirst($app);
- $module=$this->root."/module/";
- $path=$module."/Lib"."/";
- if(!File::exists($path)){
- File::makeDirectory($path);
- }
- $path=$module."/Lib"."/".ucfirst($app).".php";
- $content="<?php ".chr(9).chr(13).
- "namespace Module\\Lib;".chr(9).chr(13).
- "class ".ucfirst($app)." {".chr(9).chr(13).
- "}";
- File::put($path,$content);
- }
- protected function cController()
- {
- $proj=$this->argument('module');
- $app=$this->argument('app');
- $proj=ucfirst($proj);
- $module=$this->root."/module/".$proj."/";
- $path=$module."/Controller"."/".ucfirst($app).".php";
- $content="<?php ".chr(9).chr(13).
- "namespace Module\\$proj\Controller;".chr(9).chr(13).
- "class ".ucfirst($app)." extends BaseController{".chr(9).chr(13).
- " function _init(){".chr(9).chr(13).
- " }".chr(9).chr(13).
- "}";
- File::put($path,$content);
- }
- protected function cBaseController()
- {
- $proj=$this->argument('module');
- $proj=ucfirst($proj);
- $module=$this->root."/module/".$proj."/";
- $path=$module."/Controller"."/BaseController.php";
- $content="<?php".chr(9).chr(13).
- "namespace Module\\$proj\Controller;".chr(9).chr(13).
- "class BaseController extends \\Module\\Controller{".chr(9).chr(13).
- " function _init(){".chr(9).chr(13).
- " }".chr(9).chr(13).
- " function __construct(){".chr(9).chr(13).
- " \$this->_init();".chr(9).chr(13).
- " }".chr(9).chr(13).
- "}";
- File::put($path,$content);
- }
- protected function cBaseModel()
- {
- $proj=$this->argument('module');
- $proj=ucfirst($proj);
- $module=$this->root."/module/".$proj."/";
- $path=$module."/Model"."/BaseModel.php";
- $content="<?php".chr(9).chr(13).
- "namespace Module\\$proj\Model;".chr(9).chr(13).
- "class BaseModel extends \Illuminate\Database\Eloquent\Model{".chr(9).chr(13).
- "}";
- File::put($path,$content);
- }
- protected function cModel()
- {
- $proj=$this->argument('module');
- $model=$this->argument('app');
- $proj=ucfirst($proj);
- $model=ucfirst($model);
- $module=$this->root."/module/".$proj."/";
- $path=$module."/Model"."/$model.php";
- $content="<?php".chr(9).chr(13).
- "namespace Module\\$proj\Model;".chr(9).chr(13).
- "class $model extends BaseModel{".chr(9).chr(13).
- "}";
- File::put($path,$content);
- }
- protected function cdir()
- {
- $proj=$this->argument('module');
- $proj=ucfirst($proj);
- $module=$this->root."/module/".$proj."/";
- File::makeDirectory($module);
- $path=$module."/Model"."/";
- File::makeDirectory($path);
- $path=$module."/Controller"."/";
- File::makeDirectory($path);
- $path=$this->root."/resources/views/".lcfirst($proj)."/";
- File::makeDirectory($path);
- $this->cBaseController();
- $this->cBaseModel();
- }
- }
|