|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright 2019 Christoph Wurst <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @author 2019 Christoph Wurst <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @license GNU AGPL version 3 or any later version |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
* |
|
23
|
|
|
*/ |
|
24
|
|
|
|
|
25
|
|
|
namespace OC\Core\Command\Broadcast; |
|
26
|
|
|
|
|
27
|
|
|
use OCP\EventDispatcher\ABroadcastedEvent; |
|
28
|
|
|
use OCP\EventDispatcher\IEventDispatcher; |
|
29
|
|
|
use Symfony\Component\Console\Command\Command; |
|
30
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
31
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
32
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
33
|
|
|
|
|
34
|
|
|
class Test extends Command { |
|
35
|
|
|
|
|
36
|
|
|
/** @var IEventDispatcher */ |
|
37
|
|
|
private $eventDispatcher; |
|
38
|
|
|
|
|
39
|
|
|
public function __construct(IEventDispatcher $eventDispatcher) { |
|
40
|
|
|
parent::__construct(); |
|
41
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function configure(): void { |
|
45
|
|
|
$this |
|
46
|
|
|
->setName('broadcast:test') |
|
47
|
|
|
->setDescription('test the SSE broadcaster') |
|
48
|
|
|
->addArgument( |
|
49
|
|
|
'uid', |
|
50
|
|
|
InputArgument::REQUIRED, |
|
51
|
|
|
'the UID of the users to receive the event' |
|
52
|
|
|
) |
|
53
|
|
|
->addArgument( |
|
54
|
|
|
'name', |
|
55
|
|
|
InputArgument::OPTIONAL, |
|
56
|
|
|
'the event name', |
|
57
|
|
|
'test' |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) { |
|
62
|
|
|
$name = $input->getArgument('name'); |
|
63
|
|
|
$uid = $input->getArgument('uid'); |
|
64
|
|
|
|
|
65
|
|
|
$event = new class($name, $uid) extends ABroadcastedEvent { |
|
66
|
|
|
/** @var string */ |
|
67
|
|
|
private $name; |
|
68
|
|
|
/** @var string */ |
|
69
|
|
|
private $uid; |
|
70
|
|
|
|
|
71
|
|
|
public function __construct(string $name, |
|
72
|
|
|
string $uid) { |
|
73
|
|
|
parent::__construct(); |
|
74
|
|
|
$this->name = $name; |
|
75
|
|
|
$this->uid = $uid; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function broadcastAs(): string { |
|
79
|
|
|
return $this->name; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getUids(): array { |
|
83
|
|
|
return [ |
|
84
|
|
|
$this->uid, |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function jsonSerialize() { |
|
89
|
|
|
return [ |
|
90
|
|
|
'description' => 'this is a test event', |
|
91
|
|
|
]; |
|
92
|
|
|
} |
|
93
|
|
|
}; |
|
94
|
|
|
|
|
95
|
|
|
$this->eventDispatcher->dispatch('broadcasttest', $event); |
|
96
|
|
|
|
|
97
|
|
|
return 0; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|