![]() |
Bearsampp 2026.7.11
|
Static Public Member Functions | |
| static | checkInternetState () |
| 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 | getApiJson ($url) |
| static | getCurlHttpHeaders ($url) |
| static | getFilesToScan ($path=null, $useCache=true, $forceRefresh=false) |
| static | getFolderList ($path) |
| static | getFopenHttpHeaders ($url) |
| static | getGithubUrl ($type='user', $user=APP_GITHUB_USER, $repo=null, $branch=null, $path=null) |
| static | getGithubUserUrl () |
| static | getHeaders ($host, $port, $ssl=false) |
| static | getHttpHeaders ($pingUrl) |
| static | getLatestVersion ($url) |
| static | getMicrotime () |
| static | getRemoteFilesize ($url, $humanFileSize=true) |
| static | getVersionList ($path) |
| static | getWebsiteUrl ($path='', $fragment='', $utmSource=true) |
| static | getWebsiteUrlNoUtm ($path='', $fragment='') |
| static | humanFileSize (int $size, string $unit='') |
| static | imgToBase64 ($path) |
| static | installService ($bin, $port, $syntaxCheckCmd, $showWindow=false) |
| static | is32BitsOs () |
| static | isAdmin () |
| static | isLaunchStartup () |
| static | isPortInUse ($port) |
| static | isValidDomainName ($domainName) |
| static | isValidIp ($ip) |
| static | isValidPort ($port) |
| static | openFileContent ($caption, $content) |
| static | removeService ($service, $name) |
| static | replaceDefine ($path, $var, $value) |
| static | replaceInFile ($path, $replaceList) |
| static | setupCurlHeaderWithToken () |
| static | startLoading () |
| static | startService ($bin, $syntaxCheckCmd, $showWindow=false) |
| 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 35 of file class.util.php.
|
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.
Definition at line 1463 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 64 of file class.util.php.
References $result, and clearFolder().
Referenced by ActionClearFolders\__construct(), ActionStartup\cleanTmpFolders(), clearFolder(), and clearFolders().
|
static |
Recursively deletes files from a specified directory while excluding certain files.
| string | $path | The path to the directory to clear. |
| array | $exclude | An array of filenames to exclude from deletion. |
Definition at line 46 of file class.util.php.
References $result, and clearFolder().
|
static |
Clears the loading status file
Definition at line 582 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 494 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 522 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 108 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 418 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 396 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 152 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 835 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 442 of file class.util.php.
References $result, findRepos(), and Path\formatUnixPath().
Referenced by ToolGit\findRepos(), and findRepos().
|
static |
Sends a GET request to the specified URL and returns the response.
| string | $url | The URL to send the GET request to. |
Definition at line 1168 of file class.util.php.
References Log\error(), and setupCurlHeaderWithToken().
Referenced by getLatestVersion().
|
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.
| string | $url | The URL from which to fetch the headers. |
Definition at line 1086 of file class.util.php.
References $response, $result, and Log\trace().
Referenced by getHttpHeaders().
|
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 602 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 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 1482 of file class.util.php.
References $result.
Referenced by ActionSwitchVersion\__construct(), and getPathsToScan().
|
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.
| string | $url | The URL from which to fetch the headers. |
Definition at line 1053 of file class.util.php.
References $result.
Referenced by getHttpHeaders().
|
static |
Generates various GitHub URLs based on the specified type.
| string | $type | The type of URL ('user', 'repo', 'raw'). Defaults to 'user'. |
| string | $user | The GitHub username. Defaults to 'Bearsampp'. |
| string | null | $repo | The repository name (required for 'repo' and 'raw' types). |
| string | null | $branch | The branch name (required for 'raw' type). |
| string | null | $path | The file path (required for 'raw' type). |
Definition at line 1408 of file class.util.php.
References APP_GITHUB_USER.
Referenced by getGithubUserUrl().
|
static |
Gets the GitHub user URL for Bearsampp.
Definition at line 1450 of file class.util.php.
References APP_GITHUB_USER, and getGithubUrl().
|
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.
| string | $host | The host name or IP address to connect to. |
| int | $port | The port number to connect to. |
| bool | $ssl | Whether to use SSL (defaults to false). |
Definition at line 1124 of file class.util.php.
References $port, $result, and Log\debug().
|
static |
Retrieves HTTP headers from a given URL using either cURL or fopen, depending on availability.
| string | $pingUrl | The URL to ping for headers. |
Definition at line 1015 of file class.util.php.
References $result, Log\debug(), getCurlHttpHeaders(), and getFopenHttpHeaders().
|
static |
Fetches the latest version information from a given url.
| string | $url | The URL to fetch version information from. |
Definition at line 882 of file class.util.php.
References $result, Log\debug(), Log\error(), and getApiJson().
|
static |
Gets the current Unix timestamp with microseconds.
Definition at line 371 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 671 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 |
Retrieves the file size of a remote file.
| string | $url | The URL of the remote file. |
| bool | $humanFileSize | Whether to return the size in a human-readable format. |
Definition at line 956 of file class.util.php.
References humanFileSize().
|
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 337 of file class.util.php.
References $result.
Referenced by Module\getVersionList().
|
static |
Constructs a complete website URL with optional path, fragment, and UTM source parameters.
| string | $path | Optional path to append to the base URL. |
| string | $fragment | Optional fragment to append to the URL. |
| bool | $utmSource | Whether to include UTM source parameters. Defaults to true. |
Definition at line 917 of file class.util.php.
References $bearsamppCore, and APP_WEBSITE.
Referenced by getWebsiteUrlNoUtm().
|
static |
Constructs a website URL without UTM parameters.
| string | $path | Optional path to append to the base URL. |
| string | $fragment | Optional fragment to append to the URL. |
Definition at line 943 of file class.util.php.
References getWebsiteUrl().
|
static |
Converts a file size in bytes to a human-readable format.
Uses PHP's native human_readable_size() when no unit is forced. Falls back to manual conversion when a specific unit is requested.
| int | $size | The file size in bytes. |
| string | $unit | Optional forced unit ('GB', 'MB', 'KB', or ''). |
Definition at line 979 of file class.util.php.
Referenced by HttpClient\getRemoteFilesize(), and getRemoteFilesize().
|
static |
Converts an image file to a base64 encoded string.
| string | $path | The path to the image file. |
Definition at line 478 of file class.util.php.
|
static |
Attempts to install and start a service on a specific port, with optional syntax checking and user notifications.
| object | $bin | An object containing the binary information and methods related to the service. |
| int | $port | The port number on which the service should run. |
| string | $syntaxCheckCmd | The command to execute for syntax checking of the service configuration. |
| bool | $showWindow | Optional. Whether to show message boxes for information, warnings, and errors. Defaults to false. |
Definition at line 1248 of file class.util.php.
References $bearsamppLang, $port, Log\error(), Log\info(), Lang\INSTALL_SERVICE_TITLE, isPortInUse(), Lang\PORT_NOT_USED_BY, Lang\SERVICE_ALREADY_INSTALLED, Lang\SERVICE_INSTALL_ERROR, Lang\SERVICE_INSTALLED, Lang\STARTUP_SERVICE_SYNTAX_ERROR, and Log\warning().
Referenced by ActionService\install(), BinApache\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().
|
static |
Checks if the operating system is 32-bit.
Definition at line 1000 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 212 of file class.util.php.
References $result, and CommandRunner\shellExec().
|
static |
Checks if the application is set to launch at startup.
Definition at line 385 of file class.util.php.
References Path\getStartupLnkPath().
Referenced by ActionReload\__construct(), and TplAppLaunchStartup\process().
|
static |
Checks if a specific port is in use.
| int | $port | The port number to check |
Definition at line 1200 of file class.util.php.
References $port, and Batch\getProcessUsingPort().
Referenced by BinApache\changePort(), BinMailpit\changePort(), BinMariadb\changePort(), BinMemcached\changePort(), BinMysql\changePort(), BinPostgresql\changePort(), BinXlight\changePort(), BinPostgresql\handleNonPostgresUsage(), installService(), and ActionStartup\prepareService().
|
static |
Validates a domain name based on specific criteria.
| string | $domainName | The domain name to validate. |
Definition at line 1233 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 188 of file class.util.php.
|
static |
Validates a port number.
| int | $port | The port number to validate. |
Definition at line 201 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 1513 of file class.util.php.
References $bearsamppConfig, $bearsamppCore, and Path\getTmpPath().
Referenced by ActionDebugBase\__construct().
|
static |
Removes a service if it is installed.
| Win32Service | $service | The service object to be removed. |
| string | $name | The name of the service. |
Definition at line 1331 of file class.util.php.
References Log\error(), Log\info(), and Log\warning().
Referenced by ActionService\remove(), BinApache\setEnable(), BinMailpit\setEnable(), BinMariadb\setEnable(), BinMemcached\setEnable(), BinMysql\setEnable(), BinPostgresql\setEnable(), and BinXlight\setEnable().
|
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 279 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 292 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 |
Sets up cURL headers with token for API requests.
Definition at line 1530 of file class.util.php.
References APP_GITHUB_REPO, APP_GITHUB_USER, and APP_GITHUB_USERAGENT.
Referenced by getApiJson().
|
static |
Initiates a loading process using external components.
Definition at line 530 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 |
Attempts to start a service and performs a syntax check if required.
| object | $bin | An object containing service details. |
| string | $syntaxCheckCmd | Command to check syntax errors. |
| bool | $showWindow | Whether to show error messages in a window. |
Definition at line 1365 of file class.util.php.
References $bearsamppLang, Log\error(), Lang\START_SERVICE_ERROR, Lang\START_SERVICE_TITLE, and Lang\STARTUP_SERVICE_SYNTAX_ERROR.
Referenced by BinPhp\setEnable(), ActionService\start(), and ServiceHelper\startService().
|
static |
Stops a previously started loading process and cleans up related resources.
Definition at line 550 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 571 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 510 of file class.util.php.
Referenced by ActionReload\__construct(), and convertEncoding().