for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the Commander project.
*
* @author Daniel Schröder <[email protected]>
*/
namespace GravityMedia\Commander\Commander;
use Doctrine\ORM\EntityManagerInterface;
use GravityMedia\Commander\ORM\TaskEntity;
* Task class.
* @package GravityMedia\Commander\Commander
class Task
{
* The entity manager.
* @var EntityManagerInterface
protected $entityManager;
* The entity.
* @var TaskEntity
protected $entity;
* Create task object.
* @param EntityManagerInterface $entityManager
* @param TaskEntity $entity
public function __construct(EntityManagerInterface $entityManager, TaskEntity $entity)
$this->entityManager = $entityManager;
$this->entity = $entity;
}
* Get entity
* @return TaskEntity
public function getEntity()
return $this->entity;
* Prioritize task.
* @param int $priority
* @return $this
public function prioritize($priority)
$this->entity->setPriority($priority);
$this->entityManager->flush();
return $this;
* Defer task.
* @param int $pid
* @param callable $deferrer
public function defer($pid, $deferrer)
$connection = $this->entityManager->getConnection();
$this->entity->setPid($pid);
$connection->close();
$exitCode = $deferrer();
$connection->connect();
$this->entity->setExitCode($exitCode);
* Remove task.
public function remove()
$this->entityManager->remove($this->entity);