![]() |
Bearsampp 2026.9.23
|
Public Member Functions | |
| __construct () | |
| checkDownloadId () | |
| checkQuickpickJson () | |
| fetchAndUnzipModule (string $moduleUrl, string $module) | |
| getErrorModal (string $errorMessage) | |
| getModuleDestinationPath (string $moduleType, string $moduleName) | |
| getModules () | |
| getModuleUrl (string $module, string $version) | |
| getQuickpickJson () | |
| getQuickpickMenu (array $modules, array $versions, string $imagesPath) | |
| getVersions () | |
| installModule (string $module, string $version) | |
| loadQuickpick (string $imagesPath) | |
| normalizeModuleName (string $moduleName) | |
| rebuildQuickpickJson () | |
Data Fields | |
| $modules | |
Private Member Functions | |
| formatVersionLabel ($version, $isPrerelease=false) | |
| getHeaderValue ($headers, string $name) | |
| getLocalFileCreationTime () | |
| isValidHeaderResponse ($headers) | |
| logHeaders (array $headers) | |
| regenerateMenuSafe () | |
| updateModuleConfig (string $module, string $version) | |
Static Private Member Functions | |
| static | fetchChecksumFromSidecar (string $moduleUrl) |
| static | isAllowedArchive (string $fileName) |
| static | verifyModuleChecksum (string $moduleUrl, string $tmpFilePath) |
Private Attributes | |
| $jsonFilePath | |
| $versions = [] | |
Static Private Attributes | |
| static | $allowedArchiveExtensions = ['7z', 'zip'] |
Class QuickPick
The QuickPick class provides functionalities for managing and installing various modules within the Bearsampp application. It includes methods for retrieving available modules, fetching module versions, parsing release properties, and validating license keys.
Definition at line 18 of file class.action.quickPick.php.
| __construct | ( | ) |
Constructor to initialize the jsonFilePath.
Definition at line 76 of file class.action.quickPick.php.
References $bearsamppCore, and Path\getResourcesPath().
| checkDownloadId | ( | ) |
Validates the format of a given username key by checking it against an external API.
This method performs several checks to ensure the validity of the username key:
Definition at line 457 of file class.action.quickPick.php.
References $bearsamppConfig, $response, Log\debug(), Log\error(), HttpClient\getSslStreamContext(), QUICKPICK_API_KEY, and QUICKPICK_API_URL.
Referenced by getQuickpickMenu().
| checkQuickpickJson | ( | ) |
Checks if the local quickpick-releases.json file is up-to-date with the remote version.
Compares the creation time of the local JSON file with the remote file's last modified time. If the remote file is newer or the local file does not exist, it fetches the latest JSON data by calling the rebuildQuickpickJson method.
| Exception |
Definition at line 174 of file class.action.quickPick.php.
References $bearsamppConfig, $result, getHeaderValue(), getLocalFileCreationTime(), HttpClient\getSslStreamContext(), HttpClient\isGithubHost(), isValidHeaderResponse(), logHeaders(), HttpClient\proxyFetch(), QUICKPICK_JSON_URL, and rebuildQuickpickJson().
Referenced by loadQuickpick().
| fetchAndUnzipModule | ( | string | $moduleUrl, |
| string | $module ) |
Fetches the module URL and stores it in /tmp, then unzips the file based on its extension.
| string | $moduleUrl | The URL of the module to fetch. |
| string | $module | The name of the module. |
Definition at line 625 of file class.action.quickPick.php.
References $bearsamppCore, $bearsamppRoot, $result, Log\debug(), HttpClient\downloadFile(), Log\error(), getModuleDestinationPath(), and Path\getTmpPath().
Referenced by installModule().
|
staticprivate |
Fetches and parses the expected SHA-256 digest from the asset sidecar file.
The sidecar URL is the module download URL with '.sha256' appended, and its contents follow the standard "<hex-hash> <filename>" format. Only a full 64-char lowercase hex digest is accepted.
| string | $moduleUrl | The module download URL. |
Definition at line 795 of file class.action.quickPick.php.
References $result, Log\error(), HttpClient\getSslStreamContext(), HttpClient\isGithubHost(), HttpClient\proxyFetch(), and Log\trace().
Referenced by verifyModuleChecksum().
|
private |
Format version label with PR indicator if it's a prerelease
| string | $version | The version to format |
| bool | $isPrerelease | Whether this version is a prerelease |
Definition at line 90 of file class.action.quickPick.php.
References $bearsamppConfig.
| getErrorModal | ( | string | $errorMessage | ) |
Generates an error modal for configuration validation failures.
| string | $errorMessage | The error message to display. |
Definition at line 980 of file class.action.quickPick.php.
Referenced by loadQuickpick().
|
private |
Retrieves a header value case-insensitively.
HTTP header names are case-insensitive. get_headers() may return keys in any case, while the GitHub proxy normalizes them to lowercase, so lookups must not rely on exact key casing.
| mixed | $headers | The header map (or false on failure). |
| string | $name | The header name to look up. |
Definition at line 278 of file class.action.quickPick.php.
Referenced by checkQuickpickJson(), and isValidHeaderResponse().
|
private |
Returns the local file's creation time, or triggers and returns 0 if file does not exist.
Definition at line 229 of file class.action.quickPick.php.
References rebuildQuickpickJson().
Referenced by checkQuickpickJson().
| getModuleDestinationPath | ( | string | $moduleType, |
| string | $moduleName ) |
Get the destination path for a given module type and name.
This method constructs the destination path based on the type of module (application, binary, or tools) and the module name. It utilizes the bearsamppRoot global object to retrieve the base paths for each module type.
| string | $moduleType | The type of the module ('application', 'binary', or 'tools'). |
| string | $moduleName | The name of the module. |
Definition at line 858 of file class.action.quickPick.php.
References $bearsamppRoot, Path\getAppsPath(), Path\getBinPath(), and Path\getToolsPath().
Referenced by fetchAndUnzipModule().
| getModules | ( | ) |
Retrieves the list of available modules.
Definition at line 131 of file class.action.quickPick.php.
Referenced by loadQuickpick().
| getModuleUrl | ( | string | $module, |
| string | $version ) |
Fetches the URL of a specified module version from the local quickpick-releases.json file.
This method reads the quickpick-releases.json file to find the URL associated with the given module and version. It logs the process and returns the URL if found, or an error message if not.
| string | $module | The name of the module. |
| string | $version | The version of the module. |
Definition at line 420 of file class.action.quickPick.php.
References Log\debug(), Log\error(), and getVersions().
Referenced by installModule().
| getQuickpickJson | ( | ) |
Retrieves the QuickPick JSON data from the local file.
Definition at line 315 of file class.action.quickPick.php.
References Log\error().
Referenced by getVersions().
| getQuickpickMenu | ( | array | $modules, |
| array | $versions, | ||
| string | $imagesPath ) |
Generates the HTML content for the QuickPick menu.
This method creates the HTML structure for the QuickPick interface, including a dropdown for selecting modules and their respective versions. It checks if the license key is valid before displaying the modules. If the license key is invalid, it displays a subscription prompt. If there is no internet connection, it displays a message indicating the lack of internet.
| array | $modules | An array of available modules. |
| array | $versions | An associative array where the key is the module name and the value is an array containing the module versions. |
| string | $imagesPath | The path to the images directory. |
Definition at line 1018 of file class.action.quickPick.php.
References $bearsamppConfig, $imagesPath, checkDownloadId(), HttpClient\getWebsiteUrl(), and if.
Referenced by loadQuickpick().
| getVersions | ( | ) |
Retrieves the list of available versions for all modules.
This method fetches the QuickPick JSON data and returns an array of versions or If no versions are found, an error message is logged and returned.
Definition at line 372 of file class.action.quickPick.php.
References $versions, Log\debug(), Log\error(), and getQuickpickJson().
Referenced by getModuleUrl(), and loadQuickpick().
| installModule | ( | string | $module, |
| string | $version ) |
Installs a specified module by fetching its URL and unzipping its contents.
This method retrieves the URL of the specified module and version from the QuickPick JSON data. If the URL is found, it fetches and unzips the module. If the URL is not found, it logs an error and returns an error message.
| string | $module | The name of the module to install. |
| string | $version | The version of the module to install. |
Definition at line 532 of file class.action.quickPick.php.
References $bearsamppConfig, $response, CommandRunner\background(), HttpClient\checkInternetState(), CacheManager\clearAll(), Log\debug(), Log\error(), fetchAndUnzipModule(), Path\getCorePath(), getModuleUrl(), Path\getPhpExe(), Core\isRoot_FILE, Action\RELOAD, and updateModuleConfig().
|
staticprivate |
Checks whether a file path/name has an allowed archive extension.
Only lowercase '.7z' and '.zip' are accepted. This is used both before download (from the URL filename) and after download (from the actual file) to strictly reject anything else.
| string | $fileName | File name or path to validate. |
Definition at line 835 of file class.action.quickPick.php.
|
private |
Determines whether the header response is valid and includes a 'Date' or 'Last-Modified' key.
Both direct (get_headers) and GitHub-proxy HEAD responses are accepted, so update checks keep working even if the proxy forwards Last-Modified but not Date (or vice versa). Header name matching is case-insensitive.
| mixed | $headers | Headers retrieved from get_headers() or the GitHub proxy. |
Definition at line 254 of file class.action.quickPick.php.
References getHeaderValue().
Referenced by checkQuickpickJson().
| loadQuickpick | ( | string | $imagesPath | ) |
Loads the QuickPick interface with the available modules and their versions.
| string | $imagesPath | The path to the images directory. |
| Exception |
Definition at line 145 of file class.action.quickPick.php.
References $bearsamppConfig, $imagesPath, $modules, $versions, checkQuickpickJson(), getErrorModal(), getModules(), getQuickpickMenu(), and getVersions().
|
private |
Logs the headers in debug mode if logsVerbose is set to 2.
| array | $headers | The headers returned by get_headers(). |
Definition at line 301 of file class.action.quickPick.php.
References $bearsamppConfig, and Log\debug().
Referenced by checkQuickpickJson().
| normalizeModuleName | ( | string | $moduleName | ) |
Normalizes a module name to find the correct module key from the modules array. Handles case-insensitive matching for all module types.
| string | $moduleName | The module name to normalize (may include 'module-' prefix) |
Definition at line 110 of file class.action.quickPick.php.
| rebuildQuickpickJson | ( | ) |
Rebuilds the local quickpick-releases.json file by fetching the latest data from the remote URL.
| Exception | If the JSON content cannot be fetched or saved. |
Definition at line 340 of file class.action.quickPick.php.
References $result, Log\debug(), HttpClient\getApiJson(), and QUICKPICK_JSON_URL.
Referenced by checkQuickpickJson(), and getLocalFileCreationTime().
|
private |
Regenerates the bearsampp.ini menu file without VBS checks (AJAX-safe version). This is a simplified version of TplApp\process() that avoids VBS errors in web context.
Definition at line 880 of file class.action.quickPick.php.
References Log\debug(), TplApp\process(), and Log\warning().
|
private |
Updates the bearsampp.conf configuration file with the new module version. This method handles all module types: binaries, apps, and tools.
| string | $module | The name of the module (e.g., 'Apache', 'PhpMyAdmin', 'Git'). |
| string | $version | The version to set in the configuration. |
Definition at line 916 of file class.action.quickPick.php.
References $bearsamppConfig, Log\debug(), Log\error(), and Log\info().
Referenced by installModule().
|
staticprivate |
Verifies the SHA-256 checksum of a downloaded module archive.
The expected hash is read from the .sha256 sidecar published alongside the release asset (e.g. <archive>.7z.sha256), fetched over a verified TLS context. The archive is only considered valid if its computed hash matches exactly.
| string | $moduleUrl | The URL the archive was downloaded from. |
| string | $tmpFilePath | The local path of the downloaded archive. |
Definition at line 748 of file class.action.quickPick.php.
References Log\debug(), Log\error(), and fetchChecksumFromSidecar().
|
staticprivate |
Whitelist of archive extensions that may be downloaded and extracted.
Definition at line 71 of file class.action.quickPick.php.
|
private |
The file path to the local quickpick-releases.json file.
Definition at line 64 of file class.action.quickPick.php.
| $modules |
An associative array where the key is the module name and the value is an array containing the module type. The module type can be one of the following:
Definition at line 29 of file class.action.quickPick.php.
Referenced by loadQuickpick().
|
private |
An associative array where the key is the module name and the value is an array containing the module versions.
Definition at line 57 of file class.action.quickPick.php.
Referenced by getVersions(), and loadQuickpick().