PHPDaemon\Applications\GibsonREST\Request::init PHP Method

init() public method

* Constructor.
public init ( )
    public function init()
    {
        try {
            $this->header('Content-Type: text/plain');
            //$this->header('Content-Type: application/x-json');
        } catch (\Exception $e) {
        }
        if (!$this->importCmdArgs()) {
            return;
        }
        $this->sleep(5, true);
        // setting timeout 5 seconds */
        $this->onSessionStart(function () {
            $this->wakeup();
            if ($this->cmd === 'LOGIN') {
                if (sizeof($this->args) !== 2) {
                    $this->result = ['$err' => 'You must pass exactly 2 arguments.'];
                    $this->wakeup();
                    return;
                }
                if (hash_equals($this->appInstance->config->username->value, $this->args[0]) + hash_equals($this->appInstance->config->password->value, $this->args[1]) < 2) {
                    $this->result = ['$err' => 'Wrong username and/or password.'];
                    return;
                }
                $this->attrs->session['logged'] = $this->appInstance->config->credver;
                $this->result = ['$ok' => 1];
                $this->wakeup();
                return;
            } elseif ($this->cmd === 'LOGOUT') {
                unset($this->attrs->session['logged']);
                $this->result = ['$ok' => 1];
                $this->wakeup();
                return;
            }
            if (!isset($this->attrs->session['logged']) || $this->attrs->session['logged'] < $this->appInstance->config->credver) {
                $this->result = ['$err' => 'You must be authenticated.'];
                $this->wakeup();
                return;
            }
        });
    }