PHP code example of docplanner / tasks-bundle

1. Go to this page and download the library: Download docplanner/tasks-bundle 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/ */

    

docplanner / tasks-bundle example snippets


class SamplePayload extends BaseTaskPayload
{
	protected $someValue;
	
	public function __construct(string $someValue)
	{
		$this->someValue = $someValue;
	}

	public function getSomeValue() : string 
	{
		return $this->someValue;
	}
}

class SampleTask extends BaseTask
{
	/**
	 * @var SamplePayload $payload
	 */
	protected function execute(BaseTaskPayload $payload): bool
	{
		file_put_contents('/tmp/payload.log', var_export($payload, true) . PHP_EOL . $payload->getSomeValue());
		
		return true;
	}
	
	public function supports(BaseTaskPayload $payload): bool
	{
		return $payload instanceof SamplePayload;
	}
}

	$taskProducer = $container->get('docplanner_tasks.task_producer');

	$taskProducer->enqueue(new SamplePayload());

	$taskProducer = $container->get('docplanner_tasks.task_producer');

	$dateTime = new \DateTime('now + 2 minutes');

	$taskProducer->enqueue(new SamplePayload(), $dateTime);