Completed
Pull Request — develop (#459)
by ANTHONIUS
10:26
created

MailServiceOptions::getPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Options;
12
13
use Zend\Mail\Transport\FileOptions;
14
use Zend\Mail\Transport\SmtpOptions;
15
16
/**
17
 * ${CARET}
18
 * 
19
 * @author Carsten Bleek <[email protected]>
20
 */
21
class MailServiceOptions extends SmtpOptions
22
{
23
    /**
24
     * Local client hostname. used in the elho chalange
25
     *
26
     * @var string $name
27
     */
28
    protected $name = 'localhost';
29
30
    /**
31
     * Fully-qualified classname or short name resolvable via Zend\Mail\Protocol\SmtpLoader.
32
     * Typically, this will be one of “smtp”, “plain”, “login”, or “crammd5”, and defaults to “smtp”.
33
     *
34
     * @var string $connectionClass
35
     */
36
    protected $connectionClass = 'plain';
37
38
    /**
39
     * Mail transport. Possible Values "smtp", "sendmail","file".
40
     * If "sendmail" is used, YAWIK will use the php mail() function
41
     * for sending mails. This requires a local MTA.
42
     *
43
     * If "file" is used, YAWIK will use FileTransport class
44
     * to be able to test mail functionality
45
     *
46
     * https://docs.zendframework.com/zend-mail/transport/intro/#configuration-options
47
     *
48
     * @var string $transportClass
49
     */
50
    protected $transportClass = 'sendmail';
51
52
    /**
53
     * Connection configuration (passed to the underlying Protocol class)
54
     *
55
     * @var array
56
     */
57
    protected $connectionConfig = [];
58
59
    /**
60
     * Remote hostname or IP address; defaults to “127.0.0.1”.
61
     *
62
     * @var string $host
63
     */
64
    protected $host = '127.0.0.1';
65
66
    /**
67
     * @var int
68
     */
69
    protected $port = 25;
70
71
    /**
72
     * 'tls', 'ssl' or null
73
     *
74
     * @var string $ssl
75
     */
76
    protected $ssl;
77
78
    /**
79
     * @var string $username
80
     */
81
    protected $username;
82
83
    /**
84
     * @var string $password
85
     */
86
    protected $password;
87
88
    /**
89
     * @var string Path to stored mail files
90
     * @see FileOptions::setPath()
91
     */
92
    protected $path;
93
94
95
    public function setUsername($username) {
96
        if ($username) {
97
            $this->connectionConfig['username'] = $username;
98
        }
99
        return $this;
100
    }
101
102
    public function getUsername(){
103
        return $this->connectionConfig['username'];
104
    }
105
106
    public function setPassword($password) {
107
        if ($password) {
108
            $this->connectionConfig['password'] = $password;
109
        }
110
        return $this;
111
    }
112
113
    public function getPassword(){
114
        return $this->connectionConfig['password'];
115
    }
116
117
    public function setSsl($ssl) {
118
        if ($ssl) {
119
            $this->connectionConfig['ssl'] = $ssl;
120
        }
121
        return $this;
122
    }
123
124
    public function getSsl(){
125
        return $this->connectionConfig['ssl'];
126
    }
127
128
    public function setTransportClass($transportClass) {
129
        $this->transportClass = $transportClass;
130
        return $this;
131
    }
132
133
    public function getTransportClass(){
134
        return $this->transportClass;
135
    }
136
137
    /**
138
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
139
     */
140
    public function getPath()
141
    {
142
        if(is_null($this->path)){
143
            $this->setPath(sys_get_temp_dir().'/yawik/mails');
144
        }
145
        return $this->path;
146
    }
147
148
    /**
149
     * @param string $path
150
     * @return MailServiceOptions
151
     */
152
    public function setPath($path)
153
    {
154
        if(!is_dir($path)){
155
            mkdir($path,0777,true);
156
            chmod($path,0777);
157
        }
158
        $this->path = $path;
159
        return $this;
160
    }
161
}
162