‪TYPO3CMS  ‪main
TaskSerializer.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 
28 {
36  public function ‪deserialize(string $serializedTask): ‪AbstractTask
37  {
38  try {
39  $task = @unserialize($serializedTask);
40  if ($task === false) {
41  throw new ‪InvalidTaskException('The serialized task is corrupted', 1642956282);
42  }
43  if (!$task instanceof ‪AbstractTask) {
44  throw new ‪InvalidTaskException('The deserialized task in not an instance of AbstractTask', 1642954501);
45  }
46  return $task;
47  } catch (\BadMethodCallException $e) {
48  // This can happen, if a Task has a dependency to a class with the BlockSerializationTrait.
49  throw new ‪InvalidTaskException($e->getMessage(), 1642938352);
50  }
51  }
52 
58  public function ‪resolveClassName(object $task): string
59  {
60  $taskClass = get_class($task);
61  if ($taskClass === '__PHP_Incomplete_Class') {
62  $taskArray = json_decode((string)json_encode($task, 0, 1), true);
63  $taskClass = (string)$taskArray['__PHP_Incomplete_Class_Name'];
64  }
65  return $taskClass;
66  }
67 
72  public function ‪extractClassName(string $serializedTask): ?string
73  {
74  if (preg_match('/^O:[0-9]+:"(?P<classname>[^"]+)"/', $serializedTask, $matches) === 1) {
75  return $matches['classname'];
76  }
77  return null;
78  }
79 }
‪TYPO3\CMS\Scheduler\Task
Definition: AbstractTask.php:16
‪TYPO3\CMS\Scheduler\Task\TaskSerializer
Definition: TaskSerializer.php:28
‪TYPO3\CMS\Scheduler\Task\AbstractTask
Definition: AbstractTask.php:33
‪TYPO3\CMS\Scheduler\Task\TaskSerializer\extractClassName
‪extractClassName(string $serializedTask)
Definition: TaskSerializer.php:72
‪TYPO3\CMS\Scheduler\Task\TaskSerializer\resolveClassName
‪class string< T > string resolveClassName(object $task)
Definition: TaskSerializer.php:58
‪TYPO3\CMS\Scheduler\Task\TaskSerializer\deserialize
‪deserialize(string $serializedTask)
Definition: TaskSerializer.php:36
‪TYPO3\CMS\Scheduler\Exception\InvalidTaskException
Definition: InvalidTaskException.php:26