summaryrefslogtreecommitdiff
path: root/src/RequestMessage.php
blob: a2e196d2ab38eaacd485c53e2c5b22b2b8d140c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

namespace jobd;

class RequestMessage extends Message {

    protected $requestNo;
    protected $requestType;
    protected $requestData;
    protected $password;

    /**
     * Request constructor.
     * @param string $request_type
     * @param null|array $request_data
     */
    public function __construct(string $request_type, $request_data = null)
    {
        parent::__construct(Message::REQUEST);

        $this->requestData = $request_data;
        $this->requestType = $request_type;
    }

    /**
     * @param string $password
     */
    public function setPassword(string $password)
    {
        $this->password = $password;
    }

    /**
     * @param int $no
     */
    public function setRequestNo(int $no)
    {
        $this->requestNo = $no;
    }

    /**
     * @return string[]
     */
    protected function getContent(): array
    {
        $request = [
            'type' => $this->requestType,
            'no' => $this->requestNo,
        ];

        if (!is_null($this->requestData))
            $request['data'] = (object)$this->requestData;

        if (!is_null($this->password))
            $request['password'] = $this->password;

        return $request;
    }

}