|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Amplexor\XConnect library |
|
4
|
|
|
* |
|
5
|
|
|
* @license http://opensource.org/licenses/MIT |
|
6
|
|
|
* @link https://github.com/amplexor-drupal/xconnect/ |
|
7
|
|
|
* @version 1.0.0 |
|
8
|
|
|
* @package Amplexor.XConnect |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Amplexor\XConnect\Service; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* X-Connect service class to send a request as a file. |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class ServiceAbstract implements ServiceInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Remote directory configuration. |
|
23
|
|
|
* |
|
24
|
|
|
* @var array |
|
25
|
|
|
*/ |
|
26
|
|
|
private $directoryConfig = array( |
|
27
|
|
|
'send' => 'To_LSP', |
|
28
|
|
|
'send_processed' => 'To_LSP_processed', |
|
29
|
|
|
'receive' => 'From_LSP', |
|
30
|
|
|
'receive_processed' => 'From_LSP_processed', |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Constructor. |
|
35
|
|
|
* |
|
36
|
|
|
* This will extract the remote directory configuration from the config |
|
37
|
|
|
* array: |
|
38
|
|
|
* - directory_send : The remote directory to store the request file in. |
|
39
|
|
|
* - directory_send_processed : The remote directory where the processed |
|
40
|
|
|
* request files are stored. |
|
41
|
|
|
* - directory_receive : The remote directory where the translated files are |
|
42
|
|
|
* stored to be picked up. |
|
43
|
|
|
* - directory_receive_processed : The repome directory where to put the |
|
44
|
|
|
* translation files that are successfully processed by the local system. |
|
45
|
|
|
* |
|
46
|
|
|
* @param array $config |
|
47
|
|
|
* The remote directory config. |
|
48
|
|
|
*/ |
|
49
|
81 |
|
public function __construct(array $config = array()) |
|
50
|
|
|
{ |
|
51
|
81 |
|
$this->setDirectoryConfig($config); |
|
52
|
81 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Set the config based on the given config array. |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $config |
|
58
|
|
|
* The configuration array. |
|
59
|
|
|
*/ |
|
60
|
81 |
|
protected function setDirectoryConfig(array $config) |
|
61
|
|
|
{ |
|
62
|
81 |
|
$configKeys = array_keys($this->directoryConfig); |
|
63
|
|
|
|
|
64
|
81 |
|
foreach ($configKeys as $key) { |
|
65
|
81 |
|
$configKey = 'directory_' . $key; |
|
66
|
81 |
|
if (array_key_exists($configKey, $config)) { |
|
67
|
27 |
|
$this->directoryConfig[$key] = $config[$configKey]; |
|
68
|
27 |
|
} |
|
69
|
81 |
|
} |
|
70
|
81 |
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the remote directory name to where to store the request files. |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
* The remote directory to store the request file in. |
|
77
|
|
|
*/ |
|
78
|
24 |
|
protected function getDirectorySend() |
|
79
|
|
|
{ |
|
80
|
24 |
|
return $this->directoryConfig['send']; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Get the remote directory where the translated response files are located. |
|
85
|
|
|
* |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
48 |
|
protected function getDirectoryReceive() |
|
89
|
|
|
{ |
|
90
|
48 |
|
return $this->directoryConfig['receive']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the remote directory where a processed response should be moved to. |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
18 |
|
protected function getDirectoryReceiveProcessed() |
|
99
|
|
|
{ |
|
100
|
18 |
|
return $this->directoryConfig['receive_processed']; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|