2024.8.23
Loading...
Searching...
No Matches
Util Class Reference

Static Public Member Functions

static changePath ($filesToScan, $rootPath=null)
 
static checkInternetState ()
 
static cleanArgv ($name, $type='text')
 
static cleanGetVar ($name, $type='text')
 
static cleanPostVar ($name, $type='text')
 
static clearFolder ($path, $exclude=array())
 
static clearFolders ($paths, $exclude=array())
 
static contains ($string, $search)
 
static cp1252ToUtf8 ($data)
 
static decryptFile ()
 
static deleteFolder ($path)
 
static disableLaunchStartup ()
 
static enableLaunchStartup ()
 
static endWith ($string, $search)
 
static findRepos ($initPath, $startPath, $checkFile, $maxDepth=1)
 
static formatUnixPath ($path)
 
static formatWindowsPath ($path)
 
static getApiJson ($url)
 
static getAppBinsRegKey ($fromRegistry=true)
 
static getAppPathRegKey ()
 
static getChangelogUrl ($utmSource=true)
 
static getCurlHttpHeaders ($url)
 
static getFilesToScan ($path=null)
 
static getFolderList ($path)
 
static getFopenHttpHeaders ($url)
 
static getGithubRawUrl ($file)
 
static getGithubUrl ($part=null)
 
static getGithubUserUrl ($part=null)
 
static getHeaders ($host, $port, $ssl=false)
 
static getHttpHeaders ($pingUrl)
 
static getLatestVersion ($url)
 
static getMicrotime ()
 
static getNssmEnvPaths ()
 
static getPowerShellPath ()
 
static getProcessorRegKey ()
 
static getRemoteFilesize ($url, $humanFileSize=true)
 
static getStartupLnkPath ()
 
static getSysPathRegKey ()
 
static getVersionList ($path)
 
static getWebsiteUrl ($path='', $fragment='', $utmSource=true)
 
static getWebsiteUrlNoUtm ($path='', $fragment='')
 
static humanFileSize ($size, $unit='')
 
static imgToBase64 ($path)
 
static installService ($bin, $port, $syntaxCheckCmd, $showWindow=false)
 
static is32BitsOs ()
 
static isAlphanumeric ($string)
 
static isLaunchStartup ()
 
static isPortInUse ($port)
 
static isValidDomainName ($domainName)
 
static isValidIp ($ip)
 
static isValidPort ($port)
 
static logDebug ($data, $file=null)
 
static logError ($data, $file=null)
 
static logInfo ($data, $file=null)
 
static logInitClass ($classInstance)
 
static logReloadClass ($classInstance)
 
static logSeparator ()
 
static logTrace ($data, $file=null)
 
static logWarning ($data, $file=null)
 
static openFileContent ($caption, $content)
 
static random ($length=32, $withNumeric=true)
 
static removeService ($service, $name)
 
static replaceDefine ($path, $var, $value)
 
static replaceInFile ($path, $replaceList)
 
static setAppBinsRegKey ($value)
 
static setAppPathRegKey ($value)
 
static setSysPathRegKey ($value)
 
static setupCurlHeaderWithToken ()
 
static startLoading ()
 
static startService ($bin, $syntaxCheckCmd, $showWindow=false)
 
static startWith ($string, $search)
 
static stopLoading ()
 
static utf8ToCp1252 ($data)
 

Data Fields

const LOG_DEBUG = 'DEBUG'
 
const LOG_ERROR = 'ERROR'
 
const LOG_INFO = 'INFO'
 
const LOG_TRACE = 'TRACE'
 
const LOG_WARNING = 'WARNING'
 

Static Private Member Functions

static findFile ($startPath, $findFile)
 
static findFiles ($startPath, $includes=array(''), $recursive=true)
 
static getPathsToScan ()
 
static log ($data, $type, $file=null)
 

Detailed Description

Utility class providing a wide range of static methods for various purposes including:

  • Cleaning and retrieving command line, GET, and POST variables based on type specifications.
  • String manipulation methods to check if strings contain, start with, or end with specified substrings.
  • File and directory management functions for deleting, clearing, or finding files and directories.
  • Logging functionalities tailored for different levels of verbosity (ERROR, WARNING, INFO, DEBUG, TRACE).
  • System utilities for handling registry operations, managing environment variables, and executing system commands.
  • Network utilities to validate IPs, domains, and manage HTTP requests.
  • Helper functions for encoding, decoding, and file operations.

This class is designed to be used as a helper or utility class where methods are accessed statically. This means you do not need to instantiate it to use the methods, but can simply call them using the Util\methodName() syntax.

Usage Example:

$cleanedData = Util::cleanGetVar('data', 'text');
Util::logError('An error occurred');
$isAvailable = Util::isValidIp('192.168.1.1');
static isValidIp($ip)
static cleanGetVar($name, $type='text')
static logError($data, $file=null)

Each method is self-contained and provides specific functionality, making this class a central point for common utility operations needed across a PHP application, especially in environments like web servers or command-line interfaces.

Definition at line 33 of file class.util.php.

Member Function Documentation

◆ changePath()

static Util::changePath ( $filesToScan,
$rootPath = null )
static

Replaces old path references with new path references in the specified files.

Parameters
array$filesToScanArray of file paths to scan and modify.
string | null$rootPathThe new root path to replace the old one. If null, uses a default root path.
Returns
array Returns an array with the count of occurrences changed and the count of files changed.

Definition at line 1255 of file class.util.php.

1256 {
1258
1259 $result = array(
1260 'countChangedOcc' => 0,
1261 'countChangedFiles' => 0
1262 );
1263
1264 $rootPath = $rootPath != null ? $rootPath : $bearsamppRoot->getRootPath();
1265 $unixOldPath = self::formatUnixPath( $bearsamppCore->getLastPathContent() );
1266 $windowsOldPath = self::formatWindowsPath( $bearsamppCore->getLastPathContent() );
1267 $unixCurrentPath = self::formatUnixPath( $rootPath );
1268 $windowsCurrentPath = self::formatWindowsPath( $rootPath );
1269
1270 foreach ( $filesToScan as $fileToScan ) {
1271 $tmpCountChangedOcc = 0;
1272 $fileContentOr = file_get_contents( $fileToScan );
1273 $fileContent = $fileContentOr;
1274
1275 // old path
1276 preg_match( '#' . $unixOldPath . '#i', $fileContent, $unixMatches );
1277 if ( !empty( $unixMatches ) ) {
1278 $fileContent = str_replace( $unixOldPath, $unixCurrentPath, $fileContent, $countChanged );
1279 $tmpCountChangedOcc += $countChanged;
1280 }
1281 preg_match( '#' . str_replace( '\\', '\\\\', $windowsOldPath ) . '#i', $fileContent, $windowsMatches );
1282 if ( !empty( $windowsMatches ) ) {
1283 $fileContent = str_replace( $windowsOldPath, $windowsCurrentPath, $fileContent, $countChanged );
1284 $tmpCountChangedOcc += $countChanged;
1285 }
1286
1287 // placeholders
1288 preg_match( '#' . Core::PATH_LIN_PLACEHOLDER . '#i', $fileContent, $unixMatches );
1289 if ( !empty( $unixMatches ) ) {
1290 $fileContent = str_replace( Core::PATH_LIN_PLACEHOLDER, $unixCurrentPath, $fileContent, $countChanged );
1291 $tmpCountChangedOcc += $countChanged;
1292 }
1293 preg_match( '#' . Core::PATH_WIN_PLACEHOLDER . '#i', $fileContent, $windowsMatches );
1294 if ( !empty( $windowsMatches ) ) {
1295 $fileContent = str_replace( Core::PATH_WIN_PLACEHOLDER, $windowsCurrentPath, $fileContent, $countChanged );
1296 $tmpCountChangedOcc += $countChanged;
1297 }
1298
1299 if ( $fileContentOr != $fileContent ) {
1300 $result['countChangedOcc'] += $tmpCountChangedOcc;
1301 $result['countChangedFiles'] += 1;
1302 file_put_contents( $fileToScan, $fileContent );
1303 }
1304 }
1305
1306 return $result;
1307 }
$result
global $bearsamppRoot
global $bearsamppCore
const PATH_WIN_PLACEHOLDER
const PATH_LIN_PLACEHOLDER
static formatUnixPath($path)
static formatWindowsPath($path)

References $bearsamppCore, $bearsamppRoot, $result, formatUnixPath(), formatWindowsPath(), Core\PATH_LIN_PLACEHOLDER, and Core\PATH_WIN_PLACEHOLDER.

Referenced by ActionStartup\changePath(), and ActionSwitchVersion\processWindow().

+ Here is the caller graph for this function:

◆ checkInternetState()

static Util::checkInternetState ( )
static

Checks the current state of the internet connection.

This method attempts to reach a well-known website (e.g., www.google.com) to determine the state of the internet connection. It returns true if the connection is successful, otherwise it returns false.

Returns
bool True if the internet connection is active, false otherwise.

Definition at line 2058 of file class.util.php.

2059 {
2060 $connected = @fsockopen( "www.google.com", 80 );
2061 if ( $connected ) {
2062 fclose( $connected );
2063
2064 return true; // Internet connection is active
2065 }
2066 else {
2067 return false; // Internet connection is not active
2068 }
2069 }

Referenced by QuickPick\getQuickpickMenu(), and QuickPick\installModule().

+ Here is the caller graph for this function:

◆ cleanArgv()

static Util::cleanArgv ( $name,
$type = 'text' )
static

Cleans and returns a specific command line argument based on the type specified.

Parameters
string$nameThe index of the argument in the $_SERVER['argv'] array.
string$typeThe type of the argument to return: 'text', 'numeric', 'boolean', or 'array'.
Returns
mixed Returns the cleaned argument based on the type or false if the argument is not set.

Definition at line 52 of file class.util.php.

53 {
54 if ( isset( $_SERVER['argv'] ) ) {
55 if ( $type == 'text' ) {
56 return (isset( $_SERVER['argv'][$name] ) && !empty( $_SERVER['argv'][$name] )) ? trim( $_SERVER['argv'][$name] ) : '';
57 }
58 elseif ( $type == 'numeric' ) {
59 return (isset( $_SERVER['argv'][$name] ) && is_numeric( $_SERVER['argv'][$name] )) ? intval( $_SERVER['argv'][$name] ) : '';
60 }
61 elseif ( $type == 'boolean' ) {
62 return (isset( $_SERVER['argv'][$name] )) ? true : false;
63 }
64 elseif ( $type == 'array' ) {
65 return (isset( $_SERVER['argv'][$name] ) && is_array( $_SERVER['argv'][$name] )) ? $_SERVER['argv'][$name] : array();
66 }
67 }
68
69 return false;
70 }

Referenced by Action\process().

+ Here is the caller graph for this function:

◆ cleanGetVar()

static Util::cleanGetVar ( $name,
$type = 'text' )
static

Cleans and returns a specific $_GET variable based on the type specified.

Parameters
string$nameThe name of the $_GET variable.
string$typeThe type of the variable to return: 'text', 'numeric', 'boolean', or 'array'.
Returns
mixed Returns the cleaned $_GET variable based on the type or false if the variable is not set.

Definition at line 80 of file class.util.php.

81 {
82 if ( is_string( $name ) ) {
83 if ( $type == 'text' ) {
84 return (isset( $_GET[$name] ) && !empty( $_GET[$name] )) ? stripslashes( $_GET[$name] ) : '';
85 }
86 elseif ( $type == 'numeric' ) {
87 return (isset( $_GET[$name] ) && is_numeric( $_GET[$name] )) ? intval( $_GET[$name] ) : '';
88 }
89 elseif ( $type == 'boolean' ) {
90 return (isset( $_GET[$name] )) ? true : false;
91 }
92 elseif ( $type == 'array' ) {
93 return (isset( $_GET[$name] ) && is_array( $_GET[$name] )) ? $_GET[$name] : array();
94 }
95 }
96
97 return false;
98 }

Referenced by Homepage\__construct().

+ Here is the caller graph for this function:

◆ cleanPostVar()

static Util::cleanPostVar ( $name,
$type = 'text' )
static

Cleans and returns a specific $_POST variable based on the type specified.

Parameters
string$nameThe name of the $_POST variable.
string$typeThe type of the variable to return: 'text', 'number', 'float', 'boolean', 'array', or 'content'.
Returns
mixed Returns the cleaned $_POST variable based on the type or false if the variable is not set.

Definition at line 108 of file class.util.php.

109 {
110 if ( is_string( $name ) ) {
111 if ( $type == 'text' ) {
112 return (isset( $_POST[$name] ) && !empty( $_POST[$name] )) ? stripslashes( trim( $_POST[$name] ) ) : '';
113 }
114 elseif ( $type == 'number' ) {
115 return (isset( $_POST[$name] ) && is_numeric( $_POST[$name] )) ? intval( $_POST[$name] ) : '';
116 }
117 elseif ( $type == 'float' ) {
118 return (isset( $_POST[$name] ) && is_numeric( $_POST[$name] )) ? floatval( $_POST[$name] ) : '';
119 }
120 elseif ( $type == 'boolean' ) {
121 return (isset( $_POST[$name] )) ? true : false;
122 }
123 elseif ( $type == 'array' ) {
124 return (isset( $_POST[$name] ) && is_array( $_POST[$name] )) ? $_POST[$name] : array();
125 }
126 elseif ( $type == 'content' ) {
127 return (isset( $_POST[$name] ) && !empty( $_POST[$name] )) ? trim( $_POST[$name] ) : '';
128 }
129 }
130
131 return false;
132 }

◆ clearFolder()

static Util::clearFolder ( $path,
$exclude = array() )
static

Recursively clears all files and directories within a specified directory, excluding specified items.

Parameters
string$pathThe path of the directory to clear.
array$excludeAn array of filenames to exclude from deletion.
Returns
array|null Returns an array with the operation status and count of files deleted, or null if the directory cannot be opened.

Definition at line 241 of file class.util.php.

242 {
243 $result = array();
244 $result['return'] = true;
245 $result['nb_files'] = 0;
246
247 $handle = @opendir( $path );
248 if ( !$handle ) {
249 return null;
250 }
251
252 while ( false !== ($file = readdir( $handle )) ) {
253 if ( $file == '.' || $file == '..' || in_array( $file, $exclude ) ) {
254 continue;
255 }
256 if ( is_dir( $path . '/' . $file ) ) {
257 $r = self::clearFolder( $path . '/' . $file );
258 if ( !$r ) {
259 $result['return'] = false;
260
261 return $result;
262 }
263 }
264 else {
265 $r = @unlink( $path . '/' . $file );
266 if ( $r ) {
267 $result['nb_files']++;
268 }
269 else {
270 $result['return'] = false;
271
272 return $result;
273 }
274 }
275 }
276
277 closedir( $handle );
278
279 return $result;
280 }
static clearFolder($path, $exclude=array())

References $result, and clearFolder().

Referenced by ActionClearFolders\__construct(), ActionStartup\cleanTmpFolders(), clearFolder(), clearFolders(), and ActionStartup\rotationLogs().

+ Here is the caller graph for this function:

◆ clearFolders()

static Util::clearFolders ( $paths,
$exclude = array() )
static

Recursively deletes files from a specified directory while excluding certain files.

Parameters
string$pathThe path to the directory to clear.
array$excludeAn array of filenames to exclude from deletion.
Returns
array Returns an array with the status of the operation and the number of files deleted.

Definition at line 223 of file class.util.php.

224 {
225 $result = array();
226 foreach ( $paths as $path ) {
227 $result[$path] = self::clearFolder( $path, $exclude );
228 }
229
230 return $result;
231 }

References $result, and clearFolder().

Referenced by ActionStartup\rotationLogs().

+ Here is the caller graph for this function:

◆ contains()

static Util::contains ( $string,
$search )
static

Checks if a string contains a specified substring.

Parameters
string$stringThe string to search in.
string$searchThe substring to search for.
Returns
bool Returns true if the substring is found in the string, otherwise false.

Definition at line 142 of file class.util.php.

143 {
144 if ( !empty( $string ) && !empty( $search ) ) {
145 $result = stripos( $string, $search );
146 if ( $result !== false ) {
147 return true;
148 }
149 else {
150 return false;
151 }
152 }
153 else {
154 return false;
155 }
156 }

References $result.

Referenced by BinMailhog\checkPort(), BinMailpit\checkPort(), BinXlight\checkPort(), BinMariadb\getCmdLineOutput(), BinMysql\getCmdLineOutput(), is32BitsOs(), and Win32Ps\killBins().

+ Here is the caller graph for this function:

◆ cp1252ToUtf8()

static Util::cp1252ToUtf8 ( $data)
static

Converts Windows-1252 encoded data to UTF-8 encoding.

Parameters
string$dataThe Windows-1252 encoded data.
Returns
string Returns the data encoded in UTF-8.

Definition at line 939 of file class.util.php.

940 {
941 return iconv( "WINDOWS-1252", "UTF-8//IGNORE", $data );
942 }

◆ decryptFile()

static Util::decryptFile ( )
static

Decrypts a file encrypted with a specified method and returns the content.

Parameters
string$encryptedFilePath to the encrypted file.
string$passwordPassword used for decryption.
string$methodEncryption method used (e.g., AES-256-CBC).
Returns
string|false Decrypted content or false on failure.

Definition at line 1980 of file class.util.php.

1981 {
1982 global $bearsamppCore;
1983
1984 $stringfile = $bearsamppCore->getResourcesPath() . '/string.dat';
1985 $encryptedFile = $bearsamppCore->getResourcesPath() . '/github.dat';
1986 $method = 'AES-256-CBC'; // The same encryption method used
1987
1988 // Get key string
1989 $stringPhrase = file_get_contents( $stringfile );
1990 if ( $stringPhrase === false ) {
1991 Util::logDebug( "Failed to read the file at path: {$stringfile}" );
1992
1993 return false;
1994 }
1995
1996 $stringKey = convert_uudecode( $stringPhrase );
1997
1998 // Read the encrypted data from the file
1999 $encryptedData = file_get_contents( $encryptedFile );
2000 if ( $encryptedData === false ) {
2001 Util::logDebug( "Failed to read the file at path: {$encryptedFile}" );
2002
2003 return false;
2004 }
2005
2006 // Decode the base64 encoded data
2007 $data = base64_decode( $encryptedData );
2008 if ( $data === false ) {
2009 Util::logDebug( "Failed to decode the data from path: {$encryptedFile}" );
2010
2011 return false;
2012 }
2013
2014 // Extract the IV which was prepended to the encrypted data
2015 $ivLength = openssl_cipher_iv_length( $method );
2016 $iv = substr( $data, 0, $ivLength );
2017 $encrypted = substr( $data, $ivLength );
2018
2019 // Decrypt the data
2020 $decrypted = openssl_decrypt( $encrypted, $method, $stringKey, 0, $iv );
2021 if ( $decrypted === false ) {
2022 Util::logDebug( "Decryption failed for data from path: {$encryptedFile}" );
2023
2024 return false;
2025 }
2026
2027 return $decrypted;
2028 }
static logDebug($data, $file=null)

References $bearsamppCore, and logDebug().

Referenced by setupCurlHeaderWithToken().

+ Here is the caller graph for this function:

◆ deleteFolder()

static Util::deleteFolder ( $path)
static

Recursively deletes a directory and all its contents.

Parameters
string$pathThe path of the directory to delete.

Definition at line 287 of file class.util.php.

288 {
289 if ( is_dir( $path ) ) {
290 if ( substr( $path, strlen( $path ) - 1, 1 ) != '/' ) {
291 $path .= '/';
292 }
293 $files = glob( $path . '*', GLOB_MARK );
294 foreach ( $files as $file ) {
295 if ( is_dir( $file ) ) {
296 self::deleteFolder( $file );
297 }
298 else {
299 unlink( $file );
300 }
301 }
302 rmdir( $path );
303 }
304 }
static deleteFolder($path)

References deleteFolder().

Referenced by deleteFolder(), and ActionStartup\rotationLogs().

+ Here is the caller graph for this function:

◆ disableLaunchStartup()

static Util::disableLaunchStartup ( )
static

Disables launching the application at startup by removing the shortcut from the startup folder.

Returns
bool True on success, false on failure.

Definition at line 665 of file class.util.php.

666 {
667 return @unlink( self::getStartupLnkPath() );
668 }

Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().

+ Here is the caller graph for this function:

◆ enableLaunchStartup()

static Util::enableLaunchStartup ( )
static

Enables launching the application at startup by creating a shortcut in the startup folder.

Returns
bool True on success, false on failure.

Definition at line 655 of file class.util.php.

656 {
657 return Vbs::createShortcut( self::getStartupLnkPath() );
658 }
static createShortcut($savePath)

References Vbs\createShortcut().

Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().

+ Here is the caller graph for this function:

◆ endWith()

static Util::endWith ( $string,
$search )
static

Checks if a string ends with a specified substring.

This method trims the right side whitespace of the input string before checking if it ends with the specified search substring.

Parameters
string$stringThe string to check.
string$searchThe substring to look for at the end of the string.
Returns
bool Returns true if the string ends with the search substring, otherwise false.

Definition at line 184 of file class.util.php.

185 {
186 $length = strlen( $search );
187 $start = $length * -1;
188
189 return (substr( $string, $start ) === $search);
190 }

Referenced by Batch\exec(), BinApache\getAlias(), BinPhp\getExtensionsFromFolder(), LangProc\getList(), TplAppLogs\getMenuLogs(), BinApache\getModulesFromFolder(), Batch\getProcessUsingPort(), and BinApache\getVhosts().

+ Here is the caller graph for this function:

◆ findFile()

static Util::findFile ( $startPath,
$findFile )
staticprivate

Recursively searches for a file starting from a specified directory.

Parameters
string$startPathThe directory path to start the search.
string$findFileThe filename to search for.
Returns
string|false Returns the path to the file if found, or false if not found.

Definition at line 314 of file class.util.php.

315 {
316 $result = false;
317
318 $handle = @opendir( $startPath );
319 if ( !$handle ) {
320 return false;
321 }
322
323 while ( false !== ($file = readdir( $handle )) ) {
324 if ( $file == '.' || $file == '..' ) {
325 continue;
326 }
327 if ( is_dir( $startPath . '/' . $file ) ) {
328 $result = self::findFile( $startPath . '/' . $file, $findFile );
329 if ( $result !== false ) {
330 break;
331 }
332 }
333 elseif ( $file == $findFile ) {
334 $result = self::formatUnixPath( $startPath . '/' . $file );
335 break;
336 }
337 }
338
339 closedir( $handle );
340
341 return $result;
342 }
static findFile($startPath, $findFile)

References $result, findFile(), and formatUnixPath().

Referenced by findFile(), and getPowerShellPath().

+ Here is the caller graph for this function:

◆ findFiles()

static Util::findFiles ( $startPath,
$includes = array(''),
$recursive = true )
staticprivate

Recursively finds files in a directory that match a set of inclusion patterns.

Parameters
string$startPathThe directory path to start the search from.
array$includesAn array of file patterns to include in the search. Patterns starting with '!' are excluded.
bool$recursiveDetermines whether the search should be recursive.
Returns
array An array of files that match the inclusion patterns.

Definition at line 1205 of file class.util.php.

1206 {
1207 $result = array();
1208
1209 $handle = @opendir( $startPath );
1210 if ( !$handle ) {
1211 return $result;
1212 }
1213
1214 while ( false !== ($file = readdir( $handle )) ) {
1215 if ( $file == '.' || $file == '..' ) {
1216 continue;
1217 }
1218 if ( is_dir( $startPath . '/' . $file ) && $recursive ) {
1219 $tmpResults = self::findFiles( $startPath . '/' . $file, $includes );
1220 foreach ( $tmpResults as $tmpResult ) {
1221 $result[] = $tmpResult;
1222 }
1223 }
1224 elseif ( is_file( $startPath . '/' . $file ) ) {
1225 foreach ( $includes as $include ) {
1226 if ( self::startWith( $include, '!' ) ) {
1227 $include = ltrim( $include, '!' );
1228 if ( self::startWith( $file, '.' ) && !self::endWith( $file, $include ) ) {
1229 $result[] = self::formatUnixPath( $startPath . '/' . $file );
1230 }
1231 elseif ( $file != $include ) {
1232 $result[] = self::formatUnixPath( $startPath . '/' . $file );
1233 }
1234 }
1235 elseif ( self::endWith( $file, $include ) || $file == $include || empty( $include ) ) {
1236 $result[] = self::formatUnixPath( $startPath . '/' . $file );
1237 }
1238 }
1239 }
1240 }
1241
1242 closedir( $handle );
1243
1244 return $result;
1245 }
static findFiles($startPath, $includes=array(''), $recursive=true)

References $result, findFiles(), and formatUnixPath().

Referenced by findFiles(), and getFilesToScan().

+ Here is the caller graph for this function:

◆ findRepos()

static Util::findRepos ( $initPath,
$startPath,
$checkFile,
$maxDepth = 1 )
static

Recursively searches for repositories starting from a given path up to a specified depth.

Parameters
string$initPathThe initial path from where the search begins.
string$startPathThe current path from where to search.
string$checkFileThe file name to check for in the directory to consider it a repository.
int$maxDepthThe maximum depth of directories to search into.
Returns
array Returns an array of paths that contain the specified file.

Definition at line 851 of file class.util.php.

852 {
853 $depth = substr_count( str_replace( $initPath, '', $startPath ), '/' );
854 $result = array();
855
856 $handle = @opendir( $startPath );
857 if ( !$handle ) {
858 return $result;
859 }
860
861 while ( false !== ($file = readdir( $handle )) ) {
862 if ( $file == '.' || $file == '..' ) {
863 continue;
864 }
865 if ( is_dir( $startPath . '/' . $file ) && ($initPath == $startPath || $depth <= $maxDepth) ) {
866 $tmpResults = self::findRepos( $initPath, $startPath . '/' . $file, $checkFile, $maxDepth );
867 foreach ( $tmpResults as $tmpResult ) {
868 $result[] = $tmpResult;
869 }
870 }
871 elseif ( is_file( $startPath . '/' . $checkFile ) && !in_array( $startPath, $result ) ) {
872 $result[] = self::formatUnixPath( $startPath );
873 }
874 }
875
876 closedir( $handle );
877
878 return $result;
879 }
static findRepos($initPath, $startPath, $checkFile, $maxDepth=1)

References $result, findRepos(), and formatUnixPath().

Referenced by ToolGit\findRepos(), and findRepos().

+ Here is the caller graph for this function:

◆ formatUnixPath()

static Util::formatUnixPath ( $path)
static

Converts a Windows-style path to a Unix-style path.

Parameters
string$pathThe Windows-style path to convert.
Returns
string Returns the converted Unix-style path.

Definition at line 900 of file class.util.php.

901 {
902 return str_replace( '\\', '/', $path );
903 }

Referenced by changePath(), Root\errorHandler(), Win32Ps\findByPath(), findFile(), findFiles(), findRepos(), BinApache\getAliasContent(), getNssmEnvPaths(), Vbs\getSpecialPath(), BinApache\getVhostContent(), Win32Ps\killBins(), ActionStartup\killOldInstances(), ActionGenSslCertificate\processWindow(), ActionStartup\processWindow(), BinFilezilla\reload(), and ToolGit\reload().

+ Here is the caller graph for this function:

◆ formatWindowsPath()

static Util::formatWindowsPath ( $path)
static

Converts a Unix-style path to a Windows-style path.

Parameters
string$pathThe Unix-style path to convert.
Returns
string Returns the converted Windows-style path.

Definition at line 888 of file class.util.php.

889 {
890 return str_replace( '/', '\\', $path );
891 }

Referenced by ActionAddVhost\__construct(), ActionEditAlias\__construct(), ActionEditVhost\__construct(), ActionGenSslCertificate\__construct(), changePath(), ActionStartup\checkPathRegKey(), Batch\createSymlink(), Module\createSymlink(), Symlinks\deleteCurrentSymlinks(), getAppBinsRegKey(), ToolConsoleZ\getShell(), Batch\getTmpFile(), Batch\installPostgresqlService(), openFileContent(), Batch\refreshEnvVars(), Batch\removeSymlink(), Nssm\setBinPath(), Win32Service\setBinPath(), Nssm\setEnvironmentExtra(), and Batch\uninstallPostgresqlService().

+ Here is the caller graph for this function:

◆ getApiJson()

static Util::getApiJson ( $url)
static

Sends a GET request to the specified URL and returns the response.

Parameters
string$urlThe URL to send the GET request to.
Returns
string The trimmed response data from the URL.

Definition at line 1611 of file class.util.php.

1612 {
1614
1615 $ch = curl_init();
1616 curl_setopt( $ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2 );
1617 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1618 curl_setopt( $ch, CURLOPT_VERBOSE, true );
1619 curl_setopt( $ch, CURLOPT_URL, $url );
1620 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
1621 curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
1622 $data = curl_exec( $ch );
1623 if ( curl_errno( $ch ) ) {
1624 Util::logError( 'CURL Error: ' . curl_error( $ch ) );
1625 }
1626 curl_close( $ch );
1627
1628 return trim( $data );
1629
1630 }
static setupCurlHeaderWithToken()

References logError(), and setupCurlHeaderWithToken().

Referenced by getLatestVersion().

+ Here is the caller graph for this function:

◆ getAppBinsRegKey()

static Util::getAppBinsRegKey ( $fromRegistry = true)
static

Definition at line 463 of file class.util.php.

464 {
465 global $bearsamppRegistry;
466
467 if ( $fromRegistry ) {
468 $value = $bearsamppRegistry->getValue(
472 );
473 self::logDebug( 'App reg key from registry: ' . $value );
474 }
475 else {
476 global $bearsamppBins, $bearsamppTools;
477 $value = '';
478 if ( $bearsamppBins->getApache()->isEnable() ) {
479 $value .= $bearsamppBins->getApache()->getSymlinkPath() . '/bin;';
480 }
481 if ( $bearsamppBins->getPhp()->isEnable() ) {
482 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . ';';
483 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/pear;';
484 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/deps;';
485 $value .= $bearsamppBins->getPhp()->getSymlinkPath() . '/imagick;';
486 }
487 if ( $bearsamppBins->getNodejs()->isEnable() ) {
488 $value .= $bearsamppBins->getNodejs()->getSymlinkPath() . ';';
489 }
490 if ( $bearsamppTools->getComposer()->isEnable() ) {
491 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . ';';
492 $value .= $bearsamppTools->getComposer()->getSymlinkPath() . '/vendor/bin;';
493 }
494 if ( $bearsamppTools->getGhostscript()->isEnable() ) {
495 $value .= $bearsamppTools->getGhostscript()->getSymlinkPath() . '/bin;';
496 }
497 if ( $bearsamppTools->getGit()->isEnable() ) {
498 $value .= $bearsamppTools->getGit()->getSymlinkPath() . '/bin;';
499 }
500 if ( $bearsamppTools->getNgrok()->isEnable() ) {
501 $value .= $bearsamppTools->getNgrok()->getSymlinkPath() . ';';
502 }
503 if ( $bearsamppTools->getPerl()->isEnable() ) {
504 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/site/bin;';
505 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/perl/bin;';
506 $value .= $bearsamppTools->getPerl()->getSymlinkPath() . '/c/bin;';
507 }
508 if ( $bearsamppTools->getPython()->isEnable() ) {
509 $value .= $bearsamppTools->getPython()->getSymlinkPath() . '/bin;';
510 }
511 if ( $bearsamppTools->getRuby()->isEnable() ) {
512 $value .= $bearsamppTools->getRuby()->getSymlinkPath() . '/bin;';
513 }
514 if ( $bearsamppTools->getYarn()->isEnable() ) {
515 $value .= $bearsamppTools->getYarn()->getSymlinkPath() . ';';
516 $value .= $bearsamppTools->getYarn()->getSymlinkPath() . '/global/bin;';
517 }
518 $value = self::formatWindowsPath( $value );
519 self::logDebug( 'Generated app bins reg key: ' . $value );
520 }
521
522 return $value;
523 }
global $bearsamppBins
const APP_BINS_REG_ENTRY
const HKEY_LOCAL_MACHINE

References $bearsamppBins, Registry\APP_BINS_REG_ENTRY, Registry\ENV_KEY, formatWindowsPath(), Registry\HKEY_LOCAL_MACHINE, and logDebug().

Referenced by ActionStartup\checkBinsRegKey(), Win32Service\create(), and ActionSwitchVersion\processWindow().

+ Here is the caller graph for this function:

◆ getAppPathRegKey()

static Util::getAppPathRegKey ( )
static

Retrieves the application path from the registry.

Returns
mixed The value of the application path registry key or false on error.

Definition at line 549 of file class.util.php.

550 {
551 global $bearsamppRegistry;
552
553 return $bearsamppRegistry->getValue(
557 );
558 }
const APP_PATH_REG_ENTRY

References Registry\APP_PATH_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkPathRegKey().

+ Here is the caller graph for this function:

◆ getChangelogUrl()

static Util::getChangelogUrl ( $utmSource = true)
static

Constructs the URL to the changelog page, optionally including UTM parameters.

Parameters
bool$utmSourceWhether to include UTM source parameters.
Returns
string The URL to the changelog page.

Definition at line 1390 of file class.util.php.

1391 {
1392 return self::getWebsiteUrl( 'doc/changelog', null, $utmSource );
1393 }
static getWebsiteUrl($path='', $fragment='', $utmSource=true)

References getWebsiteUrl().

◆ getCurlHttpHeaders()

static Util::getCurlHttpHeaders ( $url)
static

Retrieves HTTP headers from a given URL using cURL.

This method initializes a cURL session, sets various options to fetch headers including disabling SSL peer verification, and executes the request. It logs the raw response for debugging purposes and parses the headers from the response.

Parameters
string$urlThe URL from which to fetch the headers.
Returns
array An array of headers if successful, otherwise an empty array.

Definition at line 1529 of file class.util.php.

1530 {
1531 $result = array();
1532
1533 $ch = curl_init();
1534 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1535 curl_setopt( $ch, CURLOPT_VERBOSE, true );
1536 curl_setopt( $ch, CURLOPT_HEADER, true );
1537 curl_setopt( $ch, CURLOPT_URL, $url );
1538 curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
1539
1540 $response = @curl_exec( $ch );
1541 if ( empty( $response ) ) {
1542 return $result;
1543 }
1544
1545 self::logTrace( 'getCurlHttpHeaders:' . $response );
1546 $responseHeaders = explode( "\r\n\r\n", $response, 2 );
1547 if ( !isset( $responseHeaders[0] ) || empty( $responseHeaders[0] ) ) {
1548 return $result;
1549 }
1550
1551 return explode( "\n", $responseHeaders[0] );
1552 }
$response
static logTrace($data, $file=null)

References $response, $result, and logTrace().

Referenced by getHttpHeaders().

+ Here is the caller graph for this function:

◆ getFilesToScan()

static Util::getFilesToScan ( $path = null)
static

Retrieves a list of files to scan from specified paths or default paths.

Parameters
string | null$pathOptional. The path to start scanning from. If null, uses default paths.
Returns
array Returns an array of files found during the scan.

Definition at line 975 of file class.util.php.

976 {
977 $result = array();
978 $pathsToScan = !empty( $path ) ? $path : self::getPathsToScan();
979 foreach ( $pathsToScan as $pathToScan ) {
980 $startTime = self::getMicrotime();
981 $findFiles = self::findFiles( $pathToScan['path'], $pathToScan['includes'], $pathToScan['recursive'] );
982 foreach ( $findFiles as $findFile ) {
983 $result[] = $findFile;
984 }
985 self::logDebug( $pathToScan['path'] . ' scanned in ' . round( self::getMicrotime() - $startTime, 3 ) . 's' );
986 }
987
988 return $result;
989 }
static getPathsToScan()
static getMicrotime()

References $result, findFiles(), getMicrotime(), getPathsToScan(), and logDebug().

Referenced by ActionSwitchVersion\processWindow(), and ActionStartup\scanFolders().

+ Here is the caller graph for this function:

◆ getFolderList()

static Util::getFolderList ( $path)
static

Retrieves a list of folders from a specified directory, excluding certain directories.

Parameters
string$pathThe directory path from which to list folders.
Returns
array|bool An array of folder names, or false if the directory cannot be opened.

Definition at line 1890 of file class.util.php.

1891 {
1892 $result = array();
1893
1894 $handle = @opendir( $path );
1895 if ( !$handle ) {
1896 return false;
1897 }
1898
1899 while ( false !== ($file = readdir( $handle )) ) {
1900 $filePath = $path . '/' . $file;
1901 if ( $file != "." && $file != ".." && is_dir( $filePath ) && $file != 'current' ) {
1902 $result[] = $file;
1903 }
1904 }
1905
1906 closedir( $handle );
1907
1908 return $result;
1909 }

References $result.

Referenced by ActionSwitchVersion\__construct(), and getPathsToScan().

+ Here is the caller graph for this function:

◆ getFopenHttpHeaders()

static Util::getFopenHttpHeaders ( $url)
static

Retrieves HTTP headers from a given URL using the fopen function.

This method creates a stream context to disable SSL peer and peer name verification, which allows self-signed certificates. It attempts to open the URL and read the HTTP response headers.

Parameters
string$urlThe URL from which to fetch the headers.
Returns
array An array of headers if successful, otherwise an empty array.

Definition at line 1496 of file class.util.php.

1497 {
1498 $result = array();
1499
1500 $context = stream_context_create( array(
1501 'ssl' => array(
1502 'verify_peer' => false,
1503 'verify_peer_name' => false,
1504 'allow_self_signed' => true,
1505 )
1506 ) );
1507
1508 $fp = @fopen( $url, 'r', false, $context );
1509 if ( $fp ) {
1510 $meta = stream_get_meta_data( $fp );
1511 $result = isset( $meta['wrapper_data'] ) ? $meta['wrapper_data'] : $result;
1512 fclose( $fp );
1513 }
1514
1515 return $result;
1516 }

References $result.

Referenced by getHttpHeaders().

+ Here is the caller graph for this function:

◆ getGithubRawUrl()

static Util::getGithubRawUrl ( $file)
static

Constructs a URL for raw content from a GitHub repository.

Parameters
string$fileThe file path to append to the base URL.
Returns
string The full URL to the raw content on GitHub.

Definition at line 1876 of file class.util.php.

1877 {
1878 $file = !empty( $file ) ? '/' . $file : null;
1879
1880 return 'https://raw.githubusercontent.com/' . APP_GITHUB_USER . '/' . APP_GITHUB_REPO . '/main' . $file;
1881 }
const APP_GITHUB_USER
Definition root.php:15
const APP_GITHUB_REPO
Definition root.php:16

References APP_GITHUB_REPO, and APP_GITHUB_USER.

◆ getGithubUrl()

static Util::getGithubUrl ( $part = null)
static

Constructs a GitHub repository URL with an optional path.

Parameters
string | null$partOptional path to append to the URL.
Returns
string The full GitHub repository URL.

Definition at line 1862 of file class.util.php.

1863 {
1864 $part = !empty( $part ) ? '/' . $part : null;
1865
1866 return self::getGithubUserUrl( APP_GITHUB_REPO . $part );
1867 }
static getGithubUserUrl($part=null)

References APP_GITHUB_REPO, and getGithubUserUrl().

◆ getGithubUserUrl()

static Util::getGithubUserUrl ( $part = null)
static

Constructs a GitHub user URL with an optional path.

Parameters
string | null$partOptional path to append to the URL.
Returns
string The full GitHub user URL.

Definition at line 1848 of file class.util.php.

1849 {
1850 $part = !empty( $part ) ? '/' . $part : null;
1851
1852 return 'https://github.com/' . APP_GITHUB_USER . $part;
1853 }

References APP_GITHUB_USER.

Referenced by ActionAbout\__construct(), getGithubUrl(), and ActionAbout\processWindow().

+ Here is the caller graph for this function:

◆ getHeaders()

static Util::getHeaders ( $host,
$port,
$ssl = false )
static

Retrieves the initial response line from a specified host and port using a socket connection.

This method optionally uses SSL and creates a stream context similar to getFopenHttpHeaders. It attempts to connect to the host and port, reads the first line of the response, and parses it. Detailed debug information is logged for each header line received.

Parameters
string$hostThe host name or IP address to connect to.
int$portThe port number to connect to.
bool$sslWhether to use SSL (defaults to false).
Returns
array An array containing the first line of the response, split into parts, or an empty array if unsuccessful.

Definition at line 1567 of file class.util.php.

1568 {
1569 $result = array();
1570 $context = stream_context_create( array(
1571 'ssl' => array(
1572 'verify_peer' => false,
1573 'verify_peer_name' => false,
1574 'allow_self_signed' => true,
1575 )
1576 ) );
1577
1578 $fp = @stream_socket_client( ($ssl ? 'ssl://' : '') . $host . ':' . $port, $errno, $errstr, 5, STREAM_CLIENT_CONNECT, $context );
1579 if ( $fp ) {
1580 $out = fgets( $fp );
1581 $result = explode( PHP_EOL, $out );
1582 @fclose( $fp );
1583 }
1584
1585 if ( !empty( $result ) ) {
1586 $rebuildResult = array();
1587 foreach ( $result as $row ) {
1588 $row = trim( $row );
1589 if ( !empty( $row ) ) {
1590 $rebuildResult[] = $row;
1591 }
1592 }
1593 $result = $rebuildResult;
1594
1595 self::logDebug( 'getHeaders:' );
1596 foreach ( $result as $header ) {
1597 self::logDebug( '-> ' . $header );
1598 }
1599 }
1600
1601 return $result;
1602 }
$port

References $port, $result, and logDebug().

Referenced by BinFilezilla\checkPort(), BinMailhog\checkPort(), BinMailpit\checkPort(), and BinXlight\checkPort().

+ Here is the caller graph for this function:

◆ getHttpHeaders()

static Util::getHttpHeaders ( $pingUrl)
static

Retrieves HTTP headers from a given URL using either cURL or fopen, depending on availability.

Parameters
string$pingUrlThe URL to ping for headers.
Returns
array An array of HTTP headers.

Definition at line 1457 of file class.util.php.

1458 {
1459 if ( function_exists( 'curl_version' ) ) {
1460 $result = self::getCurlHttpHeaders( $pingUrl );
1461 }
1462 else {
1463 $result = self::getFopenHttpHeaders( $pingUrl );
1464 }
1465
1466 if ( !empty( $result ) ) {
1467 $rebuildResult = array();
1468 foreach ( $result as $row ) {
1469 $row = trim( $row );
1470 if ( !empty( $row ) ) {
1471 $rebuildResult[] = $row;
1472 }
1473 }
1474 $result = $rebuildResult;
1475
1476 self::logDebug( 'getHttpHeaders:' );
1477 foreach ( $result as $header ) {
1478 self::logDebug( '-> ' . $header );
1479 }
1480 }
1481
1482 return $result;
1483 }
static getFopenHttpHeaders($url)
static getCurlHttpHeaders($url)

References $result, getCurlHttpHeaders(), getFopenHttpHeaders(), and logDebug().

Referenced by BinApache\checkPort().

+ Here is the caller graph for this function:

◆ getLatestVersion()

static Util::getLatestVersion ( $url)
static

Fetches the latest version information from a given URL.

Parameters
string$urlThe URL to fetch version information from.
Returns
array|null Returns an array with 'version' and 'url' if successful, null otherwise.

Definition at line 1316 of file class.util.php.

1317 {
1318 $result = self::getApiJson( $url );
1319 if ( empty( $result ) ) {
1320 self::logError( 'Cannot retrieve latest github info for: ' . $result . ' RESULT' );
1321
1322 return null;
1323 }
1324
1325 $resultArray = json_decode( $result, true );
1326 if ( isset( $resultArray['tag_name'] ) && isset( $resultArray['assets'][0]['browser_download_url'] ) ) {
1327 $tagName = $resultArray['tag_name'];
1328 $downloadUrl = $resultArray['assets'][0]['browser_download_url'];
1329 $name = $resultArray['name'];
1330 self::logDebug( 'Latest version tag name: ' . $tagName );
1331 self::logDebug( 'Download URL: ' . $downloadUrl );
1332 self::logDebug( 'Name: ' . $name );
1333
1334 return ['version' => $tagName, 'html_url' => $downloadUrl, 'name' => $name];
1335 }
1336 else {
1337 self::logError( 'Tag name, download URL, or name not found in the response: ' . $result );
1338
1339 return null;
1340 }
1341 }
static getApiJson($url)

References $result, getApiJson(), logDebug(), and logError().

Referenced by ActionCheckVersion\__construct(), and ActionCheckVersion\processWindow().

+ Here is the caller graph for this function:

◆ getMicrotime()

static Util::getMicrotime ( )
static

Gets the current Unix timestamp with microseconds.

Returns
float Returns the current Unix timestamp combined with microseconds.

Definition at line 456 of file class.util.php.

457 {
458 list( $usec, $sec ) = explode( " ", microtime() );
459
460 return ((float) $usec + (float) $sec);
461 }

Referenced by ActionStartup\__construct(), getFilesToScan(), ActionStartup\installServices(), and ActionStartup\processWindow().

+ Here is the caller graph for this function:

◆ getNssmEnvPaths()

static Util::getNssmEnvPaths ( )
static

Retrieves and formats environment paths from a data file. Paths are verified to be directories and formatted to Unix style. Warnings are logged for paths that do not exist.

Returns
string A semicolon-separated string of formatted environment paths. @global object $bearsamppRoot Global object containing root path methods.

Definition at line 1919 of file class.util.php.

1920 {
1921 global $bearsamppRoot;
1922
1923 $result = '';
1924 $nssmEnvPathsFile = $bearsamppRoot->getRootPath() . '/nssmEnvPaths.dat';
1925
1926 if ( is_file( $nssmEnvPathsFile ) ) {
1927 $paths = explode( PHP_EOL, file_get_contents( $nssmEnvPathsFile ) );
1928 foreach ( $paths as $path ) {
1929 $path = trim( $path );
1930 if ( stripos( $path, ':' ) === false ) {
1931 $path = $bearsamppRoot->getRootPath() . '/' . $path;
1932 }
1933 if ( is_dir( $path ) ) {
1934 $result .= self::formatUnixPath( $path ) . ';';
1935 }
1936 else {
1937 self::logWarning( 'Path not found in nssmEnvPaths.dat: ' . $path );
1938 }
1939 }
1940 }
1941
1942 return $result;
1943 }
static logWarning($data, $file=null)

References $bearsamppRoot, $result, formatUnixPath(), and logWarning().

Referenced by Win32Service\create().

+ Here is the caller graph for this function:

◆ getPathsToScan()

static Util::getPathsToScan ( )
staticprivate

Retrieves a list of directories and file types to scan within the BEARSAMPP environment.

This method compiles an array of paths from various components of the BEARSAMPP stack, including Apache, PHP, MySQL, MariaDB, PostgreSQL, Node.js, Filezilla, Composer, ConsoleZ, Python, Ruby, and Yarn. Each path entry includes the directory path, file types to include in the scan, and whether the scan should be recursive.

The method uses global variables to access the root paths of each component. It then dynamically fetches specific subdirectories using the getFolderList method (which is assumed to be defined elsewhere in this class or in the global scope) and constructs an array of path specifications.

Each path specification is an associative array with the following keys:

  • 'path': The full directory path to scan.
  • 'includes': An array of file extensions or filenames to include in the scan.
  • 'recursive': A boolean indicating whether the scan should include subdirectories.

The method is designed to be used for setting up scans of configuration files and other important files within the BEARSAMPP environment, possibly for purposes like configuration management, backup, or security auditing.

Returns
array An array of associative arrays, each containing 'path', 'includes', and 'recursive' keys.

Definition at line 1015 of file class.util.php.

1016 {
1017 global $bearsamppRoot, $bearsamppCore, $bearsamppBins, $bearsamppApps, $bearsamppTools;
1018 $paths = array();
1019
1020 // Alias
1021 $paths[] = array(
1022 'path' => $bearsamppRoot->getAliasPath(),
1023 'includes' => array(''),
1024 'recursive' => false
1025 );
1026
1027 // Vhosts
1028 $paths[] = array(
1029 'path' => $bearsamppRoot->getVhostsPath(),
1030 'includes' => array(''),
1031 'recursive' => false
1032 );
1033
1034 // OpenSSL
1035 $paths[] = array(
1036 'path' => $bearsamppCore->getOpenSslPath(),
1037 'includes' => array('openssl.cfg'),
1038 'recursive' => false
1039 );
1040
1041 // Homepage
1042 $paths[] = array(
1043 'path' => $bearsamppCore->getResourcesPath() . '/homepage',
1044 'includes' => array('alias.conf'),
1045 'recursive' => false
1046 );
1047
1048 // Apache
1049 $folderList = self::getFolderList( $bearsamppBins->getApache()->getRootPath() );
1050 foreach ( $folderList as $folder ) {
1051 $paths[] = array(
1052 'path' => $bearsamppBins->getApache()->getRootPath() . '/' . $folder,
1053 'includes' => array('.ini', '.conf'),
1054 'recursive' => true
1055 );
1056 }
1057
1058 // PHP
1059 $folderList = self::getFolderList( $bearsamppBins->getPhp()->getRootPath() );
1060 foreach ( $folderList as $folder ) {
1061 $paths[] = array(
1062 'path' => $bearsamppBins->getPhp()->getRootPath() . '/' . $folder,
1063 'includes' => array('.php', '.bat', '.ini', '.reg', '.inc'),
1064 'recursive' => true
1065 );
1066 }
1067
1068 // MySQL
1069 $folderList = self::getFolderList( $bearsamppBins->getMysql()->getRootPath() );
1070 foreach ( $folderList as $folder ) {
1071 $paths[] = array(
1072 'path' => $bearsamppBins->getMysql()->getRootPath() . '/' . $folder,
1073 'includes' => array('my.ini'),
1074 'recursive' => false
1075 );
1076 }
1077
1078 // MariaDB
1079 $folderList = self::getFolderList( $bearsamppBins->getMariadb()->getRootPath() );
1080 foreach ( $folderList as $folder ) {
1081 $paths[] = array(
1082 'path' => $bearsamppBins->getMariadb()->getRootPath() . '/' . $folder,
1083 'includes' => array('my.ini'),
1084 'recursive' => false
1085 );
1086 }
1087
1088 // PostgreSQL
1089 $folderList = self::getFolderList( $bearsamppBins->getPostgresql()->getRootPath() );
1090 foreach ( $folderList as $folder ) {
1091 $paths[] = array(
1092 'path' => $bearsamppBins->getPostgresql()->getRootPath() . '/' . $folder,
1093 'includes' => array('.ber', '.conf', '.bat'),
1094 'recursive' => true
1095 );
1096 }
1097
1098 // Node.js
1099 $folderList = self::getFolderList( $bearsamppBins->getNodejs()->getRootPath() );
1100 foreach ( $folderList as $folder ) {
1101 $paths[] = array(
1102 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/etc',
1103 'includes' => array('npmrc'),
1104 'recursive' => true
1105 );
1106 $paths[] = array(
1107 'path' => $bearsamppBins->getNodejs()->getRootPath() . '/' . $folder . '/node_modules/npm',
1108 'includes' => array('npmrc'),
1109 'recursive' => false
1110 );
1111 }
1112
1113 // Filezilla
1114 $folderList = self::getFolderList( $bearsamppBins->getFilezilla()->getRootPath() );
1115 foreach ( $folderList as $folder ) {
1116 $paths[] = array(
1117 'path' => $bearsamppBins->getFilezilla()->getRootPath() . '/' . $folder,
1118 'includes' => array('.xml'),
1119 'recursive' => true
1120 );
1121 }
1122
1123 // Composer
1124 $folderList = self::getFolderList( $bearsamppTools->getComposer()->getRootPath() );
1125 foreach ( $folderList as $folder ) {
1126 $paths[] = array(
1127 'path' => $bearsamppTools->getComposer()->getRootPath() . '/' . $folder,
1128 'includes' => array('giscus.json'),
1129 'recursive' => false
1130 );
1131 }
1132
1133 // ConsoleZ
1134 $folderList = self::getFolderList( $bearsamppTools->getConsoleZ()->getRootPath() );
1135 foreach ( $folderList as $folder ) {
1136 $paths[] = array(
1137 'path' => $bearsamppTools->getConsoleZ()->getRootPath() . '/' . $folder,
1138 'includes' => array('console.xml', '.ini', '.btm'),
1139 'recursive' => true
1140 );
1141 }
1142
1143 // Python
1144 $folderList = self::getFolderList( $bearsamppTools->getPython()->getRootPath() );
1145 foreach ( $folderList as $folder ) {
1146 $paths[] = array(
1147 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/bin',
1148 'includes' => array('.bat'),
1149 'recursive' => false
1150 );
1151 $paths[] = array(
1152 'path' => $bearsamppTools->getPython()->getRootPath() . '/' . $folder . '/settings',
1153 'includes' => array('winpython.ini'),
1154 'recursive' => false
1155 );
1156 }
1157
1158 // Ruby
1159 $folderList = self::getFolderList( $bearsamppTools->getRuby()->getRootPath() );
1160 foreach ( $folderList as $folder ) {
1161 $paths[] = array(
1162 'path' => $bearsamppTools->getRuby()->getRootPath() . '/' . $folder . '/bin',
1163 'includes' => array('!.dll', '!.exe'),
1164 'recursive' => false
1165 );
1166 }
1167
1168 // Yarn
1169 $folderList = self::getFolderList( $bearsamppTools->getYarn()->getRootPath() );
1170 foreach ( $folderList as $folder ) {
1171 $paths[] = array(
1172 'path' => $bearsamppTools->getYarn()->getRootPath() . '/' . $folder,
1173 'includes' => array('yarn.bat'),
1174 'recursive' => false
1175 );
1176 $paths[] = array(
1177 'path' => $bearsamppTools->getYarn()->getRootPath() . '/' . $folder . '/global/bin',
1178 'includes' => array('.bat'),
1179 'recursive' => false
1180 );
1181 $paths[] = array(
1182 'path' => $bearsamppTools->getYarn()->getRootPath() . '/' . $folder . '/nodejs/etc',
1183 'includes' => array('npmrc'),
1184 'recursive' => true
1185 );
1186 $paths[] = array(
1187 'path' => $bearsamppTools->getYarn()->getRootPath() . '/' . $folder . '/nodejs/node_modules/npm',
1188 'includes' => array('npmrc'),
1189 'recursive' => false
1190 );
1191 }
1192
1193 return $paths;
1194 }
static getFolderList($path)

References $bearsamppBins, $bearsamppCore, $bearsamppRoot, and getFolderList().

Referenced by getFilesToScan().

+ Here is the caller graph for this function:

◆ getPowerShellPath()

static Util::getPowerShellPath ( )
static

Finds the path to the PowerShell executable in the Windows System32 directory.

Returns
string|false Returns the path to powershell.exe if found, otherwise false.

Definition at line 832 of file class.util.php.

833 {
834 if ( is_dir( 'C:\Windows\System32\WindowsPowerShell' ) ) {
835 return self::findFile( 'C:\Windows\System32\WindowsPowerShell', 'powershell.exe' );
836 }
837
838 return false;
839 }

References findFile().

Referenced by TplConsoleZ\getTabPowerShellSection().

+ Here is the caller graph for this function:

◆ getProcessorRegKey()

static Util::getProcessorRegKey ( )
static

Retrieves the processor identifier from the registry.

Returns
mixed The value of the processor identifier registry key or false on error.

Definition at line 619 of file class.util.php.

620 {
621 global $bearsamppRegistry;
622
623 return $bearsamppRegistry->getValue(
627 );
628 }
const PROCESSOR_REG_ENTRY
const PROCESSOR_REG_SUBKEY

References Registry\HKEY_LOCAL_MACHINE, Registry\PROCESSOR_REG_ENTRY, and Registry\PROCESSOR_REG_SUBKEY.

Referenced by is32BitsOs().

+ Here is the caller graph for this function:

◆ getRemoteFilesize()

static Util::getRemoteFilesize ( $url,
$humanFileSize = true )
static

Retrieves the file size of a remote file.

Parameters
string$urlThe URL of the remote file.
bool$humanFileSizeWhether to return the size in a human-readable format.
Returns
mixed The file size, either in bytes or as a formatted string.

Definition at line 1403 of file class.util.php.

1404 {
1405 $size = 0;
1406
1407 $data = get_headers( $url, true );
1408 if ( isset( $data['Content-Length'] ) ) {
1409 $size = intval( $data['Content-Length'] );
1410 }
1411
1412 return $humanFileSize ? self::humanFileSize( $size ) : $size;
1413 }
static humanFileSize($size, $unit='')

References humanFileSize().

◆ getStartupLnkPath()

static Util::getStartupLnkPath ( )
static

Retrieves the path for the startup link file.

Returns
string The full path to the startup link file.

Definition at line 635 of file class.util.php.

636 {
637 return Vbs::getStartupPath( APP_TITLE . '.lnk' );
638 }
static getStartupPath($file=null)
const APP_TITLE
Definition root.php:12

References APP_TITLE, and Vbs\getStartupPath().

◆ getSysPathRegKey()

static Util::getSysPathRegKey ( )
static

Retrieves the system path from the registry.

Returns
mixed The value of the system path registry key or false on error.

Definition at line 584 of file class.util.php.

585 {
586 global $bearsamppRegistry;
587
588 return $bearsamppRegistry->getValue(
592 );
593 }
const SYSPATH_REG_ENTRY

References Registry\ENV_KEY, Registry\HKEY_LOCAL_MACHINE, and Registry\SYSPATH_REG_ENTRY.

Referenced by ActionStartup\checkSystemPathRegKey().

+ Here is the caller graph for this function:

◆ getVersionList()

static Util::getVersionList ( $path)
static

Retrieves a list of version directories within a specified path.

Parameters
string$pathThe path to search for version directories.
Returns
array|false Returns a sorted array of version names, or false if the directory cannot be opened.

Definition at line 429 of file class.util.php.

430 {
431 $result = array();
432
433 $handle = @opendir( $path );
434 if ( !$handle ) {
435 return false;
436 }
437
438 while ( false !== ($file = readdir( $handle )) ) {
439 $filePath = $path . '/' . $file;
440 if ( $file != "." && $file != ".." && is_dir( $filePath ) && $file != 'current' ) {
441 $result[] = str_replace( basename( $path ), '', $file );
442 }
443 }
444
445 closedir( $handle );
446 natcasesort( $result );
447
448 return $result;
449 }

References $result.

Referenced by Module\getVersionList().

+ Here is the caller graph for this function:

◆ getWebsiteUrl()

static Util::getWebsiteUrl ( $path = '',
$fragment = '',
$utmSource = true )
static

Constructs a complete website URL with optional path, fragment, and UTM source parameters.

Parameters
string$pathOptional path to append to the base URL.
string$fragmentOptional fragment to append to the URL.
bool$utmSourceWhether to include UTM source parameters.
Returns
string The constructed URL.

Definition at line 1365 of file class.util.php.

1366 {
1367 global $bearsamppCore;
1368
1369 $url = APP_WEBSITE;
1370 if ( !empty( $path ) ) {
1371 $url .= '/' . ltrim( $path, '/' );
1372 }
1373 if ( $utmSource ) {
1374 $url = rtrim( $url, '/' ) . '/?utm_source=bearsampp-' . $bearsamppCore->getAppVersion();
1375 }
1376 if ( !empty( $fragment ) ) {
1377 $url .= $fragment;
1378 }
1379
1380 return $url;
1381 }
const APP_WEBSITE
Definition root.php:13

References $bearsamppCore, and APP_WEBSITE.

Referenced by getChangelogUrl(), TplAppApache\getMenuApache(), TplAppFilezilla\getMenuFilezilla(), TplAppMailhog\getMenuMailhog(), TplAppMailpit\getMenuMailpit(), TplAppMariadb\getMenuMariadb(), TplAppMemcached\getMenuMemcached(), TplAppMysql\getMenuMysql(), TplAppNodejs\getMenuNodejs(), TplAppPhp\getMenuPhp(), TplAppPostgresql\getMenuPostgresql(), TplAppXlight\getMenuXlight(), QuickPick\getQuickpickMenu(), TplApp\getSectionMenuRight(), getWebsiteUrlNoUtm(), and ActionAbout\processWindow().

+ Here is the caller graph for this function:

◆ getWebsiteUrlNoUtm()

static Util::getWebsiteUrlNoUtm ( $path = '',
$fragment = '' )
static

Constructs a website URL without UTM parameters.

Parameters
string$pathOptional path to append to the base URL.
string$fragmentOptional fragment to append to the URL.
Returns
string The constructed URL without UTM parameters.

Definition at line 1351 of file class.util.php.

1352 {
1353 return self::getWebsiteUrl( $path, $fragment, false );
1354 }

References getWebsiteUrl().

Referenced by ActionAbout\__construct().

+ Here is the caller graph for this function:

◆ humanFileSize()

static Util::humanFileSize ( $size,
$unit = '' )
static

Converts a file size in bytes to a human-readable format.

Parameters
int$sizeThe file size in bytes.
string$unitThe unit to convert to ('GB', 'MB', 'KB', or ''). If empty, auto-selects the unit.
Returns
string The formatted file size.

Definition at line 1423 of file class.util.php.

1424 {
1425 if ( (!$unit && $size >= 1 << 30) || $unit == 'GB' ) {
1426 return number_format( $size / (1 << 30), 2 ) . 'GB';
1427 }
1428 if ( (!$unit && $size >= 1 << 20) || $unit == 'MB' ) {
1429 return number_format( $size / (1 << 20), 2 ) . 'MB';
1430 }
1431 if ( (!$unit && $size >= 1 << 10) || $unit == 'KB' ) {
1432 return number_format( $size / (1 << 10), 2 ) . 'KB';
1433 }
1434
1435 return number_format( $size ) . ' bytes';
1436 }

Referenced by getRemoteFilesize().

+ Here is the caller graph for this function:

◆ imgToBase64()

static Util::imgToBase64 ( $path)
static

Converts an image file to a base64 encoded string.

Parameters
string$pathThe path to the image file.
Returns
string Returns the base64 encoded string of the image.

Definition at line 912 of file class.util.php.

913 {
914 $type = pathinfo( $path, PATHINFO_EXTENSION );
915 $data = file_get_contents( $path );
916
917 return 'data:image/' . $type . ';base64,' . base64_encode( $data );
918 }

◆ installService()

static Util::installService ( $bin,
$port,
$syntaxCheckCmd,
$showWindow = false )
static

Attempts to install and start a service on a specific port, with optional syntax checking and user notifications.

Parameters
object$binAn object containing the binary information and methods related to the service.
int$portThe port number on which the service should run.
string$syntaxCheckCmdThe command to execute for syntax checking of the service configuration.
bool$showWindowOptional. Whether to show message boxes for information, warnings, and errors. Defaults to false.
Returns
bool Returns true if the service is successfully installed and started, false otherwise.

Definition at line 1695 of file class.util.php.

1696 {
1697 global $bearsamppLang, $bearsamppWinbinder;
1698 $name = $bin->getName();
1699 $service = $bin->getService();
1700 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::INSTALL_SERVICE_TITLE ), $name );
1701
1702 $isPortInUse = self::isPortInUse( $port );
1703 if ( $isPortInUse === false ) {
1704 if ( !$service->isInstalled() ) {
1705 $service->create();
1706 if ( $service->start() ) {
1707 self::logInfo( sprintf( '%s service successfully installed. (name: %s ; port: %s)', $name, $service->getName(), $port ) );
1708 if ( $showWindow ) {
1709 $bearsamppWinbinder->messageBoxInfo(
1710 sprintf( $bearsamppLang->getValue( Lang::SERVICE_INSTALLED ), $name, $service->getName(), $port ),
1711 $boxTitle
1712 );
1713 }
1714
1715 return true;
1716 }
1717 else {
1718 $serviceError = sprintf( $bearsamppLang->getValue( Lang::SERVICE_INSTALL_ERROR ), $name );
1719 $serviceErrorLog = sprintf( 'Error during the installation of %s service', $name );
1720 if ( !empty( $syntaxCheckCmd ) ) {
1721 $cmdSyntaxCheck = $bin->getCmdLineOutput( $syntaxCheckCmd );
1722 if ( !$cmdSyntaxCheck['syntaxOk'] ) {
1723 $serviceError .= PHP_EOL . sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_SYNTAX_ERROR ), $cmdSyntaxCheck['content'] );
1724 $serviceErrorLog .= sprintf( ' (conf errors detected : %s)', $cmdSyntaxCheck['content'] );
1725 }
1726 }
1727 self::logError( $serviceErrorLog );
1728 if ( $showWindow ) {
1729 $bearsamppWinbinder->messageBoxError( $serviceError, $boxTitle );
1730 }
1731 }
1732 }
1733 else {
1734 self::logWarning( sprintf( '%s service already installed', $name ) );
1735 if ( $showWindow ) {
1736 $bearsamppWinbinder->messageBoxWarning(
1737 sprintf( $bearsamppLang->getValue( Lang::SERVICE_ALREADY_INSTALLED ), $name ),
1738 $boxTitle
1739 );
1740 }
1741
1742 return true;
1743 }
1744 }
1745 elseif ( $service->isRunning() ) {
1746 self::logWarning( sprintf( '%s service already installed and running', $name ) );
1747 if ( $showWindow ) {
1748 $bearsamppWinbinder->messageBoxWarning(
1749 sprintf( $bearsamppLang->getValue( Lang::SERVICE_ALREADY_INSTALLED ), $name ),
1750 $boxTitle
1751 );
1752 }
1753
1754 return true;
1755 }
1756 else {
1757 self::logError( sprintf( 'Port %s is used by an other application : %s', $name ) );
1758 if ( $showWindow ) {
1759 $bearsamppWinbinder->messageBoxError(
1760 sprintf( $bearsamppLang->getValue( Lang::PORT_NOT_USED_BY ), $port, $isPortInUse ),
1761 $boxTitle
1762 );
1763 }
1764 }
1765
1766 return false;
1767 }
global $bearsamppLang
const SERVICE_ALREADY_INSTALLED
const PORT_NOT_USED_BY
const SERVICE_INSTALL_ERROR
const STARTUP_SERVICE_SYNTAX_ERROR
const INSTALL_SERVICE_TITLE
const SERVICE_INSTALLED
static isPortInUse($port)
static logInfo($data, $file=null)

References $bearsamppLang, $port, Lang\INSTALL_SERVICE_TITLE, isPortInUse(), logError(), logInfo(), logWarning(), Lang\PORT_NOT_USED_BY, Lang\SERVICE_ALREADY_INSTALLED, Lang\SERVICE_INSTALL_ERROR, Lang\SERVICE_INSTALLED, and Lang\STARTUP_SERVICE_SYNTAX_ERROR.

Referenced by ActionService\install(), BinApache\setEnable(), BinFilezilla\setEnable(), BinMailhog\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().

+ Here is the caller graph for this function:

◆ is32BitsOs()

static Util::is32BitsOs ( )
static

Checks if the operating system is 32-bit.

Returns
bool True if the OS is 32-bit, false otherwise.

Definition at line 1443 of file class.util.php.

1444 {
1445 $processor = self::getProcessorRegKey();
1446
1447 return self::contains( $processor, 'x86' );
1448 }
static getProcessorRegKey()
static contains($string, $search)

References contains(), and getProcessorRegKey().

◆ isAlphanumeric()

static Util::isAlphanumeric ( $string)
static

Checks if a string is alphanumeric.

Parameters
string$stringThe string to check.
Returns
bool Returns true if the string is alphanumeric, false otherwise.

Definition at line 1680 of file class.util.php.

1681 {
1682 return ctype_alnum( $string );
1683 }

◆ isLaunchStartup()

static Util::isLaunchStartup ( )
static

Checks if the application is set to launch at startup.

Returns
bool True if the startup link exists, false otherwise.

Definition at line 645 of file class.util.php.

646 {
647 return file_exists( self::getStartupLnkPath() );
648 }

Referenced by ActionReload\__construct(), and TplAppLaunchStartup\process().

+ Here is the caller graph for this function:

◆ isPortInUse()

static Util::isPortInUse ( $port)
static

Checks if a specific port on localhost is in use and returns the process using it if available.

Parameters
int$portThe port number to check.
Returns
mixed Returns the process using the port if in use, 'N/A' if the port is open but no specific process can be identified, or false if the port is not in use.

Definition at line 1639 of file class.util.php.

1640 {
1641 // Declaring a variable to hold the IP
1642 // address getHostName() gets the name
1643 // of the local machine getHostByName()
1644 // gets the corresponding IP
1645 $localIP = getHostByName( getHostName() );
1646
1647 $connection = @fsockopen( $localIP, $port );
1648
1649 if ( is_resource( $connection ) ) {
1650 fclose( $connection );
1651 $process = Batch::getProcessUsingPort( $port );
1652
1653 return $process != null ? $process : 'N/A';
1654 }
1655
1656 return false;
1657 }
static getProcessUsingPort($port)

References $port, and Batch\getProcessUsingPort().

Referenced by BinApache\changePort(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), installService(), and ActionStartup\installServices().

+ Here is the caller graph for this function:

◆ isValidDomainName()

static Util::isValidDomainName ( $domainName)
static

Validates a domain name based on specific criteria.

Parameters
string$domainNameThe domain name to validate.
Returns
bool Returns true if the domain name is valid, false otherwise.

Definition at line 1666 of file class.util.php.

1667 {
1668 return preg_match( '/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*$/i', $domainName )
1669 && preg_match( '/^.{1,253}$/', $domainName )
1670 && preg_match( '/^[^\.]{1,63}(\.[^\.]{1,63})*$/', $domainName );
1671 }

Referenced by ActionAddVhost\processWindow(), and ActionEditVhost\processWindow().

+ Here is the caller graph for this function:

◆ isValidIp()

static Util::isValidIp ( $ip)
static

Validates an IP address.

Parameters
string$ipThe IP address to validate.
Returns
bool Returns true if the IP address is valid, otherwise false.

Definition at line 351 of file class.util.php.

352 {
353 return filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 )
354 || filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 );
355 }

◆ isValidPort()

static Util::isValidPort ( $port)
static

Validates a port number.

Parameters
int$portThe port number to validate.
Returns
bool Returns true if the port number is valid and within the range of 1 to 65535, otherwise false.

Definition at line 364 of file class.util.php.

365 {
366 return is_numeric( $port ) && ($port > 0 || $port <= 65535);
367 }

References $port.

Referenced by BinApache\changePort(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinApache\checkPort(), BinFilezilla\checkPort(), BinMailhog\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), and BinXlight\checkPort().

+ Here is the caller graph for this function:

◆ log()

static Util::log ( $data,
$type,
$file = null )
staticprivate

Logs a message to a specified file or default log file based on the log type.

Parameters
string$dataThe message to log.
string$typeThe type of log message: 'ERROR', 'WARNING', 'INFO', 'DEBUG', or 'TRACE'.
string | null$fileThe file path to write the log message to. If null, uses default log file based on type.

Definition at line 677 of file class.util.php.

678 {
680 $file = $file == null ? ($type == self::LOG_ERROR ? $bearsamppRoot->getErrorLogFilePath() : $bearsamppRoot->getLogFilePath()) : $file;
681 if ( !$bearsamppRoot->isRoot() ) {
682 $file = $bearsamppRoot->getHomepageLogFilePath();
683 }
684
685 $verbose = array();
686 $verbose[Config::VERBOSE_SIMPLE] = $type == self::LOG_ERROR || $type == self::LOG_WARNING;
687 $verbose[Config::VERBOSE_REPORT] = $verbose[Config::VERBOSE_SIMPLE] || $type == self::LOG_INFO;
688 $verbose[Config::VERBOSE_DEBUG] = $verbose[Config::VERBOSE_REPORT] || $type == self::LOG_DEBUG;
689 $verbose[Config::VERBOSE_TRACE] = $verbose[Config::VERBOSE_DEBUG] || $type == self::LOG_TRACE;
690
691 $writeLog = false;
692 if ( $bearsamppConfig->getLogsVerbose() == Config::VERBOSE_SIMPLE && $verbose[Config::VERBOSE_SIMPLE] ) {
693 $writeLog = true;
694 }
695 elseif ( $bearsamppConfig->getLogsVerbose() == Config::VERBOSE_REPORT && $verbose[Config::VERBOSE_REPORT] ) {
696 $writeLog = true;
697 }
698 elseif ( $bearsamppConfig->getLogsVerbose() == Config::VERBOSE_DEBUG && $verbose[Config::VERBOSE_DEBUG] ) {
699 $writeLog = true;
700 }
701 elseif ( $bearsamppConfig->getLogsVerbose() == Config::VERBOSE_TRACE && $verbose[Config::VERBOSE_TRACE] ) {
702 $writeLog = true;
703 }
704
705 if ( $writeLog ) {
706 file_put_contents(
707 $file,
708 '[' . date( 'Y-m-d H:i:s', time() ) . '] # ' . APP_TITLE . ' ' . $bearsamppCore->getAppVersion() . ' # ' . $type . ': ' . $data . PHP_EOL,
709 FILE_APPEND
710 );
711 }
712 }
const VERBOSE_REPORT
const VERBOSE_DEBUG
const VERBOSE_SIMPLE
const VERBOSE_TRACE
const LOG_INFO
const LOG_TRACE
const LOG_WARNING
const LOG_DEBUG
global $bearsamppConfig
Definition homepage.php:26

References $bearsamppConfig, $bearsamppCore, $bearsamppRoot, APP_TITLE, LOG_DEBUG, LOG_INFO, LOG_TRACE, LOG_WARNING, Config\VERBOSE_DEBUG, Config\VERBOSE_REPORT, Config\VERBOSE_SIMPLE, and Config\VERBOSE_TRACE.

Referenced by logDebug(), logError(), logInfo(), logTrace(), and logWarning().

+ Here is the caller graph for this function:

◆ logDebug()

static Util::logDebug ( $data,
$file = null )
static

Logs debug information. This function is a wrapper around the generic log function for debug-level messages.

Parameters
mixed$dataThe data to log.
string | null$fileOptional. The file path to log to. If not provided, a default path is used.

Definition at line 766 of file class.util.php.

767 {
768 self::log( $data, self::LOG_DEBUG, $file );
769 }
static log($data, $type, $file=null)

References log().

Referenced by Action\call(), BinApache\changePort(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), QuickPick\checkDownloadId(), BinApache\checkPort(), BinFilezilla\checkPort(), BinMailhog\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), BinXlight\checkPort(), decryptFile(), Symlinks\deleteCurrentSymlinks(), QuickPick\fetchAndUnzipModule(), getAppBinsRegKey(), getFilesToScan(), getHeaders(), getHttpHeaders(), getLatestVersion(), QuickPick\getModuleUrl(), QuickPick\getVersions(), QuickPick\installModule(), Vbs\killProc(), Action\process(), QuickPick\rebuildQuickpickJson(), BinApache\refreshAlias(), BinApache\refreshConf(), BinApache\refreshVhosts(), BinFilezilla\reload(), BinApache\setEnable(), BinFilezilla\setEnable(), BinMailhog\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinNodejs\setEnable(), BinPhp\setEnable(), BinPostgresql\setEnable(), BinXlight\setEnable(), Win32Service\start(), BinApache\switchVersion(), BinFilezilla\switchVersion(), BinMailhog\switchVersion(), BinMailpit\switchVersion(), BinMariadb\switchVersion(), BinMemcached\switchVersion(), BinMysql\switchVersion(), BinNodejs\switchVersion(), BinPhp\switchVersion(), BinPostgresql\switchVersion(), BinXlight\switchVersion(), Core\unzipFile(), AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), BinApache\updateConfig(), BinFilezilla\updateConfig(), BinMailhog\updateConfig(), BinMailpit\updateConfig(), BinMariadb\updateConfig(), BinMemcached\updateConfig(), BinMysql\updateConfig(), BinNodejs\updateConfig(), BinPhp\updateConfig(), BinPostgresql\updateConfig(), BinXlight\updateConfig(), Module\updateConfig(), ToolGit\updateConfig(), ActionStartup\writeLog(), Batch\writeLog(), Nssm\writeLog(), Registry\writeLog(), Vbs\writeLog(), Win32Service\writeLog(), and WinBinder\writeLog().

◆ logError()

static Util::logError ( $data,
$file = null )
static

Logs error messages. This function is a wrapper around the generic log function for error-level messages.

Parameters
mixed$dataThe data to log.
string | null$fileOptional. The file path to log to. If not provided, a default path is used.

Definition at line 802 of file class.util.php.

803 {
804 self::log( $data, self::LOG_ERROR, $file );
805 }

References log().

Referenced by BinApache\changePort(), BinFilezilla\changePort(), BinMailhog\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), QuickPick\checkDownloadId(), BinApache\checkPort(), BinFilezilla\checkPort(), BinMailhog\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), BinXlight\checkPort(), Vbs\createShortcut(), Module\createSymlink(), Symlinks\deleteCurrentSymlinks(), QuickPick\fetchAndUnzipModule(), getApiJson(), Core\getAppVersion(), Core\getFileFromUrl(), getLatestVersion(), QuickPick\getModuleUrl(), QuickPick\getQuickpickJson(), QuickPick\getVersions(), QuickPick\installModule(), installService(), ActionCheckVersion\processWindow(), AppAdminer\reload(), AppPhpmyadmin\reload(), AppPhppgadmin\reload(), AppWebgrind\reload(), BinApache\reload(), BinFilezilla\reload(), BinMailhog\reload(), BinMailpit\reload(), BinMariadb\reload(), BinMemcached\reload(), BinMysql\reload(), BinNodejs\reload(), BinPhp\reload(), BinPostgresql\reload(), BinXlight\reload(), ToolComposer\reload(), ToolConsoleZ\reload(), ToolGhostscript\reload(), ToolGit\reload(), ToolNgrok\reload(), ToolPerl\reload(), ToolPython\reload(), ToolRuby\reload(), ToolXdc\reload(), ToolYarn\reload(), removeService(), Win32Service\start(), startService(), Core\unzipFile(), AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), BinApache\updateConfig(), BinFilezilla\updateConfig(), BinMailhog\updateConfig(), BinMailpit\updateConfig(), BinMariadb\updateConfig(), BinMemcached\updateConfig(), BinMysql\updateConfig(), BinNodejs\updateConfig(), BinPhp\updateConfig(), BinPostgresql\updateConfig(), BinXlight\updateConfig(), and Nssm\writeLogError().

◆ logInfo()

static Util::logInfo ( $data,
$file = null )
static

Logs informational messages. This function is a wrapper around the generic log function for informational messages.

Parameters
mixed$dataThe data to log.
string | null$fileOptional. The file path to log to. If not provided, a default path is used.

Definition at line 778 of file class.util.php.

779 {
780 self::log( $data, self::LOG_INFO, $file );
781 }

References log().

Referenced by Batch\exitApp(), installService(), AppAdminer\reload(), AppPhpmyadmin\reload(), AppPhppgadmin\reload(), AppWebgrind\reload(), BinApache\reload(), BinFilezilla\reload(), BinMailhog\reload(), BinMailpit\reload(), BinMariadb\reload(), BinMemcached\reload(), BinMysql\reload(), BinNodejs\reload(), BinPhp\reload(), BinPostgresql\reload(), Bins\reload(), BinXlight\reload(), ToolComposer\reload(), ToolConsoleZ\reload(), ToolGhostscript\reload(), ToolGit\reload(), ToolNgrok\reload(), ToolPerl\reload(), ToolPython\reload(), ToolRuby\reload(), ToolXdc\reload(), ToolYarn\reload(), removeService(), BinApache\setEnable(), BinFilezilla\setEnable(), BinMailhog\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinNodejs\setEnable(), BinPhp\setEnable(), BinPostgresql\setEnable(), BinXlight\setEnable(), Win32Service\start(), Apps\update(), Bins\update(), Tools\update(), and Nssm\writeLogInfo().

+ Here is the caller graph for this function:

◆ logInitClass()

◆ logReloadClass()

static Util::logReloadClass ( $classInstance)
static

Logs the reloading of a class instance.

Parameters
object$classInstanceThe instance of the class to log.

Definition at line 822 of file class.util.php.

823 {
824 self::logTrace( 'Reload ' . get_class( $classInstance ) );
825 }

References logTrace().

Referenced by AppAdminer\reload(), AppPhpmyadmin\reload(), AppPhppgadmin\reload(), AppWebgrind\reload(), BinApache\reload(), BinFilezilla\reload(), BinMailhog\reload(), BinMailpit\reload(), BinMariadb\reload(), BinMemcached\reload(), BinMysql\reload(), BinNodejs\reload(), BinPhp\reload(), BinPostgresql\reload(), BinXlight\reload(), ToolComposer\reload(), ToolConsoleZ\reload(), ToolGhostscript\reload(), ToolGit\reload(), ToolNgrok\reload(), ToolPerl\reload(), ToolPython\reload(), ToolRuby\reload(), ToolXdc\reload(), and ToolYarn\reload().

+ Here is the caller graph for this function:

◆ logSeparator()

static Util::logSeparator ( )
static

Appends a separator line to multiple log files if they do not already end with it. This function ensures that each log file ends with a clear separator for better readability.

@global object $bearsamppRoot An object that provides paths to various log files.

Definition at line 720 of file class.util.php.

721 {
722 global $bearsamppRoot;
723
724 $logs = array(
725 $bearsamppRoot->getLogFilePath(),
726 $bearsamppRoot->getErrorLogFilePath(),
727 $bearsamppRoot->getServicesLogFilePath(),
728 $bearsamppRoot->getRegistryLogFilePath(),
729 $bearsamppRoot->getStartupLogFilePath(),
730 $bearsamppRoot->getBatchLogFilePath(),
731 $bearsamppRoot->getVbsLogFilePath(),
732 $bearsamppRoot->getWinbinderLogFilePath(),
733 );
734
735 $separator = '========================================================================================' . PHP_EOL;
736 foreach ( $logs as $log ) {
737 if ( !file_exists( $log ) ) {
738 continue; // Skip to the next iteration if the file does not exist
739 }
740 $logContent = @file_get_contents( $log );
741 if ( $logContent !== false && !self::endWith( $logContent, $separator ) ) {
742 file_put_contents( $log, $separator, FILE_APPEND );
743 }
744 }
745 }

References $bearsamppRoot.

Referenced by Root\register().

+ Here is the caller graph for this function:

◆ logTrace()

static Util::logTrace ( $data,
$file = null )
static

Logs trace information. This function is a wrapper around the generic log function for trace-level messages.

Parameters
mixed$dataThe data to log.
string | null$fileOptional. The file path to log to. If not provided, a default path is used.

Definition at line 754 of file class.util.php.

755 {
756 self::log( $data, self::LOG_TRACE, $file );
757 }

References log().

Referenced by getCurlHttpHeaders(), logInitClass(), logReloadClass(), BinApache\refreshAlias(), BinApache\refreshConf(), BinApache\refreshVhosts(), Config\replaceAll(), replaceInFile(), and Core\unzipFile().

+ Here is the caller graph for this function:

◆ logWarning()

static Util::logWarning ( $data,
$file = null )
static

Logs warning messages. This function is a wrapper around the generic log function for warning-level messages.

Parameters
mixed$dataThe data to log.
string | null$fileOptional. The file path to log to. If not provided, a default path is used.

Definition at line 790 of file class.util.php.

791 {
792 self::log( $data, self::LOG_WARNING, $file );
793 }

References log().

Referenced by getNssmEnvPaths(), Batch\initializeMysql(), Batch\initializePostgresql(), installService(), ToolGit\reload(), and removeService().

+ Here is the caller graph for this function:

◆ openFileContent()

static Util::openFileContent ( $caption,
$content )
static

Opens a file with a given caption and content in the default text editor. The file is created in a temporary directory with a unique name.

Parameters
string$captionThe filename to use when saving the content.
string$contentThe content to write to the file.

@global object $bearsamppRoot Global object to access temporary path. @global object $bearsamppConfig Global configuration object. @global object $bearsamppWinbinder Global object to execute external programs.

Definition at line 1956 of file class.util.php.

1957 {
1958 global $bearsamppRoot, $bearsamppConfig, $bearsamppWinbinder;
1959
1960 $folderPath = $bearsamppRoot->getTmpPath() . '/openFileContent-' . self::random();
1961 if ( !is_dir( $folderPath ) ) {
1962 mkdir( $folderPath, 0777, true );
1963 }
1964
1965 $filepath = self::formatWindowsPath( $folderPath . '/' . $caption );
1966 file_put_contents( $filepath, $content );
1967
1968 $bearsamppWinbinder->exec( $bearsamppConfig->getNotepad(), '"' . $filepath . '"' );
1969 }
static random($length=32, $withNumeric=true)

References $bearsamppConfig, $bearsamppRoot, formatWindowsPath(), and random().

Referenced by ActionDebugApache\__construct(), ActionDebugMariadb\__construct(), ActionDebugMysql\__construct(), and ActionDebugPostgresql\__construct().

+ Here is the caller graph for this function:

◆ random()

static Util::random ( $length = 32,
$withNumeric = true )
static

Generates a random string of specified length and character set.

Parameters
int$lengthThe length of the random string to generate.
bool$withNumericWhether to include numeric characters in the random string.
Returns
string Returns the generated random string.

Definition at line 200 of file class.util.php.

201 {
202 $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
203 if ( $withNumeric ) {
204 $characters .= '0123456789';
205 }
206
207 $randomString = '';
208 for ( $i = 0; $i < $length; $i++ ) {
209 $randomString .= $characters[rand( 0, strlen( $characters ) - 1 )];
210 }
211
212 return $randomString;
213 }

Referenced by OpenSsl\createCrt(), Batch\getTmpFile(), and openFileContent().

+ Here is the caller graph for this function:

◆ removeService()

static Util::removeService ( $service,
$name )
static

Removes a service if it is installed.

Parameters
Win32Service$serviceThe service object to be removed.
string$nameThe name of the service.
Returns
bool Returns true if the service is successfully removed, false otherwise.

Definition at line 1777 of file class.util.php.

1778 {
1779 if ( !($service instanceof Win32Service) ) {
1780 self::logError( '$service not an instance of Win32Service' );
1781
1782 return false;
1783 }
1784
1785 if ( $service->isInstalled() ) {
1786 if ( $service->delete() ) {
1787 self::logInfo( sprintf( '%s service successfully removed', $name ) );
1788
1789 return true;
1790 }
1791 else {
1792 self::logError( sprintf( 'Error during the uninstallation of %s service', $name ) );
1793
1794 return false;
1795 }
1796 }
1797 else {
1798 self::logWarning( sprintf( '%s service does not exist', $name ) );
1799 }
1800
1801 return true;
1802 }

References logError(), logInfo(), and logWarning().

Referenced by ActionService\remove(), BinApache\setEnable(), BinFilezilla\setEnable(), BinMailhog\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().

+ Here is the caller graph for this function:

◆ replaceDefine()

static Util::replaceDefine ( $path,
$var,
$value )
static

Replaces a defined constant in a file with a new value.

Parameters
string$pathThe file path where the constant is defined.
string$varThe name of the constant.
mixed$valueThe new value for the constant.

Definition at line 376 of file class.util.php.

377 {
378 self::replaceInFile( $path, array(
379 '/^define\‍((.*?)' . $var . '(.*?),/' => 'define(\'' . $var . '\', ' . (is_int( $value ) ? $value : '\'' . $value . '\'') . ');'
380 ) );
381 }
static replaceInFile($path, $replaceList)

References replaceInFile().

◆ replaceInFile()

static Util::replaceInFile ( $path,
$replaceList )
static

Performs replacements in a file based on a list of regular expression patterns.

Parameters
string$pathThe path to the file where replacements are to be made.
array$replaceListAn associative array where keys are regex patterns and values are replacement strings.

Definition at line 389 of file class.util.php.

390 {
391 if ( file_exists( $path ) ) {
392 $lines = file( $path );
393 $fp = fopen( $path, 'w' );
394 foreach ( $lines as $nb => $line ) {
395 $replaceDone = false;
396 foreach ( $replaceList as $regex => $replace ) {
397 if ( preg_match( $regex, $line, $matches ) ) {
398 $countParams = preg_match_all( '/{{(\d+)}}/', $replace, $paramsMatches );
399 if ( $countParams > 0 && $countParams <= count( $matches ) ) {
400 foreach ( $paramsMatches[1] as $paramsMatch ) {
401 $replace = str_replace( '{{' . $paramsMatch . '}}', $matches[$paramsMatch], $replace );
402 }
403 }
404 self::logTrace( 'Replace in file ' . $path . ' :' );
405 self::logTrace( '## line_num: ' . trim( $nb ) );
406 self::logTrace( '## old: ' . trim( $line ) );
407 self::logTrace( '## new: ' . trim( $replace ) );
408 fwrite( $fp, $replace . PHP_EOL );
409
410 $replaceDone = true;
411 break;
412 }
413 }
414 if ( !$replaceDone ) {
415 fwrite( $fp, $line );
416 }
417 }
418 fclose( $fp );
419 }
420 }

References logTrace().

Referenced by BinPostgresql\rebuildConf(), Homepage\refreshCommonsJsContent(), replaceDefine(), ToolGit\setScanStartup(), AppAdminer\updateConfig(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), AppWebgrind\updateConfig(), BinApache\updateConfig(), BinMariadb\updateConfig(), BinMysql\updateConfig(), BinPhp\updateConfig(), and BinPostgresql\updateConfig().

+ Here is the caller graph for this function:

◆ setAppBinsRegKey()

static Util::setAppBinsRegKey ( $value)
static

Retrieves or generates the application binaries registry key.

Parameters
bool$fromRegistryDetermines whether to retrieve the key from the registry or generate it.
Returns
string Returns the application binaries registry key.

Definition at line 532 of file class.util.php.

533 {
534 global $bearsamppRegistry;
535
536 return $bearsamppRegistry->setStringValue(
540 $value
541 );
542 }

References Registry\APP_BINS_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkBinsRegKey(), and ActionSwitchVersion\processWindow().

+ Here is the caller graph for this function:

◆ setAppPathRegKey()

static Util::setAppPathRegKey ( $value)
static

Sets the application path in the registry.

Parameters
string$valueThe new value for the application path.
Returns
bool True on success, false on failure.

Definition at line 567 of file class.util.php.

568 {
569 global $bearsamppRegistry;
570
571 return $bearsamppRegistry->setStringValue(
575 $value
576 );
577 }

References Registry\APP_PATH_REG_ENTRY, Registry\ENV_KEY, and Registry\HKEY_LOCAL_MACHINE.

Referenced by ActionStartup\checkPathRegKey().

+ Here is the caller graph for this function:

◆ setSysPathRegKey()

static Util::setSysPathRegKey ( $value)
static

Sets the system path in the registry.

Parameters
string$valueThe new value for the system path.
Returns
bool True on success, false on failure.

Definition at line 602 of file class.util.php.

603 {
604 global $bearsamppRegistry;
605
606 return $bearsamppRegistry->setExpandStringValue(
610 $value
611 );
612 }

References Registry\ENV_KEY, Registry\HKEY_LOCAL_MACHINE, and Registry\SYSPATH_REG_ENTRY.

Referenced by ActionStartup\checkSystemPathRegKey().

+ Here is the caller graph for this function:

◆ setupCurlHeaderWithToken()

static Util::setupCurlHeaderWithToken ( )
static

Sets up a cURL header array using a decrypted GitHub Personal Access Token.

Returns
array The header array for cURL with authorization and other necessary details.

Definition at line 2035 of file class.util.php.

2036 {
2037
2038 // Usage
2040 $Token = self::decryptFile();
2041
2042 return [
2043 'Accept: application/vnd.github+json',
2044 'Authorization: Token ' . $Token,
2045 'User-Agent: ' . APP_GITHUB_USERAGENT,
2046 'X-GitHub-Api-Version: 2022-11-28'
2047 ];
2048 }
static decryptFile()
const APP_GITHUB_USERAGENT
Definition root.php:17

References $bearsamppConfig, $bearsamppCore, APP_GITHUB_USERAGENT, and decryptFile().

Referenced by getApiJson().

+ Here is the caller graph for this function:

◆ startLoading()

static Util::startLoading ( )
static

Initiates a loading process using external components.

Definition at line 947 of file class.util.php.

948 {
949 global $bearsamppCore, $bearsamppWinbinder;
950 $bearsamppWinbinder->exec( $bearsamppCore->getPhpExe(), Core::isRoot_FILE . ' ' . Action::LOADING );
951 }
const LOADING
const isRoot_FILE

References $bearsamppCore, Core\isRoot_FILE, and Action\LOADING.

Referenced by ActionCheckVersion\__construct(), ActionEnable\__construct(), ActionLaunchStartup\__construct(), ActionManualRestart\__construct(), ActionRefreshRepos\__construct(), ActionReload\__construct(), ActionService\__construct(), ActionSwitchOnline\__construct(), and ActionStartup\processWindow().

+ Here is the caller graph for this function:

◆ startService()

static Util::startService ( $bin,
$syntaxCheckCmd,
$showWindow = false )
static

Attempts to start a service and performs a syntax check if required.

Parameters
object$binAn object containing service details.
string$syntaxCheckCmdCommand to check syntax errors.
bool$showWindowWhether to show error messages in a window.
Returns
bool Returns true if the service starts successfully, false otherwise.

Definition at line 1813 of file class.util.php.

1814 {
1815 global $bearsamppLang, $bearsamppWinbinder;
1816 $name = $bin->getName();
1817 $service = $bin->getService();
1818 $boxTitle = sprintf( $bearsamppLang->getValue( Lang::START_SERVICE_TITLE ), $name );
1819
1820 if ( !$service->start() ) {
1821 $serviceError = sprintf( $bearsamppLang->getValue( Lang::START_SERVICE_ERROR ), $name );
1822 $serviceErrorLog = sprintf( 'Error while starting the %s service', $name );
1823 if ( !empty( $syntaxCheckCmd ) ) {
1824 $cmdSyntaxCheck = $bin->getCmdLineOutput( $syntaxCheckCmd );
1825 if ( !$cmdSyntaxCheck['syntaxOk'] ) {
1826 $serviceError .= PHP_EOL . sprintf( $bearsamppLang->getValue( Lang::STARTUP_SERVICE_SYNTAX_ERROR ), $cmdSyntaxCheck['content'] );
1827 $serviceErrorLog .= sprintf( ' (conf errors detected : %s)', $cmdSyntaxCheck['content'] );
1828 }
1829 }
1830 self::logError( $serviceErrorLog );
1831 if ( $showWindow ) {
1832 $bearsamppWinbinder->messageBoxError( $serviceError, $boxTitle );
1833 }
1834
1835 return false;
1836 }
1837
1838 return true;
1839 }
const START_SERVICE_TITLE
const START_SERVICE_ERROR

References $bearsamppLang, logError(), Lang\START_SERVICE_ERROR, Lang\START_SERVICE_TITLE, and Lang\STARTUP_SERVICE_SYNTAX_ERROR.

Referenced by BinPhp\setEnable(), and ActionService\start().

+ Here is the caller graph for this function:

◆ startWith()

static Util::startWith ( $string,
$search )
static

Checks if a string starts with a specified substring.

Parameters
string$stringThe string to check.
string$searchThe substring to look for at the start of the string.
Returns
bool Returns true if the string starts with the search substring, otherwise false.

Definition at line 166 of file class.util.php.

167 {
168 $length = strlen( $search );
169
170 return (substr( $string, 0, $length ) === $search);
171 }

Referenced by BinApache\checkPort(), BinMariadb\checkPort(), BinMysql\checkPort(), BinApache\getModulesFromConf(), BinApache\getModulesFromFolder(), BinApache\getOfflineContent(), BinApache\getOnlineContent(), Batch\getOsInfo(), Batch\getPearVersion(), Batch\getProcessUsingPort(), Registry\getValue(), BinApache\getVhostsUrl(), Win32Ps\killBins(), Autoloader\load(), and Registry\setValue().

+ Here is the caller graph for this function:

◆ stopLoading()

static Util::stopLoading ( )
static

Stops a previously started loading process and cleans up related resources.

Definition at line 956 of file class.util.php.

957 {
958 global $bearsamppCore;
959 if ( file_exists( $bearsamppCore->getLoadingPid() ) ) {
960 $pids = file( $bearsamppCore->getLoadingPid() );
961 foreach ( $pids as $pid ) {
962 Win32Ps::kill( $pid );
963 }
964 @unlink( $bearsamppCore->getLoadingPid() );
965 }
966 }
static kill($pid)

References $bearsamppCore, and Win32Ps\kill().

Referenced by ActionManualRestart\__construct(), ActionService\__construct(), ActionCheckVersion\showVersionOkMessageBox(), and ActionCheckVersion\showVersionUpdateWindow().

+ Here is the caller graph for this function:

◆ utf8ToCp1252()

static Util::utf8ToCp1252 ( $data)
static

Converts UTF-8 encoded data to Windows-1252 encoding.

Parameters
string$dataThe UTF-8 encoded data.
Returns
string Returns the data encoded in Windows-1252.

Definition at line 927 of file class.util.php.

928 {
929 return iconv( "UTF-8", "WINDOWS-1252//IGNORE", $data );
930 }

Referenced by ActionReload\__construct().

+ Here is the caller graph for this function:

Field Documentation

◆ LOG_DEBUG

const Util::LOG_DEBUG = 'DEBUG'

Definition at line 41 of file class.util.php.

Referenced by log().

◆ LOG_ERROR

const Util::LOG_ERROR = 'ERROR'

This code snippet defines constants for logging levels.

Definition at line 38 of file class.util.php.

◆ LOG_INFO

const Util::LOG_INFO = 'INFO'

Definition at line 40 of file class.util.php.

Referenced by log().

◆ LOG_TRACE

const Util::LOG_TRACE = 'TRACE'

Definition at line 42 of file class.util.php.

Referenced by log().

◆ LOG_WARNING

const Util::LOG_WARNING = 'WARNING'

Definition at line 39 of file class.util.php.

Referenced by log().


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