PHP Artisan自定义命令

时间:2014-04-04 14:33:07

标签: php laravel laravel-4

我的php工匠需要一个自定义命令。

我通过artisan shell创建了命令文件。

但是当我通过php artisan执行它时,它会将其视为未定义。

对我来说,如何为我的命令添加参数也很困惑。

这是我的整个命令文件:

<?php

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class createLibrarySet extends Command
{

/**
 * The console command name.
 *
 * @var string
 */
protected $name = 'createLibrarySet';

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Creates a Library Set.';

/**
 * Create a new command instance.
 *
 * @return void
 */
public function __construct()
{
    parent::__construct();
}

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function fire()
{
    $dir = mkdir(app_path()."/".library."/".$this->library_name);
    $coreName = $this->library_name;
    $serivceProvider = $coreName."."."ServiceProvider.php";
    $library = $coreName."."."Library.php";
    $facade = $coreName."."."Facade.php";
    $interface = $coreName."."."Interface.php";
    fopen($dir."/".$library, "w");
    fopen($dir."/".$facade, "w");
    fopen($dir."/".$serivceProvider, "w");
    fopen($dir."/".$interface, "w");
}

/**
 * Get the console command arguments.
 *
 * @return array
 */
protected function getArguments()
{
    return array(
        array('example', InputArgument::REQUIRED, 'An example argument.'),
    );
}

/**
 * Get the console command options.
 *
 * @return array
 */
protected function getOptions()
{
    return array(
        array('example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null),
    );
}

}

1 个答案:

答案 0 :(得分:3)

您必须将命令添加到app/start/artisan.php

Artisan::resolve('createLibrarySet');

现在你应该可以在

中看到
php artisan

列表。

要得到你的论点,你只需要:

$email = $this->argument('email');

和选项

$force = $this->option('force');
相关问题