]> git.mxchange.org Git - friendica.git/blob - src/Core/Worker/Factory/Process.php
Refactor Process for new paradigm
[friendica.git] / src / Core / Worker / Factory / Process.php
1 <?php
2
3 namespace Friendica\Core\Worker\Factory;
4
5 use Friendica\BaseFactory;
6 use Friendica\Capabilities\ICanCreateFromTableRow;
7 use Friendica\Core\Worker\Entity;
8
9 class Process extends BaseFactory implements ICanCreateFromTableRow
10 {
11         public function createFromTableRow(array $row): Entity\Process
12         {
13                 return new Entity\Process(
14                         $row['pid'],
15                         $row['command'],
16                         new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC'))
17                 );
18         }
19
20         /**
21          * Creates a new process entry for a given PID
22          *
23          * @param int $pid
24          *
25          * @return Entity\Process
26          */
27         public function create(int $pid): Entity\Process
28         {
29                 $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
30
31                 $command = basename($trace[0]['file']);
32
33                 return $this->createFromTableRow([
34                         'pid'     => $pid,
35                         'command' => $command,
36                 ]);
37         }
38 }