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