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