Skip to content

Commit

Permalink
ENH Various fixes for PHP 8.1 compatibility (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz authored Apr 13, 2022
1 parent c31a503 commit 03ded57
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/Jobs/DoormanQueuedJobTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,41 +72,55 @@ public function __construct(QueuedJobDescriptor $descriptor)
$this->descriptor = $descriptor;
}

public function __serialize(): array
{
return [
'descriptor' => $this->descriptor->ID,
];
}

public function __unserialize(array $data): void
{
if (!isset($data['descriptor'])) {
throw new InvalidArgumentException('Malformed data');
}
$descriptor = QueuedJobDescriptor::get()
->filter('ID', $data['descriptor'])
->first();
if (!$descriptor) {
throw new InvalidArgumentException('Descriptor not found');
}
$this->descriptor = $descriptor;
}

/**
* The __serialize() magic method will be automatically used instead of this
*
* @inheritdoc
*
* @return string
* @deprecated will be removed in 5.0
*/
public function serialize()
{
return serialize(array(
'descriptor' => $this->descriptor->ID,
));
return serialize($this->__serialize);
}

/**
* The __unserialize() magic method will be automatically used instead of this almost all the time
* This method will be automatically used if existing serialized data was not saved as an associative array
* and the PHP version used in less than PHP 9.0
*
* @inheritdoc
*
* @throws InvalidArgumentException
* @param string
* @deprecated will be removed in 5.0
*/
public function unserialize($serialized)
{
$data = unserialize($serialized);

if (!isset($data['descriptor'])) {
throw new InvalidArgumentException('Malformed data');
}

$descriptor = QueuedJobDescriptor::get()
->filter('ID', $data['descriptor'])
->first();

if (!$descriptor) {
throw new InvalidArgumentException('Descriptor not found');
}

$this->descriptor = $descriptor;
$this->__unserialize($data);
}

/**
Expand Down

0 comments on commit 03ded57

Please sign in to comment.