class ReportWorkerBase
Same name in other branches
- 3.x modules/cron_example/src/Plugin/QueueWorker/ReportWorkerBase.php \Drupal\cron_example\Plugin\QueueWorker\ReportWorkerBase
- 4.0.x modules/cron_example/src/Plugin/QueueWorker/ReportWorkerBase.php \Drupal\cron_example\Plugin\QueueWorker\ReportWorkerBase
Provides base functionality for the ReportWorkers.
Hierarchy
- class \Drupal\cron_example\Plugin\QueueWorker\ReportWorkerBase extends \Drupal\Core\Queue\QueueWorkerBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\Messenger\MessengerTrait
Expanded class hierarchy of ReportWorkerBase
File
-
cron_example/
src/ Plugin/ QueueWorker/ ReportWorkerBase.php, line 16
Namespace
Drupal\cron_example\Plugin\QueueWorkerView source
abstract class ReportWorkerBase extends QueueWorkerBase implements ContainerFactoryPluginInterface {
use StringTranslationTrait;
use MessengerTrait;
/**
* The state.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* ReportWorkerBase constructor.
*
* @param array $configuration
* The configuration of the instance.
* @param string $plugin_id
* The plugin id.
* @param mixed $plugin_definition
* The plugin definition.
* @param \Drupal\Core\State\StateInterface $state
* The state service the instance should use.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* The logger service the instance should use.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, StateInterface $state, LoggerChannelFactoryInterface $logger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->state = $state;
$this->logger = $logger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$form = new static($configuration, $plugin_id, $plugin_definition, $container->get('state'), $container->get('logger.factory'));
$form->setMessenger($container->get('messenger'));
return $form;
}
/**
* Simple reporter log and display information about the queue.
*
* @param int $worker
* Worker number.
* @param object $item
* The $item which was stored in the cron queue.
*/
protected function reportWork($worker, $item) {
if ($this->state
->get('cron_example_show_status_message')) {
$this->messenger()
->addMessage($this->t('Queue @worker worker processed item with sequence @sequence created at @time', [
'@worker' => $worker,
'@sequence' => $item->sequence,
'@time' => date('c', $item->created),
]));
}
$this->logger
->get('cron_example')
->info('Queue @worker worker processed item with sequence @sequence created at @time', [
'@worker' => $worker,
'@sequence' => $item->sequence,
'@time' => date('c', $item->created),
]);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
ReportWorkerBase::$logger | protected | property | The logger. |
ReportWorkerBase::$state | protected | property | The state. |
ReportWorkerBase::create | public static | function | |
ReportWorkerBase::reportWork | protected | function | Simple reporter log and display information about the queue. |
ReportWorkerBase::__construct | public | function | ReportWorkerBase constructor. |