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 */
18class 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) {
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}
global $bearsamppLang
const RUBY
const ERROR_FILE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const LOCAL_CFG_CONSOLE_EXE
__construct($id, $type)
const LOCAL_CFG_EXE
setVersion($version)
const ROOT_CFG_VERSION
reload($id=null, $type=null)
static logReloadClass($classInstance)
static logError($data, $file=null)
static logInitClass($classInstance)
static logInfo($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26