1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Conveyor package. |
5
|
|
|
* |
6
|
|
|
* (c) Jeroen Fiege <[email protected]> |
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 Webcreate\Conveyor\Transporter; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
15
|
|
|
use Webcreate\Conveyor\Event\TransporterEvent; |
16
|
|
|
use Webcreate\Conveyor\Event\TransporterEvents; |
17
|
|
|
use Webcreate\Conveyor\Transporter\AbstractTransporter; |
18
|
|
|
|
19
|
|
|
class ReadOnlyTransporter extends AbstractTransporter implements SshCapableTransporterInterface, TransactionalTransporterInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var AbstractTransporter |
23
|
|
|
*/ |
24
|
|
|
protected $innerTransporter; |
25
|
|
|
|
26
|
|
|
public function __construct(EventDispatcherInterface $dispatcher, AbstractTransporter $innerTransporter = null) |
27
|
|
|
{ |
28
|
|
|
parent::__construct($dispatcher); |
29
|
|
|
|
30
|
|
|
if (null !== $innerTransporter) { |
31
|
|
|
$this->setInnerTransporter($innerTransporter); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function getHost() |
36
|
|
|
{ |
37
|
|
|
return $this->innerTransporter->getHost(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function getPath() |
41
|
|
|
{ |
42
|
|
|
return $this->innerTransporter->getPath(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function getUser() |
46
|
|
|
{ |
47
|
|
|
return $this->innerTransporter->getUser(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getPass() |
51
|
|
|
{ |
52
|
|
|
return $this->innerTransporter->getPass(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setInnerTransporter(AbstractTransporter $transporter) |
56
|
|
|
{ |
57
|
|
|
$this->innerTransporter = $transporter; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Checks if a file or directory exists on the remote server |
62
|
|
|
* |
63
|
|
|
* @param string $path remote source path |
64
|
|
|
* @return bool true when the resource exists, false otherwise |
65
|
|
|
*/ |
66
|
|
|
public function exists($path) |
67
|
|
|
{ |
68
|
|
|
return $this->innerTransporter->exists($path); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Create a directory on the remote server |
73
|
|
|
* |
74
|
|
|
* @param string $dest remote path |
75
|
|
|
*/ |
76
|
|
|
public function mkdir($dest) |
77
|
|
|
{ |
78
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_MKDIR, new TransporterEvent($this, $dest)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Retrieve file or directory from remote server |
83
|
|
|
* |
84
|
|
|
* @param string $src remote source path |
85
|
|
|
* @param string $dest (optional) local destination path |
86
|
|
|
*/ |
87
|
|
|
public function get($src, $dest = null) |
88
|
|
|
{ |
89
|
|
|
return $this->innerTransporter->get($src, $dest); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Upload a file or directory to remote server |
94
|
|
|
* |
95
|
|
|
* @param string $src local source path |
96
|
|
|
* @param string $dest remote destination path |
97
|
|
|
*/ |
98
|
|
|
public function put($src, $dest) |
99
|
|
|
{ |
100
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_PUT, new TransporterEvent($this, array('dest' => $dest, 'src' => $src))); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function putContent($content, $dest) |
104
|
|
|
{ |
105
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_PUT_CONTENT, new TransporterEvent($this, array('dest' => $dest, 'content' => $content))); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function symlink($src, $dest) |
109
|
|
|
{ |
110
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_SYMLINK, new TransporterEvent($this, array('dest' => $dest, 'src' => $src))); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Checks for symlink on the remote server |
115
|
|
|
* |
116
|
|
|
* @param $dest |
117
|
|
|
* @return bool |
118
|
|
|
*/ |
119
|
|
|
public function isSymlink($dest) |
120
|
|
|
{ |
121
|
|
|
return $this->innerTransporter->isSymlink($dest); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Copies a file/directory on the remote host |
126
|
|
|
* |
127
|
|
|
* @param string $src |
128
|
|
|
* @param string $dest |
129
|
|
|
* @param bool $recursive |
130
|
|
|
* @return mixed |
131
|
|
|
*/ |
132
|
|
|
public function copy($src, $dest, $recursive = true) |
133
|
|
|
{ |
134
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_COPY, new TransporterEvent($this, array('dest' => $dest, 'src' => $src))); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Removes a file/directory on the remote host |
139
|
|
|
* |
140
|
|
|
* @param string $path |
141
|
|
|
* @param bool $recursive |
142
|
|
|
* @return mixed |
143
|
|
|
*/ |
144
|
|
|
public function remove($path, $recursive = true) |
145
|
|
|
{ |
146
|
|
|
$this->dispatcher->dispatch(TransporterEvents::TRANSPORTER_REMOVE, new TransporterEvent($this, array('path' => $path))); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function exec($command, $callback = null) |
150
|
|
|
{ |
151
|
|
|
// nothing here |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function begin() |
155
|
|
|
{ |
156
|
|
|
// nothing here |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function commit() |
160
|
|
|
{ |
161
|
|
|
// nothing here |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function ls($path) |
|
|
|
|
165
|
|
|
{ |
166
|
|
|
return $this->innerTransporter->ls($path); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
Even though PHP does not care about the name of your methods, it is generally a good practice to choose method names which can be easily understood by other human readers.