为了账号安全,请及时绑定邮箱和手机立即绑定

MigrateMakeCommand.php

标签:
PHP

<?php

 

namespace Illuminate\Database\Console\Migrations;

 

use Illuminate\Support\Composer;

use Illuminate\Database\Migrations\MigrationCreator;

// namespace a

class MigrateMakeCommand extends BaseCommand

{// MigrateMakeCommand extends BaseCommand

    /**

     * The console command signature.

     *

     * @var string

     */

   // The console command signature.

    protected $signature = 'make:migration {name : The name of the migration.}

        {--create= : The table to be created.}

        {--table= : The table to migrate.}

        {--path= : The location where the migration file should be created.}';

   // too long signature

 

    /**

     * The console command description.

     *

     * @var string

     */

    protected $description = 'Create a new migration file';// description

 

    /**

     * The migration creator instance.

     *

     * @var \Illuminate\Database\Migrations\MigrationCreator

     */

    protected $creator;//The migration creator instance.

 

    /**

     * The Composer instance.

     *

     * @var \Illuminate\Support\Composer

     */

    protected $composer;// set composer

 

    /**

     * Create a new migration install command instance.

     *

     * @param  \Illuminate\Database\Migrations\MigrationCreator  $creator

     * @param  \Illuminate\Support\Composer  $composer

     * @return void

     */

    public function __construct(MigrationCreator $creator, Composer $composer)

    {

        parent::__construct();

 

        $this->creator = $creator;

        $this->composer = $composer;

    }// __construct

 

    /**

     * Execute the console command.

     *

     * @return void

     */

    public function fire()

    {// fire just execute the console command

        // It's possible for the developer to specify the tables to modify in this

        // schema operation. The developer may also specify if this table needs

        // to be freshly created so we can create the appropriate migrations.

        $name = $this->input->getArgument('name');// get name

 

        $table = $this->input->getOption('table');// get table

 

        $create = $this->input->getOption('create');// get create

 

        if (! $table && is_string($create)) {

            $table = $create;

        }// set table be create

 

        // 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);

       // a wrap function to migration something and write it.

 

        $this->composer->dumpAutoloads();// use Auto loads

    }

 

    /**

     * Write the migration file to disk.

     *

     * @param  string  $name

     * @param  string  $table

     * @param  bool    $create

     * @return string

     */

    protected function writeMigration($name, $table, $create)

    {// write the migration file to disk

        $path = $this->getMigrationPath();// set the path

 

        $file = pathinfo($this->creator->create($name, $path, $table, $create), PATHINFO_FILENAME);

// get file

        $this->line("<info>Created Migration:</info> $file");

    }// use a big wrap function

 

    /**

     * Get migration path (either specified by '--path' option or default location).

     *

     * @return string

     */

    protected function getMigrationPath()

    {// Get migration path (either specified by "--path" option or default location)

        if (! is_null($targetPath = $this->input->getOption('path'))) {

            return $this->laravel->basePath().'/'.$targetPath;

        }// get this son class base path

 

        return parent::getMigrationPath();// use default path.

    }

}

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消