QueuedCommand.php
TLDR
This file contains the QueuedCommand
class, which is used for queuing and handling Artisan commands in Laravel.
Methods
__construct($data)
This method is the constructor of the QueuedCommand
class. It receives an array of data and sets it to the $data
property.
handle(KernelContract $kernel)
This method is used to handle the job. It calls the call
method on the $kernel
instance with the values of the $data
property as arguments.
displayName()
This method returns the display name for the queued job, which is the first value in the $data
array.
Classes
QueuedCommand
This class represents a queued command in Laravel. It implements the ShouldQueue
interface and uses the Dispatchable
and Queueable
traits. It has a constructor for setting the $data
property and a handle
method for executing the command. Additionally, it has a displayName
method for getting the display name of the queued job.
<?php
namespace Illuminate\Foundation\Console;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Console\Kernel as KernelContract;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class QueuedCommand implements ShouldQueue
{
use Dispatchable, Queueable;
/**
* The data to pass to the Artisan command.
*
* @var array
*/
protected $data;
/**
* Create a new job instance.
*
* @param array $data
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Handle the job.
*
* @param \Illuminate\Contracts\Console\Kernel $kernel
* @return void
*/
public function handle(KernelContract $kernel)
{
$kernel->call(...array_values($this->data));
}
/**
* Get the display name for the queued job.
*
* @return string
*/
public function displayName()
{
return array_values($this->data)[0];
}
}