Ist die Abhängigkeitsinjektion einer benutzerdefinierten Klasse in einer command
möglich?Laravel: Abhängigkeitsinjektion in Befehlen
Ich versuche dies:
<?php
namespace vendor\package\Commands;
use Illuminate\Console\Command;
use vendor\package\Models\Log;
use vendor\package\Updates\UpdateStatistics;
class UpdatePublishmentStats extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'vendorname:updatePublishmentStats';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Updates Twitter followers & Facebook page likes';
/**
* Contact implementation
* @var vendor\package\Update\UpdateStatistics
*/
protected $stats;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct(
Log $log,
UpdateStatistics $stats
) {
parent::__construct();
$this->log = $log;
$this->stats = $stats;
}
Aber wenn ich versuche, dies zu tun:
public function handle()
{
$this->stats->updateFbStats();
}
ich plötzlich Segmentation fault: 11
Wenn ich den use vendor\package\Updates\UpdateStatistics;
Teil löschen, I don‘ t bekomme diesen Fehler.
Also, was mache ich hier falsch? Ist es nicht möglich, die Abhängigkeitsinjektion in einem Befehl zu verwenden?