Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| Memory | |
100.00% |
7 / 7 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| write | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| read | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| all | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Queue\Registry\Adapter; |
| 16 | |
| 17 | use Pop\Queue\Registry\AbstractRegistry; |
| 18 | use Pop\Queue\Registry\WorkerRecord; |
| 19 | |
| 20 | /** |
| 21 | * In-memory registry class |
| 22 | * |
| 23 | * A hermetic, single-process reference implementation of the registry |
| 24 | * contract. Because it never leaves the process it can't provide real |
| 25 | * cross-process visibility - it exists to prove the contract in tests and |
| 26 | * to serve as a fake for consumers testing against this package. |
| 27 | * |
| 28 | * @category Pop |
| 29 | * @package Pop\Queue |
| 30 | * @author Nick Sagona, III <nick@popphp.org> |
| 31 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 32 | * @license https://www.popphp.org/license New BSD License |
| 33 | * @version 3.0.0 |
| 34 | */ |
| 35 | class Memory extends AbstractRegistry |
| 36 | { |
| 37 | |
| 38 | /** |
| 39 | * Records, keyed by worker ID |
| 40 | * @var array |
| 41 | */ |
| 42 | protected array $records = []; |
| 43 | |
| 44 | public function write(WorkerRecord $record): void |
| 45 | { |
| 46 | // Store the flattened form so callers can't mutate what's "stored" |
| 47 | // by holding on to the object they passed in. |
| 48 | $this->records[$record->getId()] = $record->toArray(); |
| 49 | } |
| 50 | |
| 51 | public function read(string $id): ?WorkerRecord |
| 52 | { |
| 53 | return isset($this->records[$id]) ? WorkerRecord::fromArray($this->records[$id]) : null; |
| 54 | } |
| 55 | |
| 56 | public function all(): array |
| 57 | { |
| 58 | $records = []; |
| 59 | foreach ($this->records as $id => $data) { |
| 60 | $records[$id] = WorkerRecord::fromArray($data); |
| 61 | } |
| 62 | |
| 63 | return $records; |
| 64 | } |
| 65 | |
| 66 | public function delete(string $id): void |
| 67 | { |
| 68 | unset($this->records[$id]); |
| 69 | } |
| 70 | |
| 71 | } |