Your cart is empty!
Prepare Dispatcher
public function onPrepareCronDispatcher( Dispatcher $cronDispatcher ) : void
Fires while constructing the cron jobs dispatcher.
Description
Trigger hook to let the plugins alter the cron jobs dispatcher. It is possible to use this hook to implement custom cron jobs.
In order to extend the list of supported cron jobs, you need to attach your classes to the $cronDispatcher object, which can be done through the code below.
$cronDispatcher->registerCronProvider('test_cron', function(int $id) {
require_once dirname(__FILE__) . '/crons/TestCron.php';
return new TestCron($id);
});
The registered cron jobs must inherit the E4J\VikRestaurants\Cron\CronJob class, otherwise they will be ignored.
Parameters
- $cronDispatcher
-
(Dispatcher) The cron dispatcher instance. This class is part of the
E4J\VikRestaurants\Cronnamespace.
Return Value
None.
Example
The example below explains how to support a custom cron job.
/**
* Trigger event to let the plugins alter the cron dispatcher.
* It is possible to use this event to include third-party cron jobs.
*
* @param E4J\VikRestaurants\Cron\Dispatcher $cronDispatcher
*
* @return void
*/
public function onPrepareCronDispatcher($cronDispatcher)
{
// register "test_cron" job
$cronDispatcher->registerCronProvider('test_cron', function(int $id) {
// anonymous classes are supported too, but still need to inherit the CronJob class
return new class (int $id) extends E4J\VikRestaurants\Cron\CronJob {
/**
* @inheritDoc
*/
public function getTitle()
{
return 'Test Cron';
}
/**
* @inheritDoc
*/
public function getDescription()
{
return 'Testing the implementation of a custom cron job.';
}
/**
* @inheritDoc
*/
public function getForm()
{
// configuration parameters go here
return [];
}
/**
* @inheritDoc
*/
protected function execute(\JRegistry $args, \E4J\VikRestaurants\Cron\Status $status);
{
/**
* @todo do stuff here
*/
}
};
});
}
Changelog
| Version | Description |
|---|---|
| 1.10 | Introduced. |
Last Update: 23 hours ago.
Helpful?