|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright Mediact. All rights reserved. |
|
4
|
|
|
* https://www.Mediact.nl |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Mediact\FileMapping; |
|
8
|
|
|
|
|
9
|
|
|
class UnixFileMapping implements FileMappingInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var string */ |
|
12
|
|
|
private $sourceDirectory; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
private $destinationDirectory; |
|
16
|
|
|
|
|
17
|
|
|
/** @var string */ |
|
18
|
|
|
private $source; |
|
19
|
|
|
|
|
20
|
|
|
/** @var string */ |
|
21
|
|
|
private $destination; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $sourceDirectory |
|
27
|
|
|
* @param string $destinationDirectory |
|
28
|
|
|
* @param string $mapping |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( |
|
31
|
|
|
string $sourceDirectory, |
|
32
|
|
|
string $destinationDirectory, |
|
33
|
|
|
string $mapping |
|
34
|
|
|
) { |
|
35
|
|
|
$this->sourceDirectory = $sourceDirectory; |
|
36
|
|
|
$this->destinationDirectory = $destinationDirectory; |
|
37
|
|
|
|
|
38
|
|
|
// Expand the source and destination. |
|
39
|
|
|
static $pattern = '/({(.*),(.*)})/'; |
|
40
|
|
|
$this->source = preg_replace($pattern, '$2', $mapping); |
|
41
|
|
|
$this->destination = preg_replace($pattern, '$3', $mapping); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the relative path to the source file. |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getRelativeSource(): string |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->source; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get the absolute path to the source file. |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getSource(): string |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->sourceDirectory |
|
62
|
|
|
. DIRECTORY_SEPARATOR |
|
63
|
|
|
. $this->source; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Get the relative path to the destination file. |
|
68
|
|
|
* |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getRelativeDestination(): string |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->destination; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get the absolute path to the destination file. |
|
78
|
|
|
* |
|
79
|
|
|
* @return string |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getDestination(): string |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->destinationDirectory |
|
84
|
|
|
. DIRECTORY_SEPARATOR |
|
85
|
|
|
. $this->destination; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|