|
1 | 1 | <?php |
2 | 2 |
|
| 3 | +declare(strict_types=1); |
| 4 | + |
3 | 5 | /** |
4 | 6 | * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors |
5 | 7 | * SPDX-FileCopyrightText: 2016 ownCloud, Inc. |
|
12 | 14 |
|
13 | 15 | class QueueBus implements IBus { |
14 | 16 | /** |
15 | | - * @var ICommand[]|callable[] |
| 17 | + * @var ICommand[] |
16 | 18 | */ |
17 | | - private $queue = []; |
| 19 | + private array $queue = []; |
18 | 20 |
|
19 | 21 | /** |
20 | 22 | * Schedule a command to be fired |
21 | | - * |
22 | | - * @param \OCP\Command\ICommand | callable $command |
23 | 23 | */ |
24 | | - public function push($command) { |
| 24 | + public function push(ICommand $command): void { |
25 | 25 | $this->queue[] = $command; |
26 | 26 | } |
27 | 27 |
|
28 | 28 | /** |
29 | 29 | * Require all commands using a trait to be run synchronous |
30 | | - * |
31 | | - * @param string $trait |
32 | 30 | */ |
33 | | - public function requireSync($trait) { |
| 31 | + public function requireSync(string $trait): void { |
34 | 32 | } |
35 | 33 |
|
36 | | - /** |
37 | | - * @param \OCP\Command\ICommand | callable $command |
38 | | - */ |
39 | | - private function runCommand($command) { |
40 | | - if ($command instanceof ICommand) { |
41 | | - // ensure the command can be serialized |
42 | | - $serialized = serialize($command); |
43 | | - if (strlen($serialized) > 4000) { |
44 | | - throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
45 | | - } |
46 | | - $unserialized = unserialize($serialized); |
47 | | - $unserialized->handle(); |
48 | | - } else { |
49 | | - $command(); |
| 34 | + private function runCommand(ICommand $command): void { |
| 35 | + // ensure the command can be serialized |
| 36 | + $serialized = serialize($command); |
| 37 | + if (strlen($serialized) > 4000) { |
| 38 | + throw new \InvalidArgumentException('Trying to push a command which serialized form can not be stored in the database (>4000 character)'); |
50 | 39 | } |
| 40 | + $unserialized = unserialize($serialized, ['allowed_classes' => [ |
| 41 | + \Test\Command\SimpleCommand::class, |
| 42 | + \Test\Command\StateFullCommand::class, |
| 43 | + \Test\Command\FilesystemCommand::class, |
| 44 | + \OCA\Files_Trashbin\Command\Expire::class, |
| 45 | + \OCA\Files_Versions\Command\Expire::class, |
| 46 | + ]]); |
| 47 | + $unserialized->handle(); |
51 | 48 | } |
52 | 49 |
|
53 | | - public function run() { |
| 50 | + public function run(): void { |
54 | 51 | while ($command = array_shift($this->queue)) { |
55 | 52 | $this->runCommand($command); |
56 | 53 | } |
|
0 commit comments