Bearsampp 2025.8.29
Loading...
Searching...
No Matches
ActionSwitchPhpExtension Class Reference

Public Member Functions

 __construct ($args)

Data Fields

const SWITCH_OFF = 'off'
const SWITCH_ON = 'on'

Detailed Description

Class ActionSwitchPhpExtension

This class is responsible for enabling or disabling PHP extensions by modifying the php.ini configuration file.

Definition at line 15 of file class.action.switchPhpExtension.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $args)

ActionSwitchPhpExtension constructor.

Parameters
array$argsAn array containing the extension name and the action (on/off).

Definition at line 25 of file class.action.switchPhpExtension.php.

26 {
27 global $bearsamppBins;
28
29 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
30 $onContent = 'extension=' . $args[0];
31 $offContent = ';extension=' . $args[0];
32
33 $phpiniContent = file_get_contents($bearsamppBins->getPhp()->getConf());
34 if ($args[1] == self::SWITCH_ON) {
35 $phpiniContent = str_replace($offContent, $onContent, $phpiniContent);
36 } elseif ($args[1] == self::SWITCH_OFF) {
37 $phpiniContent = str_replace($onContent, $offContent, $phpiniContent);
38 }
39
40 $phpiniContentOr = file_get_contents($bearsamppBins->getPhp()->getConf());
41 if ($phpiniContent == $phpiniContentOr && file_exists($bearsamppBins->getPhp()->getSymlinkPath() . '/ext/php_' . $args[0] . '.dll')) {
42 $extsIni = $bearsamppBins->getPhp()->getExtensionsFromConf();
43 $latestExt = (end($extsIni) == '0' ? ';' : '');
44 $latestExt .= 'extension=' . key($extsIni);
45 $phpiniContent = str_replace(
46 $latestExt,
47 $latestExt . PHP_EOL . $onContent,
48 $phpiniContent
49 );
50 }
51
52 file_put_contents($bearsamppBins->getPhp()->getConf(), $phpiniContent);
53 }
54 }
global $bearsamppBins

References $bearsamppBins.

Field Documentation

◆ SWITCH_OFF

◆ SWITCH_ON


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