Bearsampp 2026.9.23
Loading...
Searching...
No Matches
ToolGit Class Reference
Inheritance diagram for ToolGit:
Collaboration 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 ()
 getId ()
 getName ()
 getRelease ()
 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
 $currentPath
 $rootPath
 $symlinkPath

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

Static Public Member Functions inherited from Module
static clearMemoryCache ()
static invalidateConfigCacheForPath ($sourcePath)
Protected Attributes inherited from Module
 $bearsamppConf
 $bearsamppConfRaw
 $enable
 $name
 $release = 'N/A'
 $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 77 of file class.tool.git.php.

78 {
79 Log::initClass($this);
80 $this->reload($id, $type);
81 }
static initClass($classInstance)
reload($id=null, $type=null)

References Module\$id, Module\$type, Log\initClass(), and reload().

Here is the call graph for this function:

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 188 of file class.tool.git.php.

189 {
190 $result = array();
191
192 if ($cache) {
193 if (file_exists($this->reposCacheFile)) {
194 $repos = file($this->reposCacheFile);
195 foreach ($repos as $repo) {
196 array_push($result, trim($repo));
197 }
198 }
199 } else {
200 if (!empty($this->repos)) {
201 foreach ($this->repos as $repo) {
202 $foundRepos = Util::findRepos($repo, $repo, '.git/config');
203 if (!empty($foundRepos)) {
204 foreach ($foundRepos as $foundRepo) {
205 array_push($result, $foundRepo);
206 }
207 }
208 }
209 }
210 $strResult = implode(PHP_EOL, $result);
211 file_put_contents($this->reposCacheFile, $strResult);
212 }
213
214 return $result;
215 }
$result
static findRepos($initPath, $startPath, $checkFile, $maxDepth=1)

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

Here is the call graph for this function:

◆ getBash()

getBash ( )

Retrieves the path to the Git Bash executable.

Returns
string The path to the Git Bash executable.

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

256 {
257 return $this->bash;
258 }

References $bash.

Referenced by updateConfig().

Here is the caller graph for this function:

◆ getExe()

getExe ( )

Retrieves the path to the Git executable.

Returns
string The path to the Git executable.

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

246 {
247 return $this->exe;
248 }

References $exe.

Referenced by updateConfig().

Here is the caller graph for this function:

◆ getRepos()

getRepos ( )

Retrieves the list of repositories.

Returns
array The list of repositories.

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

236 {
237 return $this->repos;
238 }

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 265 of file class.tool.git.php.

266 {
267 return $this->scanStartup == Config::ENABLED;
268 }
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 89 of file class.tool.git.php.

90 {
92 Log::reloadClass($this);
93
94 $this->name = $bearsamppLang->getValue(Lang::GIT);
95 $this->version = $bearsamppConfig->getRaw(self::ROOT_CFG_VERSION);
96 parent::reload($id, $type);
97
98 $this->reposFile = $this->symlinkPath . '/' . self::REPOS_FILE;
99 $this->reposCacheFile = $this->symlinkPath . '/' . self::REPOS_CACHE_FILE;
100
101 if ($this->bearsamppConfRaw !== false) {
102 $this->exe = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_EXE];
103 $this->bash = $this->symlinkPath . '/' . $this->bearsamppConfRaw[self::LOCAL_CFG_BASH];
104 $this->scanStartup = $this->bearsamppConfRaw[self::LOCAL_CFG_SCAN_STARTUP];
105 }
106
107 if (!$this->enable) {
108 Log::info($this->name . ' is not enabled!');
109
110 return;
111 }
112 if (!is_dir($this->currentPath)) {
113 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->currentPath));
114 }
115 if (!is_dir($this->symlinkPath)) {
116 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_FILE_NOT_FOUND), $this->name . ' ' . $this->version, $this->symlinkPath));
117
118 return;
119 }
120 if (!is_file($this->bearsamppConf)) {
121 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->bearsamppConf));
122 }
123 if (!is_file($this->reposFile)) {
124 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_CONF_NOT_FOUND), $this->name . ' ' . $this->version, $this->reposFile));
125 }
126 if (!is_file($this->exe)) {
127 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->exe));
128 }
129 if (!is_file($this->bash)) {
130 Log::error(sprintf($bearsamppLang->getValue(Lang::ERROR_EXE_NOT_FOUND), $this->name . ' ' . $this->version, $this->bash));
131 }
132
133 if (is_file($this->reposFile)) {
134 $this->repos = explode(PHP_EOL, file_get_contents($this->reposFile));
135 $rebuildRepos = array();
136 foreach ($this->repos as $repo) {
137 $repo = trim($repo);
138 if (stripos($repo, ':') === false) {
139 $repo = Path::getRootPath() . '/' . $repo;
140 }
141 if (is_dir($repo)) {
142 $rebuildRepos[] = Path::formatUnixPath($repo);
143 } else {
144 Log::warning($this->name . ' repository not found: ' . $repo);
145 }
146 }
147 $this->repos = $rebuildRepos;
148 }
149 }
global $bearsamppLang
global $bearsamppRoot
const ERROR_EXE_NOT_FOUND
const ERROR_CONF_NOT_FOUND
const GIT
const ERROR_FILE_NOT_FOUND
static info($data, $file=null)
static warning($data, $file=null)
static reloadClass($classInstance)
static error($data, $file=null)
static getRootPath($aetrayPath=false)
static formatUnixPath($path)
global $bearsamppConfig
Definition homepage.php:46

References $bearsamppConfig, $bearsamppLang, $bearsamppRoot, Module\$id, Module\$type, Log\error(), Lang\ERROR_CONF_NOT_FOUND, Lang\ERROR_EXE_NOT_FOUND, Lang\ERROR_FILE_NOT_FOUND, Path\formatUnixPath(), Path\getRootPath(), Lang\GIT, Log\info(), Log\reloadClass(), and Log\warning().

Referenced by __construct(), and setVersion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 275 of file class.tool.git.php.

276 {
277 $this->scanStartup = intval($scanStartup) === Config::ENABLED ? Config::ENABLED : Config::DISABLED;
278 Util::replaceInFile($this->bearsamppConf, array(
279 '/^' . self::LOCAL_CFG_SCAN_STARTUP . '/' => self::LOCAL_CFG_SCAN_STARTUP . ' = "' . $this->scanStartup . '"'
280 ));
281 }
const DISABLED
static replaceInFile($path, $replaceList)

References $scanStartup, Config\DISABLED, Config\ENABLED, and Util\replaceInFile().

Here is the call graph for this function:

◆ setVersion()

setVersion ( $version)

Sets the version of the Git tool module.

Parameters
string$versionThe version to set.

Reimplemented from Module.

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

223 {
224 global $bearsamppConfig;
225 $this->version = $version;
226 $bearsamppConfig->replace(self::ROOT_CFG_VERSION, $version);
227 $this->reload();
228 }

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

Here is the call graph for this function:

◆ 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 160 of file class.tool.git.php.

161 {
162 global $bearsamppWinbinder;
163
164 if (!$this->enable) {
165 return true;
166 }
167
168 $version = $version == null ? $this->version : $version;
169 Log::debug(($sub > 0 ? str_repeat(' ', 2 * $sub) : '') . 'Update ' . $this->name . ' ' . $version . ' config');
170
171 if (file_exists(Path::getModuleSymlinkPath($this) . '/post-install.bat')) {
172 $bearsamppWinbinder->exec($this->getBash(), '--no-needs-console --hide --no-cd --command="' . Path::getModuleSymlinkPath($this) . '/post-install.bat"', true);
173 }
174
175 $bearsamppWinbinder->exec($this->getExe(), 'config --global core.autocrlf false', true);
176 $bearsamppWinbinder->exec($this->getExe(), 'config --global core.eol lf', true);
177
178 return true;
179 }
static debug($data, $file=null)
static getModuleSymlinkPath($module)

References Module\$version, Log\debug(), getBash(), getExe(), and Path\getModuleSymlinkPath().

Here is the call graph for this function:

Field Documentation

◆ $bash

$bash
private

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

Referenced by getBash().

◆ $exe

$exe
private

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

Referenced by getExe().

◆ $repos

$repos
private

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

Referenced by findRepos(), and getRepos().

◆ $reposCacheFile

$reposCacheFile
private

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

◆ $reposFile

$reposFile
private

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

◆ $scanStartup

$scanStartup
private

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

Referenced by setScanStartup().

◆ LOCAL_CFG_BASH

const LOCAL_CFG_BASH = 'gitBash'

Configuration key for the Git Bash executable in the local configuration.

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

◆ LOCAL_CFG_EXE

const LOCAL_CFG_EXE = 'gitExe'

Configuration key for the Git executable in the local configuration.

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

◆ LOCAL_CFG_SCAN_STARTUP

const LOCAL_CFG_SCAN_STARTUP = 'gitScanStartup'

Configuration key for the Git scan-at-startup flag in the local configuration.

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

◆ REPOS_CACHE_FILE

const REPOS_CACHE_FILE = 'reposCache.dat'

The file name of the repositories cache.

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

◆ REPOS_FILE

const REPOS_FILE = 'repos.dat'

The file name of the repositories list.

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

◆ ROOT_CFG_VERSION

const ROOT_CFG_VERSION = 'gitVersion'

Configuration key for the Git version in the root configuration.

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


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