cron = $cron; $this->config = $config_factory->get('automated_cron.settings'); $this->state = $state; } /** * Run the automated cron if enabled. * * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event * The Event to process. */ public function onTerminate(PostResponseEvent $event) { $interval = $this->config->get('interval'); if ($interval > 0) { $cron_next = $this->state->get('system.cron_last', 0) + $interval; if ((int) $event->getRequest()->server->get('REQUEST_TIME') > $cron_next) { $this->cron->run(); } } } /** * Registers the methods in this class that should be listeners. * * @return array * An array of event listener definitions. */ public static function getSubscribedEvents() { return [KernelEvents::TERMINATE => [['onTerminate', 100]]]; } }