I wish someone could help me understand this code statement found on the core cRON service (\Drupal\Core\Cron
), especially in the constructor method for this class.
public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager, TimeInterface $time = NULL) {
// Omissis
$this->time = $time ?: \Drupal::service('datetime.time');
}
What does this line do? Why isn't $this->time = $time;
instead used?
The service is already injected using arguments.
class: Drupal\Core\Cron
arguments:
- '@module_handler'
- '@lock'
- '@queue'
- '@state'
- '@account_switcher'
- '@logger.channel.cron'
- '@plugin.manager.queue_worker'
- '@datetime.time'
lazy: true