Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Various fixes for PHP 8.1 compatibility #370

Merged
merged 1 commit into from
Apr 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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