2024.8.23
Loading...
Searching...
No Matches
class.tool.yarn.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 ToolYarn
12 *
13 * This class represents the Yarn tool module in the Bearsampp application.
14 * It extends the abstract Module class and provides specific functionalities
15 * for managing the Yarn tool, including version management and executable path handling.
16 */
17class ToolYarn extends Module
18{
19 /**
20 * Configuration key for the Yarn version in the root configuration.
21 */
22 const ROOT_CFG_VERSION = 'yarnVersion';
23
24 /**
25 * Configuration key for the Yarn executable in the local configuration.
26 */
27 const LOCAL_CFG_EXE = 'yarnExe';
28
29 /**
30 * Path to the Yarn executable.
31 *
32 * @var string
33 */
34 private $exe;
35
36 /**
37 * Constructor for the ToolYarn class.
38 *
39 * @param string $id The ID of the module.
40 * @param string $type The type of the module.
41 */
42 public function __construct($id, $type) {
43 Util::logInitClass($this);
44 $this->reload($id, $type);
45 }
46
47 /**
48 * Reloads the Yarn module configuration based on the provided ID and type.
49 *
50 * @param string|null $id The ID of the module. If null, the current ID is used.
51 * @param string|null $type The type of the module. If null, the current type is used.
52 */
53 public function reload($id = null, $type = null) {
56
57 $this->name = $bearsamppLang->getValue(Lang::YARN);
58 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
59 parent::reload($id, $type);
60
61 if ($this->bearsamppConfRaw !== false) {
62 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
63 }
64
65 if (!$this->enable) {
66 Util::logInfo($this->name . ' is not enabled!');
67 return;
68 }
69 if (!is_dir($this->currentPath)) {
70 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
71 }
72 if (!is_dir($this->symlinkPath)) {
73 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
74 return;
75 }
76 if (!is_file($this->bearsamppConf)) {
77 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
78 }
79 if (!is_file($this->exe)) {
80 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
81 }
82 }
83
84 /**
85 * Sets the version of the Yarn module and updates the configuration.
86 *
87 * @param string $version The version to set.
88 */
89 public function setVersion($version) {
90 global $bearsamppConfig;
91 $this->version = $version;
92 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
93 $this->reload();
94 }
95
96 /**
97 * Gets the path to the Yarn executable.
98 *
99 * @return string The path to the Yarn executable.
100 */
101 public function getExe() {
102 return $this->exe;
103 }
104}
global $bearsamppLang
const ERROR_FILE_NOT_FOUND
const YARN
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const ROOT_CFG_VERSION
setVersion($version)
const LOCAL_CFG_EXE
__construct($id, $type)
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