2016-12-29 19:16:04 -06:00
|
|
|
<?php
|
2016-08-21 10:33:39 -05:00
|
|
|
|
2016-08-23 16:47:40 -05:00
|
|
|
namespace Amp\Parallel\Worker\Internal;
|
2016-08-21 10:33:39 -05:00
|
|
|
|
2016-08-23 16:47:40 -05:00
|
|
|
use Amp\Parallel\Worker\Task;
|
2016-08-21 10:33:39 -05:00
|
|
|
|
2017-07-27 23:49:20 -05:00
|
|
|
/** @internal */
|
2018-10-07 09:50:45 -05:00
|
|
|
class Job
|
|
|
|
{
|
2016-08-21 10:33:39 -05:00
|
|
|
/** @var string */
|
|
|
|
private $id;
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2016-08-23 16:47:40 -05:00
|
|
|
/** @var \Amp\Parallel\Worker\Task */
|
2016-08-21 10:33:39 -05:00
|
|
|
private $task;
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2018-10-07 09:50:45 -05:00
|
|
|
public function __construct(Task $task)
|
|
|
|
{
|
2017-12-13 21:28:08 -06:00
|
|
|
static $id = 'a';
|
|
|
|
|
2016-08-21 10:33:39 -05:00
|
|
|
$this->task = $task;
|
2017-12-13 21:28:08 -06:00
|
|
|
$this->id = $id++;
|
2016-08-21 10:33:39 -05:00
|
|
|
}
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2018-10-07 09:50:45 -05:00
|
|
|
public function getId(): string
|
|
|
|
{
|
2016-08-21 10:33:39 -05:00
|
|
|
return $this->id;
|
|
|
|
}
|
2017-05-18 09:51:31 +02:00
|
|
|
|
2018-10-07 09:50:45 -05:00
|
|
|
public function getTask(): Task
|
|
|
|
{
|
2017-11-22 20:42:56 -06:00
|
|
|
// Classes that cannot be autoloaded will be unserialized as an instance of __PHP_Incomplete_Class.
|
2017-11-22 21:38:11 -06:00
|
|
|
if ($this->task instanceof \__PHP_Incomplete_Class) {
|
2017-12-06 15:59:28 -06:00
|
|
|
throw new \Error(\sprintf("Classes implementing %s must be autoloadable by the Composer autoloader", Task::class));
|
2017-11-22 21:38:11 -06:00
|
|
|
}
|
|
|
|
|
2016-08-21 10:33:39 -05:00
|
|
|
return $this->task;
|
|
|
|
}
|
|
|
|
}
|