1 | <?php |
||
2 | namespace PortlandLabs\Slackbot\Command; |
||
3 | |||
4 | use PortlandLabs\Slackbot\Command\Argument\Manager; |
||
0 ignored issues
–
show
|
|||
5 | use PortlandLabs\Slackbot\Slack\Api\Payload\ReactionsAddPayload; |
||
6 | use PortlandLabs\Slackbot\Slack\Rtm\Event\Message; |
||
7 | use Symfony\Component\Console\Helper\Helper; |
||
8 | |||
9 | class InfoCommand extends SimpleCommand |
||
10 | { |
||
11 | |||
12 | protected $description = 'Get some diagnostic information'; |
||
13 | |||
14 | protected $signature = 'info'; |
||
15 | |||
16 | /** |
||
17 | * Handle a message |
||
18 | * |
||
19 | * @param Message $message |
||
20 | * @param Manager $manager |
||
21 | * |
||
22 | * @return void |
||
23 | * @throws \CL\Slack\Exception\SlackException |
||
24 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
25 | */ |
||
26 | public function run(Message $message, Manager $manager) |
||
27 | { |
||
28 | $extensions = []; |
||
29 | foreach (get_loaded_extensions() as $extension) { |
||
30 | $extensions[] = '`' . $extension . '@' . phpversion($extension) . '`'; |
||
31 | } |
||
32 | |||
33 | $details = [ |
||
34 | 'ID' => '`' . $this->bot->getId() . '`', |
||
35 | 'Uptime' => '_' . $this->bot->getUptime() . '_', |
||
36 | 'Memory Usage' => Helper::formatMemory(memory_get_usage(true)), |
||
37 | 'Peak Usage' => Helper::formatMemory(memory_get_peak_usage(true)), |
||
38 | 'userId' => $this->bot->rtm()->getUserId(), |
||
39 | 'userName' => $this->bot->rtm()->getUserName(), |
||
40 | 'PHP Version' => phpversion(), |
||
41 | 'extensions' => implode(', ', $extensions), |
||
42 | ]; |
||
43 | |||
44 | $data = []; |
||
45 | foreach ($details as $key => $detail) { |
||
46 | $data[] = "*$key:* $detail"; |
||
47 | } |
||
48 | |||
49 | $api = $this->bot->api(); |
||
50 | $builder = $api->getBuilder(); |
||
51 | |||
52 | // Send with icon |
||
53 | $builder->send(implode(PHP_EOL, $data)) |
||
54 | ->to($message->getChannel())->withIcon(':information_source:') |
||
55 | ->execute($api); |
||
56 | |||
57 | $this->bot->api()->send(ReactionsAddPayload::reactTo($message, 'the_horns')); |
||
58 | } |
||
59 | } |
||
60 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: