PHP code example of sunvalley-technologies / php-task-manager-symfony-bundle

1. Go to this page and download the library: Download sunvalley-technologies/php-task-manager-symfony-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/ */

    

sunvalley-technologies / php-task-manager-symfony-bundle example snippets




class ExampleTask extends \SunValley\TaskManager\Symfony\Task\AbstractSymfonyTask {
    


    protected function __run(\SunValley\TaskManager\ProgressReporter $reporter,\Symfony\Component\DependencyInjection\ContainerInterface $container){
        $data = $this->getOptions()['data'];
        $entityManager = $container->get('entity_manager');
        $entity = $entityManager->find('\Some\Entity');
        $entity->setData($data);
        $entityManager->persist($entity);
        $entityManager->flush();

        return 'Task Completed'; // will be passed as $result to $reporter->finishTask($result) if it is not called or failed before 
    }

    public function buildOptionsResolver() : \Symfony\Component\OptionsResolver\OptionsResolver{
        $resolver = new Symfony\Component\OptionsResolver\OptionsResolver();
        $resolver->setRequired('data');
        return $resolver;
    }

}

class MyService {
    use \Symfony\Component\DependencyInjection\ContainerAwareTrait;

    public function changeDataOnBackground($data) {
        $task = new ExampleTask(uniqid('', true), ['data' => $data]); // this can throw an exception if options are invalid
        $this->container->get('php_task_manager_client')->submitTaskSync($task);
    }
}

class MyAsyncService {

    /** @var \SunValley\TaskManager\Symfony\Task\TaskManagerFactory */
    private $taskManagerFactory;

    public function __construct($taskManagerFactory) { $this->taskManagerFactory = $taskManagerFactory; }

    public function changeDataOnBackground($data): \React\Promise\PromiseInterface {
        $task = new ExampleTask(uniqid('', true), ['data' => $data]); // this can throw an exception if options are invalid

        return $this->taskManagerFactory->generate()->submitTask($task);
    }
}