1 | <?php |
||
11 | abstract class AbstractTransport implements TransportInterface |
||
12 | { |
||
13 | /** |
||
14 | * File where transport will download to. The file name is generated if this is used. |
||
15 | * |
||
16 | * @var string |
||
17 | * |
||
18 | * @private There's some logic here that requires only this class has access to it. |
||
19 | */ |
||
20 | private $destination; |
||
21 | |||
22 | /** |
||
23 | * Directory where transport will download to. The file name is generated if this is used. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $destinationDir; |
||
28 | |||
29 | /** |
||
30 | * The number of seconds that the transport may be cached. |
||
31 | * |
||
32 | * @var int |
||
33 | */ |
||
34 | protected $maxAge; |
||
35 | |||
36 | /** |
||
37 | * @var Connection |
||
38 | */ |
||
39 | protected $connection; |
||
40 | |||
41 | /** |
||
42 | * @var EventDispatcherInterface |
||
43 | */ |
||
44 | protected $eventDispatcher; |
||
45 | |||
46 | /** |
||
47 | * @param Connection $conn |
||
48 | * @param string|null $destination |
||
49 | * @param EventDispatcherInterface $dispatcher |
||
50 | */ |
||
51 | 132 | public function __construct(Connection $conn, $destination = null, EventDispatcherInterface $dispatcher = null) |
|
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | public function __clone() |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | public function __toString() |
||
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | */ |
||
79 | 18 | public function setConnection(Connection $connection) |
|
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | 8 | public function getConnection() |
|
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | 6 | public function setEventDispatcher(EventDispatcherInterface $dispatcher) |
|
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | 4 | public function getEventDispatcher() |
|
107 | |||
108 | /** |
||
109 | * @param int $seconds |
||
110 | */ |
||
111 | 4 | public function setMaxAge($seconds) |
|
115 | |||
116 | /** |
||
117 | * @return int |
||
118 | */ |
||
119 | 4 | public function getMaxAge() |
|
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | 12 | public function setDestination($destination) |
|
139 | |||
140 | /** |
||
141 | * @inheritdoc |
||
142 | */ |
||
143 | 60 | public function getDestination() |
|
151 | |||
152 | /** |
||
153 | * @inheritdoc |
||
154 | */ |
||
155 | 20 | public function setDestinationDir($destinationDir) |
|
167 | |||
168 | /** |
||
169 | * @inheritdoc |
||
170 | */ |
||
171 | 70 | public function getDestinationDir() |
|
175 | |||
176 | /** |
||
177 | * @return string |
||
178 | */ |
||
179 | 16 | public function getDefaultDestination() |
|
183 | |||
184 | /** |
||
185 | * @inheritdoc |
||
186 | */ |
||
187 | 56 | public function getFile() |
|
194 | |||
195 | /** |
||
196 | * @param \DateTime $maxAge |
||
197 | * |
||
198 | * @throws TransportException |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | 56 | final public function fetch(\DateTime $maxAge = null) |
|
236 | |||
237 | /** |
||
238 | * @return string |
||
239 | */ |
||
240 | 26 | final public static function getDefaultUserAgent() |
|
244 | |||
245 | /** |
||
246 | * Purges a previously transported file, removing the destination and |
||
247 | * whatever cache the transport uses internally. |
||
248 | */ |
||
249 | 4 | public function purge() |
|
257 | |||
258 | /** |
||
259 | * @param string $destination |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | 22 | protected function getTempDestination($destination) |
|
267 | |||
268 | /** |
||
269 | * @param string $destination |
||
270 | * @param \DateTime $maxAge |
||
271 | * |
||
272 | * @return bool |
||
273 | */ |
||
274 | 42 | protected function isFresh($destination, \DateTime $maxAge = null) |
|
302 | |||
303 | /** |
||
304 | * Fetches the resource, makes sure a file is present at the given destination. |
||
305 | * |
||
306 | * @param string $destination |
||
307 | */ |
||
308 | abstract protected function doFetch($destination); |
||
309 | } |
||
310 |