|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The class containing the configuration options for RCS. |
|
4
|
|
|
* |
|
5
|
|
|
* @author tarjei huse |
|
6
|
|
|
* @package midcom.services.rcs |
|
7
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
8
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* The config class is used to generate the RCS configuration. |
|
13
|
|
|
* |
|
14
|
|
|
* @see midcom_services_rcs for an overview of the options |
|
15
|
|
|
* @package midcom.services.rcs |
|
16
|
|
|
*/ |
|
17
|
|
|
class midcom_services_rcs_config |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* The array of configuration options |
|
21
|
|
|
* |
|
22
|
|
|
* @var midcom_config |
|
23
|
|
|
*/ |
|
24
|
|
|
private $config; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Constructor |
|
28
|
|
|
*/ |
|
29
|
8 |
|
public function __construct(midcom_config $config) |
|
30
|
|
|
{ |
|
31
|
8 |
|
$this->config = $config; |
|
32
|
8 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Returns the root of the directory containing the RCS files. |
|
36
|
|
|
*/ |
|
37
|
83 |
|
public function get_rcs_root() : string |
|
38
|
|
|
{ |
|
39
|
83 |
|
if (empty($this->config['midcom_services_rcs_root'])) { |
|
40
|
|
|
$basedir = dirname(midgard_connection::get_instance()->config->sharedir); |
|
41
|
|
|
$this->config['midcom_services_rcs_root'] = $basedir . '/rcs'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
83 |
|
return $this->config['midcom_services_rcs_root']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* If the RCS service is enabled |
|
49
|
|
|
* (set by midcom_services_rcs_enable) |
|
50
|
|
|
* |
|
51
|
|
|
* @return boolean true if it is enabled |
|
52
|
|
|
*/ |
|
53
|
83 |
|
public function use_rcs() : bool |
|
54
|
|
|
{ |
|
55
|
83 |
|
return !empty($this->config['midcom_services_rcs_enable']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Returns the prefix for the rcs utilities. |
|
60
|
|
|
*/ |
|
61
|
84 |
|
public function get_bin_prefix() : ?string |
|
62
|
|
|
{ |
|
63
|
84 |
|
if (!isset($this->config['midcom_services_rcs_bin_dir'])) { |
|
64
|
|
|
return null; |
|
65
|
|
|
} |
|
66
|
84 |
|
return $this->config['midcom_services_rcs_bin_dir'] . '/'; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Returns the backend classname. |
|
71
|
|
|
*/ |
|
72
|
82 |
|
public function get_backend_class() : string |
|
73
|
|
|
{ |
|
74
|
82 |
|
if ($this->use_rcs()) { |
|
75
|
82 |
|
$this->test_rcs_config(); |
|
76
|
82 |
|
return midcom_services_rcs_backend_rcs::class; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
return midcom_services_rcs_backend_null::class; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Checks if the basic rcs service is usable. |
|
84
|
|
|
*/ |
|
85
|
83 |
|
public function test_rcs_config() |
|
86
|
|
|
{ |
|
87
|
83 |
|
if (!is_writable($this->get_rcs_root())) { |
|
88
|
|
|
throw new midcom_error("The root RCS directory {$this->config['midcom_services_rcs_root']} is not writable!"); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
83 |
|
if ($this->get_bin_prefix() === null) { |
|
92
|
|
|
throw new midcom_error("midcom_services_rcs_bin_dir not found in configuration. This must be defined before RCS will work."); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
83 |
|
if (!is_executable($this->config['midcom_services_rcs_bin_dir'] . "/ci")) { |
|
96
|
|
|
throw new midcom_error("Cannot execute {$this->config['midcom_services_rcs_bin_dir']}/ci."); |
|
97
|
|
|
} |
|
98
|
83 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|