2024.8.23
Loading...
Searching...
No Matches
class.tool.ruby.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 ToolRuby
12
*
13
* This class represents a Ruby tool module in the Bearsampp application.
14
* It extends the Module class and provides functionalities specific to managing
15
* Ruby tools, including loading configurations, setting versions, and retrieving
16
* executable paths.
17
*/
18
class
ToolRuby
extends
Module
19
{
20
/**
21
* Configuration key for the Ruby version in the root configuration.
22
*/
23
const
ROOT_CFG_VERSION
=
'rubyVersion'
;
24
25
/**
26
* Configuration key for the Ruby executable in the local configuration.
27
*/
28
const
LOCAL_CFG_EXE
=
'rubyExe'
;
29
30
/**
31
* Configuration key for the Ruby console executable in the local configuration.
32
*/
33
const
LOCAL_CFG_CONSOLE_EXE
=
'rubyConsoleExe'
;
34
35
/**
36
* @var string Path to the Ruby executable.
37
*/
38
private
$exe
;
39
40
/**
41
* @var string Path to the Ruby console executable.
42
*/
43
private
$consoleExe
;
44
45
/**
46
* Constructor for the ToolRuby class.
47
*
48
* @param string $id The ID of the module.
49
* @param string $type The type of the module.
50
*/
51
public
function
__construct
(
$id
,
$type
) {
52
Util::logInitClass
($this);
53
$this->
reload
(
$id
,
$type
);
54
}
55
56
/**
57
* Reloads the Ruby tool configuration based on the provided ID and type.
58
*
59
* @param string|null $id The ID of the module. If null, the current ID is used.
60
* @param string|null $type The type of the module. If null, the current type is used.
61
*/
62
public
function
reload
(
$id
=
null
,
$type
=
null
) {
63
global
$bearsamppConfig
,
$bearsamppLang
;
64
Util::logReloadClass
($this);
65
66
$this->name =
$bearsamppLang
->getValue(
Lang::RUBY
);
67
$this->version =
$bearsamppConfig
->getRaw(self::ROOT_CFG_VERSION);
68
parent::reload(
$id
,
$type
);
69
70
if
($this->bearsamppConfRaw !==
false
) {
71
$this->exe = $this->symlinkPath .
'/'
. $this->bearsamppConfRaw[
self::LOCAL_CFG_EXE
];
72
$this->consoleExe = $this->symlinkPath .
'/'
. $this->bearsamppConfRaw[
self::LOCAL_CFG_CONSOLE_EXE
];
73
}
74
75
if
(!$this->enable) {
76
Util::logInfo
($this->name .
' is not enabled!'
);
77
return
;
78
}
79
if
(!is_dir($this->currentPath)) {
80
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->currentPath));
81
}
82
if
(!is_dir($this->symlinkPath)) {
83
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->symlinkPath));
84
return
;
85
}
86
if
(!is_file($this->bearsamppConf)) {
87
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_CONF_NOT_FOUND
), $this->name .
' '
. $this->version, $this->bearsamppConf));
88
}
89
if
(!is_file($this->exe)) {
90
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_EXE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->exe));
91
}
92
if
(!is_file($this->consoleExe)) {
93
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_EXE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->consoleExe));
94
}
95
}
96
97
/**
98
* Sets the version of the Ruby tool and reloads the configuration.
99
*
100
* @param string $version The version to set.
101
*/
102
public
function
setVersion
(
$version
) {
103
global
$bearsamppConfig
;
104
$this->version =
$version
;
105
$bearsamppConfig
->replace(self::ROOT_CFG_VERSION,
$version
);
106
$this->
reload
();
107
}
108
109
/**
110
* Gets the path to the Ruby executable.
111
*
112
* @return string The path to the Ruby executable.
113
*/
114
public
function
getExe
() {
115
return
$this->exe
;
116
}
117
118
/**
119
* Gets the path to the Ruby console executable.
120
*
121
* @return string The path to the Ruby console executable.
122
*/
123
public
function
getConsoleExe
() {
124
return
$this->consoleExe
;
125
}
126
}
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
Lang\RUBY
const RUBY
Definition
class.lang.php:153
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
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
ToolRuby
Definition
class.tool.ruby.php:19
ToolRuby\LOCAL_CFG_CONSOLE_EXE
const LOCAL_CFG_CONSOLE_EXE
Definition
class.tool.ruby.php:33
ToolRuby\__construct
__construct($id, $type)
Definition
class.tool.ruby.php:51
ToolRuby\LOCAL_CFG_EXE
const LOCAL_CFG_EXE
Definition
class.tool.ruby.php:28
ToolRuby\setVersion
setVersion($version)
Definition
class.tool.ruby.php:102
ToolRuby\$consoleExe
$consoleExe
Definition
class.tool.ruby.php:43
ToolRuby\getConsoleExe
getConsoleExe()
Definition
class.tool.ruby.php:123
ToolRuby\getExe
getExe()
Definition
class.tool.ruby.php:114
ToolRuby\$exe
$exe
Definition
class.tool.ruby.php:38
ToolRuby\ROOT_CFG_VERSION
const ROOT_CFG_VERSION
Definition
class.tool.ruby.php:23
ToolRuby\reload
reload($id=null, $type=null)
Definition
class.tool.ruby.php:62
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.ruby.php
Generated by
1.11.0