Bearsampp 2026.5.5
Loading...
Searching...
No Matches
UtilPath Class Reference

Static Public Member Functions

static clearPathFormatCache ()
static formatUnixPath ($path)
static formatWindowsPath ($path)
static getPathFormatCacheSize ()
static getPathFormatStats ()

Static Private Attributes

static $pathFormatCache = []
static $pathFormatCacheMaxSize = 500
static $pathFormatStats

Detailed Description

Path formatting utilities with a write-through cache.

Converts between Windows (backslash) and Unix (forward-slash) path styles and caches the results to avoid redundant string replacements for frequently used paths such as root, bin, and tool paths.

Usage:

$win = UtilPath::formatWindowsPath('/some/unix/path');
$unix = UtilPath::formatUnixPath('C:\some\windows\path');
static formatWindowsPath($path)
static formatUnixPath($path)

Definition at line 24 of file class.util.path.php.

Member Function Documentation

◆ clearPathFormatCache()

clearPathFormatCache ( )
static

Clears the path format cache. Useful when paths change or for testing purposes.

Returns
void

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

143 {
144 self::$pathFormatCache = [];
145 self::$pathFormatStats = [
146 'unix_hits' => 0,
147 'unix_misses' => 0,
148 'windows_hits' => 0,
149 'windows_misses' => 0,
150 ];
151 }

◆ formatUnixPath()

formatUnixPath ( $path)
static

Converts a Windows-style path to a Unix-style path with caching. Unix-style paths use forward slashes (/) as separators.

Performance optimization: Caches results to avoid redundant string replacements for frequently used paths (e.g., root paths, bin paths).

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

Definition at line 98 of file class.util.path.php.

99 {
100 if (empty($path)) {
101 return $path;
102 }
103
104 $cacheKey = 'u_' . $path;
105 if (isset(self::$pathFormatCache[$cacheKey])) {
106 self::$pathFormatStats['unix_hits']++;
107 return self::$pathFormatCache[$cacheKey];
108 }
109
110 self::$pathFormatStats['unix_misses']++;
111
112 $result = str_replace('\\', '/', $path);
113
114 if (count(self::$pathFormatCache) < self::$pathFormatCacheMaxSize) {
115 self::$pathFormatCache[$cacheKey] = $result;
116 } else {
117 $removeCount = (int)(self::$pathFormatCacheMaxSize * 0.1);
118 self::$pathFormatCache = array_slice(self::$pathFormatCache, $removeCount, null, true);
119 self::$pathFormatCache[$cacheKey] = $result;
120 }
121
122 return $result;
123 }
$result

References $result.

Referenced by Util\changePath(), ActionQuit\checkForOrphanedProcesses(), Root\errorHandler(), Win32Ps\findByPath(), Util\findFile(), Util\findFiles(), Util\findRepos(), BinApache\getAliasContent(), BinApache\getVhostContent(), Win32Ps\killBins(), ActionStartup\killOldInstances(), ActionGenSslCertificate\processWindow(), ActionStartup\processWindow(), and ToolGit\reload().

◆ formatWindowsPath()

formatWindowsPath ( $path)
static

Converts a Unix-style path to a Windows-style path with caching. This is a Windows application, so paths use backslashes () as separators.

Performance optimization: Caches results to avoid redundant string replacements for frequently used paths (e.g., root paths, bin paths).

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

Definition at line 60 of file class.util.path.php.

61 {
62 if (empty($path)) {
63 return $path;
64 }
65
66 $cacheKey = 'w_' . $path;
67 if (isset(self::$pathFormatCache[$cacheKey])) {
68 self::$pathFormatStats['windows_hits']++;
69 return self::$pathFormatCache[$cacheKey];
70 }
71
72 self::$pathFormatStats['windows_misses']++;
73
74 $result = str_replace('/', '\\', $path);
75
76 if (count(self::$pathFormatCache) < self::$pathFormatCacheMaxSize) {
77 self::$pathFormatCache[$cacheKey] = $result;
78 } else {
79 $removeCount = (int)(self::$pathFormatCacheMaxSize * 0.1);
80 self::$pathFormatCache = array_slice(self::$pathFormatCache, $removeCount, null, true);
81 self::$pathFormatCache[$cacheKey] = $result;
82 }
83
84 return $result;
85 }

References $result.

Referenced by ActionGenSslCertificate\__construct(), Util\changePath(), ActionStartup\checkPathRegKey(), ActionAddVhost\createFormFields(), ActionEditAlias\createFormFields(), ActionEditVhost\createFormFields(), Batch\createSymlink(), Module\createSymlink(), Util\getAppBinsRegKey(), TplAestan\getItemPowerShell(), Nssm\getNssmEnvPaths(), ToolPowerShell\getShell(), Batch\getTmpFile(), BinMariadb\initData(), Batch\installPostgresqlService(), Batch\refreshEnvVars(), BinMariadb\reload(), Batch\removeSymlink(), Nssm\setBinPath(), Win32Service\setBinPath(), Nssm\setEnvironmentExtra(), and Batch\uninstallPostgresqlService().

◆ getPathFormatCacheSize()

getPathFormatCacheSize ( )
static

Gets the current size of the path format cache.

Returns
int Number of cached path conversions.

Definition at line 158 of file class.util.path.php.

159 {
160 return count(self::$pathFormatCache);
161 }

◆ getPathFormatStats()

getPathFormatStats ( )
static

Gets path format cache statistics. Useful for monitoring cache effectiveness and tuning cache size.

Returns
array Array containing unix_hits, unix_misses, windows_hits, windows_misses.

Definition at line 131 of file class.util.path.php.

132 {
133 return self::$pathFormatStats;
134 }

Field Documentation

◆ $pathFormatCache

$pathFormatCache = []
staticprivate

Definition at line 30 of file class.util.path.php.

◆ $pathFormatCacheMaxSize

$pathFormatCacheMaxSize = 500
staticprivate

Definition at line 36 of file class.util.path.php.

◆ $pathFormatStats

$pathFormatStats
staticprivate
Initial value:
= [
'unix_hits' => 0,
'unix_misses' => 0,
'windows_hits' => 0,
'windows_misses' => 0,
]

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


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