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