1<?php
2
3namespace dokuwiki\plugin\slacknotifier\helper;
4
5use InvalidArgumentException;
6
7/**
8 * Context of the edit.
9 *
10 * Things extracted from $INFO.
11 *
12 * @property ?string $username
13 */
14class Context
15{
16    public function __get($name)
17    {
18        $method = "get$name";
19        if (!method_exists($this, $method)) {
20            throw new InvalidArgumentException("Invalid property: $name");
21        }
22
23        return $this->{$method}();
24    }
25
26    public function getUsername(): ?string
27    {
28        global $INFO, $USERINFO;
29
30        // https://github.com/michitux/dokuwiki-plugin-move/issues/235
31        $userinfo = $INFO['userinfo'] ?? $USERINFO;
32
33        return $userinfo['name'] ?? null;
34    }
35}
36