Completed
Push — master ( baf6b1...a46b20 )
by WEBEWEB
01:16
created

AbstractFtpClient::newFtpException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the core-library package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Library\Core\Network\FTP\Client;
13
14
use WBW\Library\Core\Network\FTP\Exception\FtpException;
15
use WBW\Library\Core\Security\Authenticator;
16
17
/**
18
 * Abstract FTP client.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Library\Core\Network\FTP\Client
22
 * @abstract
23
 */
24
abstract class AbstractFtpClient {
25
26
    /**
27
     * Authenticator.
28
     *
29
     * @var Authenticator
30
     */
31
    private $authenticator;
32
33
    /**
34
     * Connection.
35
     *
36
     * @var ressource
37
     */
38
    private $connection;
39
40
    /**
41
     * Constructor.
42
     *
43
     * @param Authenticator $authenticator The authenticator.
44
     */
45
    protected function __construct(Authenticator $authenticator) {
46
        $this->setAuthenticator($authenticator);
47
    }
48
49
    /**
50
     * Get the authenticator.
51
     *
52
     * @return Authenticator Returns the authenticator.
53
     */
54
    public function getAuthenticator() {
55
        return $this->authenticator;
56
    }
57
58
    /**
59
     * Get the connection.
60
     *
61
     * @return mixed Returns the connection.
62
     */
63
    public function getConnection() {
64
        return $this->connection;
65
    }
66
67
    /**
68
     * Construct a new FTP exception.
69
     *
70
     * @param string $message The message.
71
     * @return FtpException Returns a new FTP exception.
72
     */
73
    protected function newFtpException($message) {
74
75
        $format = "%s://%s:%s@%s:%d ${message}";
76
        $args   = [
77
            $this->getAuthenticator()->getScheme(),
78
            $this->getAuthenticator()->getPasswordAuthentication()->getUsername(),
79
            $this->getAuthenticator()->getPasswordAuthentication()->getPassword(),
80
            $this->getAuthenticator()->getHostname(),
81
            $this->getAuthenticator()->getPort(),
82
        ];
83
84
        return new FtpException(vsprintf($format, $args));
85
    }
86
87
    /**
88
     * Set the authenticator.
89
     *
90
     * @param Authenticator $authenticator The authenticator.
91
     * @return AbstractFtpClient Returns this FTP client.
92
     */
93
    protected function setAuthenticator(Authenticator $authenticator) {
94
        $this->authenticator = $authenticator;
95
        return $this;
96
    }
97
98
    /**
99
     * Set the connection.
100
     *
101
     * @param mixed $connection The connection.
102
     * @return AbstractFtpClient Returns this FTP client.
103
     */
104
    protected function setConnection($connection) {
105
        $this->connection = $connection;
106
        return $this;
107
    }
108
}
109