2024.8.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 ()
 
 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()

ToolGit::__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()

ToolGit::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()

ToolGit::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().

+ Here is the caller graph for this function:

◆ getExe()

ToolGit::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().

+ Here is the caller graph for this function:

◆ getRepos()

ToolGit::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()

ToolGit::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()

ToolGit::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_FILE_NOT_FOUND
const GIT
const ERROR_CONF_NOT_FOUND
const ERROR_EXE_NOT_FOUND
const REPOS_FILE
const REPOS_CACHE_FILE
const LOCAL_CFG_BASH
const LOCAL_CFG_SCAN_STARTUP
const LOCAL_CFG_EXE
static logReloadClass($classInstance)
static logError($data, $file=null)
static formatUnixPath($path)
static logInfo($data, $file=null)
static logWarning($data, $file=null)
global $bearsamppConfig
Definition homepage.php:26

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, LOCAL_CFG_BASH, LOCAL_CFG_EXE, LOCAL_CFG_SCAN_STARTUP, Util\logError(), Util\logInfo(), Util\logReloadClass(), Util\logWarning(), REPOS_CACHE_FILE, and REPOS_FILE.

Referenced by __construct(), and setVersion().

+ Here is the caller graph for this function:

◆ setScanStartup()

ToolGit::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()

ToolGit::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()

ToolGit::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

ToolGit::$bash
private

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

Referenced by getBash().

◆ $exe

ToolGit::$exe
private

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

Referenced by getExe().

◆ $repos

ToolGit::$repos
private

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

Referenced by findRepos(), and getRepos().

◆ $reposCacheFile

ToolGit::$reposCacheFile
private

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

◆ $reposFile

ToolGit::$reposFile
private

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

◆ $scanStartup

ToolGit::$scanStartup
private

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

Referenced by setScanStartup().

◆ LOCAL_CFG_BASH

const ToolGit::LOCAL_CFG_BASH = 'gitBash'

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

Referenced by reload().

◆ LOCAL_CFG_EXE

const ToolGit::LOCAL_CFG_EXE = 'gitExe'

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

Referenced by reload().

◆ LOCAL_CFG_SCAN_STARTUP

const ToolGit::LOCAL_CFG_SCAN_STARTUP = 'gitScanStartup'

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

Referenced by reload().

◆ REPOS_CACHE_FILE

const ToolGit::REPOS_CACHE_FILE = 'reposCache.dat'

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

Referenced by reload().

◆ REPOS_FILE

const ToolGit::REPOS_FILE = 'repos.dat'

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

Referenced by reload().

◆ ROOT_CFG_VERSION

const ToolGit::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: