我正在制作一个使用Laravel 5的应用程序,此刻我遇到了一个小问题(我希望)。 所以我编码实现ShouldBeQueued像这样的命令:Laravel 5排队命令
class ImportDataCommand extends Command implements SelfHandling,ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
public $filePath;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($filePath)
{
$this->filePath = $filePath;
Log::info('queued shit from command contructor and i have this destinationPath => '.$filePath);//working
echo "contructor ".$this->filePath;
}
/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$destinationPath = storage_path().'/app/gtfs/';
$zip = new ZipArchive;
echo "handle ".$this->filePath;
/*$res = $zip->open($destinationPath.$this->filePath);
if ($res === TRUE) {
$zip->extractTo($destinationPath.'extracted/');
$zip->close();
echo 'done';
} else {
echo 'fail';
}*/
}
}
我打电话这样说:
$bus->dispatch(new ImportDataCommand($fileName));
时,在队列中(顺便说一句后执行命令我的问题是我使用beanstalkd
)它引发异常,因为filePath
没有设置,我想我已经明白了为什么会发生这种情况,当我用变量将它发送到busDispatcher
上的队列时,该命令被实例化,但是当调用handle()
时队列方面它没有发送。有什么建议么 ?
抱歉它是一个错字,现在固定 – danielgek
如果我正好运行它,因为它是现在,我得到[Symfony的\分量\调试\异常\ FatalErrorException] 无法访问空属性 – danielgek
你从哪里得到这个错误? –