PHP code example of buzzingpixel / craft-scheduler
1. Go to this page and download the library: Download buzzingpixel/craft-scheduler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
buzzingpixel / craft-scheduler example snippets
use BuzzingPixel\CraftScheduler\ScheduleRetrieval\RetrieveSchedule;
use BuzzingPixel\CraftScheduler\ScheduleRetrieval\RetrieveScheduleEvent;
use BuzzingPixel\CraftScheduler\ScheduleRetrieval\ScheduleConfigItem;
use BuzzingPixel\CraftScheduler\Frequency;
use yii\base\Event;
Event::on(
RetrieveSchedule::class,
RetrieveSchedule::EVENT_RETRIEVE_SCHEDULE,
static function (RetrieveScheduleEvent $e): void {
$e->scheduleConfigItems()->addItem(item: new ScheduleConfigItem(
className: SomeClass::class, // The class to run
runEvery: Frequency::ALWAYS, // How often to run it
method: 'myOptionalMethod', // Specify method on the class to call, defaults to __invoke
resolveWith: SomeContainer::class, // Optionally provide your own ContainerInterface implementation. Defaults to the Yii container (or whatever default container you specify, see below)
));
$e->scheduleConfigItems()->addItem(item: new ScheduleConfigItem(
className: SomeOtherClass::class,
runEvery: Frequency::HOUR,
));
}
);
use BuzzingPixel\CraftScheduler\CraftSchedulerPlugin;
use BuzzingPixel\CraftScheduler\ScheduleRetrieval\SetDefaultContainerEvent;
use DI\ContainerBuilder;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\App;
use Slim\Psr7\Factory\ResponseFactory;
use yii\base\Event;
use function DI\autowire;
Event::on(
CraftSchedulerPlugin::class,
CraftSchedulerPlugin::EVEN_SET_DEFAULT_CONTAINER,
static function (SetDefaultContainerEvent $e) {
$containerBuilder = (new ContainerBuilder())
->useAnnotations(true)
->useAutowiring(true)
->ignorePhpDocErrors(true)
->addDefinitions([
ResponseFactoryInterface::class => autowire(ResponseFactory::class),
]);
$container = $containerBuilder->build();
$e->setDefaultContainer($container);
}
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.