【发布时间】:2014-05-19 19:41:05
【问题描述】:
我的 php artisan 需要一个自定义命令。
我已经通过 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),
);
}
}
【问题讨论】:
-
你为什么要执行所有这些 fopen() 调用,然后无法捕获文件句柄?如果您打算实际写入这些文件,则需要文件句柄来执行此操作,而您将丢失所有这些文件。
-
不,该部分不完整,不是我关心的问题,我现在关心的是工匠界面