2024.8.23
Loading...
Searching...
No Matches
class.tool.xdc.php
Go to the documentation of this file.
1
<?php
2
/*
3
* Copyright (c) 2021-2024 Bearsampp
4
* License: GNU General Public License version 3 or later; see LICENSE.txt
5
* Author: Bear
6
* Website: https://bearsampp.com
7
* Github: https://github.com/Bearsampp
8
*/
9
10
/**
11
* Class ToolXdc
12
*
13
* This class represents the XDC tool module in the Bearsampp application.
14
* It extends the abstract Module class and provides specific functionalities
15
* for managing the XDC tool, including loading configurations, setting versions,
16
* and retrieving the executable path.
17
*/
18
class
ToolXdc
extends
Module
19
{
20
/**
21
* Configuration key for the XDC version in the root configuration.
22
*/
23
const
ROOT_CFG_VERSION
=
'xdcVersion'
;
24
25
/**
26
* Configuration key for the XDC executable in the local configuration.
27
*/
28
const
LOCAL_CFG_EXE
=
'xdcExe'
;
29
30
/**
31
* Path to the XDC executable.
32
*
33
* @var string
34
*/
35
private
$exe
;
36
37
/**
38
* Constructor for the ToolXdc class.
39
*
40
* Initializes the ToolXdc instance by logging the initialization and reloading
41
* the module configuration with the provided ID and type.
42
*
43
* @param string $id The ID of the module.
44
* @param string $type The type of the module.
45
*/
46
public
function
__construct
(
$id
,
$type
) {
47
Util::logInitClass
($this);
48
$this->
reload
(
$id
,
$type
);
49
}
50
51
/**
52
* Reloads the module configuration based on the provided ID and type.
53
*
54
* This method overrides the parent reload method to include additional
55
* configurations specific to the XDC tool. It sets the name, version, and
56
* executable path, and logs errors if the module is not properly configured.
57
*
58
* @param string|null $id The ID of the module. If null, the current ID is used.
59
* @param string|null $type The type of the module. If null, the current type is used.
60
*/
61
public
function
reload
(
$id
=
null
,
$type
=
null
) {
62
global
$bearsamppConfig
,
$bearsamppLang
;
63
Util::logReloadClass
($this);
64
65
$this->name =
$bearsamppLang
->getValue(
Lang::XDC
);
66
$this->version =
$bearsamppConfig
->getRaw(self::ROOT_CFG_VERSION);
67
parent::reload(
$id
,
$type
);
68
69
if
($this->bearsamppConfRaw !==
false
) {
70
$this->exe = $this->symlinkPath .
'/'
. $this->bearsamppConfRaw[
self::LOCAL_CFG_EXE
];
71
}
72
73
if
(!$this->enable) {
74
Util::logInfo
($this->name .
' is not enabled!'
);
75
return
;
76
}
77
if
(!is_dir($this->currentPath)) {
78
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->currentPath));
79
}
80
if
(!is_dir($this->symlinkPath)) {
81
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->symlinkPath));
82
return
;
83
}
84
if
(!is_file($this->bearsamppConf)) {
85
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_CONF_NOT_FOUND
), $this->name .
' '
. $this->version, $this->bearsamppConf));
86
}
87
if
(!is_file($this->exe)) {
88
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_EXE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->exe));
89
}
90
}
91
92
/**
93
* Sets the version of the XDC tool.
94
*
95
* This method updates the version in the configuration and reloads the module
96
* to apply the new version.
97
*
98
* @param string $version The version to set.
99
*/
100
public
function
setVersion
(
$version
) {
101
global
$bearsamppConfig
;
102
$this->version =
$version
;
103
$bearsamppConfig
->replace(self::ROOT_CFG_VERSION,
$version
);
104
$this->
reload
();
105
}
106
107
/**
108
* Gets the path to the XDC executable.
109
*
110
* @return string The path to the XDC executable.
111
*/
112
public
function
getExe
() {
113
return
$this->exe
;
114
}
115
}
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
Lang\ERROR_FILE_NOT_FOUND
const ERROR_FILE_NOT_FOUND
Definition
class.lang.php:160
Lang\ERROR_CONF_NOT_FOUND
const ERROR_CONF_NOT_FOUND
Definition
class.lang.php:158
Lang\ERROR_EXE_NOT_FOUND
const ERROR_EXE_NOT_FOUND
Definition
class.lang.php:159
Lang\XDC
const XDC
Definition
class.lang.php:154
Module
Definition
class.module.php:15
Module\$type
$type
Definition
class.module.php:18
Module\$version
$version
Definition
class.module.php:22
Module\$id
$id
Definition
class.module.php:19
ToolXdc
Definition
class.tool.xdc.php:19
ToolXdc\setVersion
setVersion($version)
Definition
class.tool.xdc.php:100
ToolXdc\reload
reload($id=null, $type=null)
Definition
class.tool.xdc.php:61
ToolXdc\ROOT_CFG_VERSION
const ROOT_CFG_VERSION
Definition
class.tool.xdc.php:23
ToolXdc\getExe
getExe()
Definition
class.tool.xdc.php:112
ToolXdc\$exe
$exe
Definition
class.tool.xdc.php:35
ToolXdc\__construct
__construct($id, $type)
Definition
class.tool.xdc.php:46
ToolXdc\LOCAL_CFG_EXE
const LOCAL_CFG_EXE
Definition
class.tool.xdc.php:28
Util\logReloadClass
static logReloadClass($classInstance)
Definition
class.util.php:822
Util\logError
static logError($data, $file=null)
Definition
class.util.php:802
Util\logInitClass
static logInitClass($classInstance)
Definition
class.util.php:812
Util\logInfo
static logInfo($data, $file=null)
Definition
class.util.php:778
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:26
Bearsampp-development
sandbox
core
classes
tools
class.tool.xdc.php
Generated by
1.11.0