![]() |
Bearsampp 2026.9.23
|
Static Public Member Functions | |
| static | clearFolder ($path, $exclude=array()) |
| static | clearFolders ($paths, $exclude=array()) |
| static | clearLoadingText () |
| static | convertEncoding ($data, $direction='to_cp1252') |
| static | cp1252ToUtf8 ($data) |
| static | deleteFolder ($path) |
| static | disableLaunchStartup () |
| static | enableLaunchStartup () |
| static | findFile ($startPath, $findFile) |
| static | findRepos ($initPath, $startPath, $checkFile, $maxDepth=1) |
| static | getFilesToScan ($path=null, $useCache=true, $forceRefresh=false) |
| static | getFolderList ($path) |
| static | getLatestVersion ($url) |
| static | getMicrotime () |
| static | getVersionList ($path) |
| static | humanFileSize (int $size, string $unit='') |
| static | imgToBase64 ($path) |
| static | is32BitsOs () |
| static | isAdmin () |
| static | isLaunchStartup () |
| static | isValidDomainName ($domainName) |
| static | isValidIp ($ip) |
| static | isValidPort ($port) |
| static | openFileContent ($caption, $content) |
| static | replaceDefine ($path, $var, $value) |
| static | replaceInFile ($path, $replaceList) |
| static | startLoading () |
| static | stopLoading () |
| static | updateLoadingText ($text) |
| static | utf8ToCp1252 ($data) |
Static Private Member Functions | |
| static | findFiles ($startPath, $includes=array(''), $recursive=true) |
| static | getPathsToScan () |
Utility class providing a wide range of static methods for various purposes including:
Path formatting (formatWindowsPath / formatUnixPath) has been moved to Path.
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:
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 34 of file class.util.php.
|
static |
Recursively clears all files and directories within a specified directory, excluding specified items.
| string | $path | The path of the directory to clear. |
| array | $exclude | An array of filenames to exclude from deletion. |
Definition at line 63 of file class.util.php.
References $result, and clearFolder().
Referenced by ActionClearFolders\__construct(), ActionStartup\cleanTmpFolders(), clearFolder(), and clearFolders().
|
static |
Clears multiple directories by delegating each one to clearFolder.
| array | $paths | The paths of the directories to clear. |
| array | $exclude | An array of filenames to exclude from deletion. |
Definition at line 45 of file class.util.php.
References $result, and clearFolder().
|
static |
Clears the loading status file
Definition at line 598 of file class.util.php.
References $bearsamppCore, and Path\getTmpPath().
Referenced by stopLoading().
|
static |
Converts data between UTF-8 and Windows-1252 encodings.
| string | $data | The data to convert. |
| string | $direction | The conversion direction: 'to_cp1252' or 'to_utf8'. Defaults to 'to_cp1252'. |
Definition at line 502 of file class.util.php.
References cp1252ToUtf8(), and utf8ToCp1252().
|
static |
Converts Windows-1252 encoded data to UTF-8 encoding.
| string | $data | The Windows-1252 encoded data. |
Definition at line 530 of file class.util.php.
Referenced by convertEncoding().
|
static |
Recursively deletes a directory and all its contents.
| string | $path | The path of the directory to delete. |
Definition at line 109 of file class.util.php.
References deleteFolder(), and Log\error().
Referenced by ActionQuit\cleanupTemporaryFiles(), deleteFolder(), and ActionStartup\rotationLogs().
|
static |
Disables launching the application at startup by removing the shortcut from the startup folder.
Definition at line 426 of file class.util.php.
References Path\getStartupLnkPath().
Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().
|
static |
Enables launching the application at startup by creating a shortcut in the startup folder.
Definition at line 404 of file class.util.php.
References $bearsamppCore, $bearsamppRoot, APP_TITLE, Win32Native\createShortcut(), Path\getExeFilePath(), Path\getIconsPath(), Path\getRootPath(), and Path\getStartupLnkPath().
Referenced by ActionLaunchStartup\__construct(), and ActionStartup\checkLaunchStartup().
|
static |
Recursively searches for a file starting from a specified directory.
| string | $startPath | The directory path to start the search. |
| string | $findFile | The filename to search for. |
Definition at line 154 of file class.util.php.
References $result, findFile(), and Path\formatUnixPath().
Referenced by findFile(), and Path\getPowerShellPath().
|
staticprivate |
Recursively finds files in a directory that match a set of inclusion patterns.
| string | $startPath | The directory path to start the search from. |
| array | $includes | An array of file patterns to include in the search. Patterns starting with '!' are excluded. |
| bool | $recursive | Determines whether the search should be recursive. |
Definition at line 851 of file class.util.php.
References $result, UtilString\endWith(), findFiles(), Path\formatUnixPath(), and UtilString\startWith().
Referenced by findFiles(), and getFilesToScan().
|
static |
Recursively searches for repositories starting from a given path up to a specified depth.
| string | $initPath | The initial path from where the search begins. |
| string | $startPath | The current path from where to search. |
| string | $checkFile | The file name to check for in the directory to consider it a repository. |
| int | $maxDepth | The maximum depth of directories to search into. |
Definition at line 450 of file class.util.php.
References $result, findRepos(), and Path\formatUnixPath().
Referenced by ToolGit\findRepos(), and findRepos().
|
static |
Retrieves a list of files to scan from specified paths or default paths. Implements caching to avoid repeated expensive file system scans.
| string | null | $path | Optional. The path to start scanning from. If null, uses default paths. |
| bool | $useCache | Whether to use cached results (default: true). |
| bool | $forceRefresh | Force refresh the cache even if valid (default: false). |
Definition at line 618 of file class.util.php.
References $result, Log\debug(), findFiles(), Cache\get(), getMicrotime(), getPathsToScan(), Log\info(), Cache\recordHit(), Cache\recordMiss(), and Cache\set().
Referenced by ActionReload\__construct(), BinPostgresql\initData(), ActionSwitchVersion\processWindow(), and ActionStartup\scanFolders().
|
static |
Gets the list of folders in the specified path.
| string | $path | The directory path to scan for folders. |
Definition at line 998 of file class.util.php.
References $result.
Referenced by ActionReload\__construct(), ActionSwitchVersion\__construct(), and getPathsToScan().
|
static |
Fetches the latest version information from a given url.
| string | $url | The URL to fetch version information from. |
Definition at line 898 of file class.util.php.
References $result, Log\error(), HttpClient\getApiJson(), and Log\trace().
Referenced by ActionCheckVersion\__construct(), and ActionCheckVersion\processWindow().
|
static |
Gets the current Unix timestamp with microseconds.
Definition at line 379 of file class.util.php.
Referenced by ActionStartup\__construct(), getFilesToScan(), ActionStartup\installServicesSequential(), ActionStartup\prepareService(), ActionStartup\processWindow(), and ActionStartup\scanFolders().
|
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, Composer, PowerShell, Python and Ruby. 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:
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.
Definition at line 687 of file class.util.php.
References $bearsamppBins, $bearsamppCore, $bearsamppRoot, Path\getAliasPath(), getFolderList(), Path\getModuleRootPath(), Path\getOpenSslPath(), Path\getResourcesPath(), and Path\getVhostsPath().
Referenced by getFilesToScan().
|
static |
Gets the list of version directories in the specified path. Returns version suffixes by stripping the common prefix (basename of path) if present.
| string | $path | The directory path to scan for version directories. |
Definition at line 345 of file class.util.php.
References $result.
Referenced by Module\getVersionList().
|
static |
Converts a file size in bytes to a human-readable format.
Uses PHP's native human_readable_size() when available. Falls back to manual conversion when a specific unit is requested or when the native function is unavailable.
| int | $size | The file size in bytes. |
| string | $unit | Optional forced unit ('GB', 'MB', 'KB', or ''). |
Definition at line 941 of file class.util.php.
|
static |
Converts an image file to a base64 encoded string.
| string | $path | The path to the image file. |
Definition at line 486 of file class.util.php.
|
static |
Checks if the operating system is 32-bit.
Definition at line 971 of file class.util.php.
References UtilString\contains().
|
static |
Checks if the current process is running with administrator/elevated privileges. This is essential for operations that require admin rights, such as installing Windows services.
Definition at line 214 of file class.util.php.
References $result, and CommandRunner\shellExec().
|
static |
Checks if the application is set to launch at startup.
Definition at line 392 of file class.util.php.
References Path\getStartupLnkPath().
Referenced by ActionReload\__construct(), and TplAppLaunchStartup\process().
|
static |
Validates a domain name based on specific criteria.
| string | $domainName | The domain name to validate. |
Definition at line 986 of file class.util.php.
Referenced by ActionAddVhost\validateInput(), and ActionEditVhost\validateInput().
|
static |
Validates an IP address.
| string | $ip | The IP address to validate. |
Definition at line 190 of file class.util.php.
|
static |
Validates a port number.
| int | $port | The port number to validate. |
Definition at line 203 of file class.util.php.
References $port.
Referenced by BinApache\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinApache\checkPort(), BinMailpit\checkPort(), BinMariadb\checkPort(), BinMemcached\checkPort(), BinMysql\checkPort(), BinPostgresql\checkPort(), and BinXlight\checkPort().
|
static |
Opens the given content in a temporary file using the editor configured in bearsampp.conf.
| string | $caption | The caption/title for the temporary file. |
| string | $content | The content to write to the temporary file. |
Definition at line 1029 of file class.util.php.
References $bearsamppConfig, Path\findExecutable(), and Path\getTmpPath().
Referenced by ActionDebugBase\__construct().
|
static |
Replaces a defined constant in a file with a new value.
| string | $path | The file path where the constant is defined. |
| string | $var | The name of the constant. |
| mixed | $value | The new value for the constant. |
Definition at line 285 of file class.util.php.
References replaceInFile().
|
static |
Performs replacements in a file based on a list of regular expression patterns.
| string | $path | The path to the file where replacements are to be made. |
| array | $replaceList | An associative array where keys are regex patterns and values are replacement strings. |
Definition at line 300 of file class.util.php.
References Log\trace().
Referenced by BinPostgresql\rebuildConf(), replaceDefine(), ToolGit\setScanStartup(), AppPhpmyadmin\updateConfig(), AppPhppgadmin\updateConfig(), BinApache\updateConfig(), BinMariadb\updateConfig(), BinMysql\updateConfig(), BinPhp\updateConfig(), and BinPostgresql\updateConfig().
|
static |
Initiates a loading process using external components.
Definition at line 540 of file class.util.php.
References $bearsamppCore, $result, Path\getPhpExe(), Core\isRoot_FILE, Action\LOADING, and Log\trace().
Referenced by ActionCheckVersion\__construct(), ActionEnable\__construct(), ActionLaunchStartup\__construct(), ActionManualRestart\__construct(), ActionRefreshRepos\__construct(), ActionReload\__construct(), ActionService\__construct(), ActionSwitchOnline\__construct(), and ActionStartup\processWindow().
|
static |
Stops a previously started loading process and cleans up related resources.
Definition at line 562 of file class.util.php.
References $bearsamppCore, clearLoadingText(), and Win32Ps\kill().
Referenced by ActionCheckVersion\__construct(), ActionEnable\__construct(), ActionLaunchStartup\__construct(), ActionManualRestart\__construct(), ActionRefreshRepos\__construct(), ActionReload\__construct(), ActionService\__construct(), ActionSwitchOnline\__construct(), ActionCheckVersion\showVersionOkMessageBox(), and ActionCheckVersion\showVersionUpdateWindow().
|
static |
Updates the loading screen text (if loading screen is active) This allows dynamic updates to show which service is being processed
| string | $text | The text to display on the loading screen |
Definition at line 585 of file class.util.php.
References $bearsamppCore, and Path\getTmpPath().
Referenced by ActionChangePort\processWindow(), ActionService\restart(), ActionService\start(), and ActionService\stop().
|
static |
Converts UTF-8 encoded data to Windows-1252 encoding.
| string | $data | The UTF-8 encoded data. |
Definition at line 518 of file class.util.php.
Referenced by ActionReload\__construct(), convertEncoding(), and ActionChangePort\processWindow().