PHP code example of tobento / app-schedule

1. Go to this page and download the library: Download tobento/app-schedule 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/ */

    

tobento / app-schedule example snippets


use Tobento\App\AppFactory;
use Tobento\Service\Schedule\ScheduleInterface;
use Tobento\Service\Schedule\ScheduleProcessorInterface;
use Tobento\Service\Schedule\TaskProcessorInterface;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots
$app->boot(\Tobento\App\Schedule\Boot\Schedule::class);
$app->booting();

// Implemented interfaces:
$schedule = $app->get(ScheduleInterface::class);
$scheduleProcessor = $app->get(ScheduleProcessorInterface::class);
$taskProcessor = $app->get(TaskProcessorInterface::class);

// Run the app
$app->run();

use Tobento\App\AppFactory;
use Tobento\Service\Schedule\ScheduleInterface;

// Create the app
$app = (new AppFactory())->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Schedule\Boot\Schedule::class);

// Adding tasks:
$app->on(ScheduleInterface::class, static function(ScheduleInterface $schedule): void {
    $schedule->task($task);
});

// Run the app
$app->run();

use Tobento\App\Boot;
use Tobento\App\Schedule\Boot\Schedule;
use Tobento\Service\Schedule\ScheduleInterface;

class MyScheduleTasksBoot extends Boot
{
    public const BOOT = [
        // you may ensure the schedule boot.
        Schedule::class,
    ];
    
    public function boot()
    {
        $this->app->on(ScheduleInterface::class, static function(ScheduleInterface $schedule): void {
            $schedule->task($task);
        });
    }
}