Request.php
1.8 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Lib\Imap\Request;
use Lib\Imap\Imap;
/**
 * 命令组装 请求 返回处理
 * @author:dc
 * @time 2024/9/18 10:12
 * Class Request
 * @package Lib\Imap\Request
 */
abstract class  Request {
    protected Imap $imap;
    /**
     * 命令执行结果
     * @var array
     */
    protected array $result = [];
    /**
     * 执行结果状态 YES OK NO BAD
     * @var string
     */
    protected string $status = '';
    /**
     * 这条命令执行的tag
     * @var string
     */
    protected string $tag = '';
    /**
     * 最后的消息
     * @var string
     */
    protected string $message = '';
    public function __construct(Imap $imap)
    {
        $this->imap = $imap;
    }
    /**
     * 执行命令
     * @param string $cmd 命令
     * @param mixed ...$params 命令参数
     * @author:dc
     * @time 2024/9/13 17:36
     */
    protected final function cmd(string $cmd,...$params){
        $this->result = $this->imap->client->request($params?sprintf($cmd,...$params):$cmd);
        // 删除最后一行的状态
        $end = array_pop($this->result);
        // 状态处理
        list($this->tag,$this->status,$this->message) = explode(' ',$end.'     ',3);
        $this->message = trim($this->message);
    }
    abstract public function exec():static ;
    /**
     * @return string
     */
    public function getMessage(): string
    {
        return $this->message;
    }
    /**
     * @return string
     */
    public function getStatus(): string
    {
        return $this->status;
    }
    /**
     * @return string
     */
    public function getTag(): string
    {
        return $this->tag;
    }
    /**
     * 是否成功
     * @return bool
     * @author:dc
     * @time 2024/9/14 9:10
     */
    public function isOk(){
        return $this->status == 'OK';
    }
}