Closed andruu closed 1 year ago
Hello, I'm trying to pass the $command variable into the handle method to update progress from artisan command line. I keep on running into the error: Cannot access protected property Lorisleiva\Actions\Decorators\CommandDecorator::$output
$command
handle
Cannot access protected property Lorisleiva\Actions\Decorators\CommandDecorator::$output
Here is the code that I'm using:
<?php public function asCommand(Command $command): void { $command->info('Processing data'); $inputData = $command->ask('Enter input data'); $summary = $this->handle($inputData, $command); $command->info('Processed ' . $summary['pages'] . ' pages'); $command->info('Processed ' . count($summary['data_links_1']) . ' data links 1'); $command->info('Processed ' . count($summary['data_links_2']) . ' data links 2'); } public function handle(string $inputData, Command $commandLine = null): array { $dataLinks1 = collect(); $dataLinks2 = collect(); $this->setupBrowser(); $crawler = $this->makeRequest($inputData, 1); $params = $this->parseResponse($crawler); $pages = $this->extractNumberOfPages($crawler); $dataLinks1 = $dataLinks1->merge($this->generateDataLinks1($params)); $dataLinks2 = $dataLinks2->merge($this->generateDataLinks2($params)); $commandLine?->output->progressStart($pages); collect()->range(2, $pages)->each(function ($page) use ($inputData, $commandLine, &$dataLinks1, &$dataLinks2) { $crawler = $this->makeRequest($inputData, $page); $params = $this->parseResponse($crawler); $dataLinks1 = $dataLinks1->merge($this->generateDataLinks1($params)); $dataLinks2 = $dataLinks2->merge($this->generateDataLinks2($params)); $commandLine?->output->progressAdvance(); }); $commandLine?->output->progressFinish(); return [ 'pages' => $pages, 'data_links_1' => $dataLinks1, 'data_links_2' => $dataLinks2, ]; } ?>
I figured it out instead of $command->output I needed to use $command->getOutput()
$command->output
$command->getOutput()
Hello, I'm trying to pass the
$command
variable into thehandle
method to update progress from artisan command line. I keep on running into the error:Cannot access protected property Lorisleiva\Actions\Decorators\CommandDecorator::$output
Here is the code that I'm using: