Bearsampp 2025.8.29
Loading...
Searching...
No Matches
ToolGit Class Reference
Inheritance diagram for ToolGit:

Public Member Functions

 __construct ($id, $type)
 findRepos ($cache=true)
 getBash ()
 getExe ()
 getRepos ()
 isScanStartup ()
 reload ($id=null, $type=null)
 setScanStartup ($scanStartup)
 setVersion ($version)
Public Member Functions inherited from Module
 __toString ()
 getCurrentPath ()
 getId ()
 getName ()
 getRelease ()
 getRootPath ()
 getSymlinkPath ()
 getType ()
 getVersion ()
 getVersionList ()
 isEnable ()
 update ($sub=0, $showWindow=false)

Data Fields

const LOCAL_CFG_BASH = 'gitBash'
const LOCAL_CFG_EXE = 'gitExe'
const LOCAL_CFG_SCAN_STARTUP = 'gitScanStartup'
const REPOS_CACHE_FILE = 'reposCache.dat'
const REPOS_FILE = 'repos.dat'
const ROOT_CFG_VERSION = 'gitVersion'
Data Fields inherited from Module
const BUNDLE_RELEASE = 'bundleRelease'

Protected Member Functions

 updateConfig ($version=null, $sub=0, $showWindow=false)
Protected Member Functions inherited from Module
 __construct ()
 replace ($key, $value)
 replaceAll ($params)

Private Attributes

 $bash
 $exe
 $repos
 $reposCacheFile
 $reposFile
 $scanStartup

Additional Inherited Members

Protected Attributes inherited from Module
 $bearsamppConf
 $bearsamppConfRaw
 $currentPath
 $enable
 $name
 $release = 'N/A'
 $rootPath
 $symlinkPath
 $version

Detailed Description

Class ToolGit

This class represents the Git tool module in the Bearsampp application. It handles the configuration, initialization, and management of Git-related settings and repositories.

Definition at line 16 of file class.tool.git.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $id,
$type )

Constructs a ToolGit object and initializes the Git tool module.

Parameters
string$idThe ID of the module.
string$typeThe type of the module.

Definition at line 41 of file class.tool.git.php.

41 {
42 Util::logInitClass($this);
43 $this->reload($id, $type);
44 }
reload($id=null, $type=null)
static logInitClass($classInstance)

References Module\$id, Module\$type, Util\logInitClass(), and reload().

Member Function Documentation

◆ findRepos()

findRepos ( $cache = true)

Finds Git repositories either from cache or by scanning the directories.

Parameters
bool$cacheWhether to use the cached repositories list.
Returns
array The list of found repositories.

Definition at line 145 of file class.tool.git.php.

145 {
146 $result = array();
147
148 if ($cache) {
149 if (file_exists($this->reposCacheFile)) {
150 $repos = file($this->reposCacheFile);
151 foreach ($repos as $repo) {
152 array_push($result, trim($repo));
153 }
154 }
155 } else {
156 if (!empty($this->repos)) {
157 foreach ($this->repos as $repo) {
158 $foundRepos = Util::findRepos($repo, $repo,'.git/config');
159 if (!empty($foundRepos)) {
160 foreach ($foundRepos as $foundRepo) {
161 array_push($result, $foundRepo);
162 }
163 }
164 }
165 }
166 $strResult = implode(PHP_EOL, $result);
167 file_put_contents($this->reposCacheFile, $strResult);
168 }
169
170 return $result;
171 }
$result
static findRepos($initPath, $startPath, $checkFile, $maxDepth=1)

References $repos, $result, and Util\findRepos().

◆ getBash()

getBash ( )

Retrieves the path to the Git Bash executable.

Returns
string The path to the Git Bash executable.

Definition at line 208 of file class.tool.git.php.

208 {
209 return $this->bash;
210 }

References $bash.

Referenced by updateConfig().

◆ getExe()

getExe ( )

Retrieves the path to the Git executable.

Returns
string The path to the Git executable.

Definition at line 199 of file class.tool.git.php.

199 {
200 return $this->exe;
201 }

References $exe.

Referenced by updateConfig().

◆ getRepos()

getRepos ( )

Retrieves the list of repositories.

Returns
array The list of repositories.

Definition at line 190 of file class.tool.git.php.

190 {
191 return $this->repos;
192 }

References $repos.

◆ isScanStartup()

isScanStartup ( )

Checks if the Git tool module is set to scan repositories at startup.

Returns
bool True if set to scan at startup, false otherwise.

Definition at line 217 of file class.tool.git.php.

217 {
218 return $this->scanStartup == Config::ENABLED;
219 }
const ENABLED

References Config\ENABLED.

◆ reload()

reload ( $id = null,
$type = null )

Reloads the Git tool module configuration based on the provided ID and type.

Parameters
string | null$idThe ID of the module. If null, the current ID is used.
string | null$typeThe type of the module. If null, the current type is used.

Reimplemented from Module.

Definition at line 52 of file class.tool.git.php.

52 {
55
56 $this->name = $bearsamppLang->getValue(Lang::GIT);
57 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
58 parent::reload($id, $type);
59
60 $this->reposFile = $this->symlinkPath . '/' . self::REPOS_FILE;
61 $this->reposCacheFile = $this->symlinkPath . '/' . self::REPOS_CACHE_FILE;
62
63 if ($this->bearsamppConfRaw !== false) {
64 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
65 $this->bash = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_BASH];
66 $this->scanStartup = $this->bearsamppConfRaw[self::LOCAL_CFG_SCAN_STARTUP];
67 }
68
69 if (!$this->enable) {
70 Util::logInfo($this->name . ' is not enabled!');
71 return;
72 }
73 if (!is_dir($this->currentPath)) {
74 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
75 }
76 if (!is_dir($this->symlinkPath)) {
77 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
78 return;
79 }
80 if (!is_file($this->bearsamppConf)) {
81 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
82 }
83 if (!is_file($this->reposFile)) {
84 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->reposFile));
85 }
86 if (!is_file($this->exe)) {
87 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
88 }
89 if (!is_file($this->bash)) {
90 Util::logError(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->bash));
91 }
92
93 if (is_file($this->reposFile)) {
94 $this->repos = explode(PHP_EOL, file_get_contents($this->reposFile));
95 $rebuildRepos = array();
96 foreach ($this->repos as $repo) {
97 $repo = trim($repo);
98 if (stripos($repo, ':') === false) {
99 $repo = $bearsamppRoot->getRootPath() . '/' . $repo;
100 }
101 if (is_dir($repo)) {
102 $rebuildRepos[] = Util::formatUnixPath($repo);
103 } else {
104 Util::logWarning($this->name . ' repository not found: ' . $repo);
105 }
106 }
107 $this->repos = $rebuildRepos;
108 }
109 }
global $bearsamppLang
global $bearsamppRoot
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const GIT
const ERROR_FILE_NOT_FOUND
static logError($data, $file=null)
static logInfo($data, $file=null)
static logReloadClass($classInstance)
static formatUnixPath($path)
static logWarning($data, $file=null)
global $bearsamppConfig
Definition homepage.php:27

References $bearsamppConfig, $bearsamppLang, $bearsamppRoot, Module\$id, Module\$type, Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Util\formatUnixPath(), Lang\GIT, Util\logError(), Util\logInfo(), Util\logReloadClass(), and Util\logWarning().

Referenced by __construct(), and setVersion().

◆ setScanStartup()

setScanStartup ( $scanStartup)

Sets whether the Git tool module should scan repositories at startup.

Parameters
bool$scanStartupTrue to enable scanning at startup, false to disable.

Definition at line 226 of file class.tool.git.php.

226 {
227 $this->scanStartup = $scanStartup;
228 Util::replaceInFile($this->bearsamppConf, array(
229 '/^' . self::LOCAL_CFG_SCAN_STARTUP . '/' => self::LOCAL_CFG_SCAN_STARTUP . ' = "' . $this->scanStartup . '"'
230 ));
231 }
static replaceInFile($path, $replaceList)

References $scanStartup, and Util\replaceInFile().

◆ setVersion()

setVersion ( $version)

Sets the version of the Git tool module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

Definition at line 178 of file class.tool.git.php.

178 {
179 global $bearsamppConfig;
180 $this->version = $version;
181 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
182 $this->reload();
183 }

References $bearsamppConfig, Module\$version, and reload().

◆ updateConfig()

updateConfig ( $version = null,
$sub = 0,
$showWindow = false )
protected

Updates the Git tool module configuration with a specific version.

Parameters
string | null$versionThe version to update to. If null, the current version is used.
int$subThe sub-level for logging indentation.
bool$showWindowWhether to show a window during the update process.
Returns
bool True if the update was successful, false otherwise.

Reimplemented from Module.

Definition at line 119 of file class.tool.git.php.

119 {
120 global $bearsamppWinbinder;
121
122 if (!$this->enable) {
123 return true;
124 }
125
126 $version = $version == null ? $this->version : $version;
127 Util::logDebug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
128
129 if (file_exists($this->getSymlinkPath() . '/post-install.bat')) {
130 $bearsamppWinbinder->exec($this->getBash(), '--no-needs-console --hide --no-cd --command=' . $this->getSymlinkPath() . '/post-install.bat', true);
131 }
132
133 $bearsamppWinbinder->exec($this->getExe(), 'config --global core.autocrlf false', true);
134 $bearsamppWinbinder->exec($this->getExe(), 'config --global core.eol lf', true);
135
136 return true;
137 }
static logDebug($data, $file=null)

References Module\$version, getBash(), getExe(), Module\getSymlinkPath(), and Util\logDebug().

Field Documentation

◆ $bash

$bash
private

Definition at line 32 of file class.tool.git.php.

Referenced by getBash().

◆ $exe

$exe
private

Definition at line 31 of file class.tool.git.php.

Referenced by getExe().

◆ $repos

$repos
private

Definition at line 29 of file class.tool.git.php.

Referenced by findRepos(), and getRepos().

◆ $reposCacheFile

$reposCacheFile
private

Definition at line 28 of file class.tool.git.php.

◆ $reposFile

$reposFile
private

Definition at line 27 of file class.tool.git.php.

◆ $scanStartup

$scanStartup
private

Definition at line 33 of file class.tool.git.php.

Referenced by setScanStartup().

◆ LOCAL_CFG_BASH

const LOCAL_CFG_BASH = 'gitBash'

Definition at line 21 of file class.tool.git.php.

◆ LOCAL_CFG_EXE

const LOCAL_CFG_EXE = 'gitExe'

Definition at line 20 of file class.tool.git.php.

◆ LOCAL_CFG_SCAN_STARTUP

const LOCAL_CFG_SCAN_STARTUP = 'gitScanStartup'

Definition at line 22 of file class.tool.git.php.

◆ REPOS_CACHE_FILE

const REPOS_CACHE_FILE = 'reposCache.dat'

Definition at line 25 of file class.tool.git.php.

◆ REPOS_FILE

const REPOS_FILE = 'repos.dat'

Definition at line 24 of file class.tool.git.php.

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'gitVersion'

Definition at line 18 of file class.tool.git.php.


The documentation for this class was generated from the following file: