2024.8.23
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()

ActionSwitchPhpExtension::__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 if (version_compare($bearsamppBins->getPhp()->getVersion(), '7.2', '<')) {
33 $onContent = 'extension=php_' . $args[0] . '.dll';
34 $offContent = ';extension=php_' . $args[0] . '.dll';
35 }
36
37 $phpiniContent = file_get_contents($bearsamppBins->getPhp()->getConf());
38 if ($args[1] == self::SWITCH_ON) {
39 $phpiniContent = str_replace($offContent, $onContent, $phpiniContent);
40 } elseif ($args[1] == self::SWITCH_OFF) {
41 $phpiniContent = str_replace($onContent, $offContent, $phpiniContent);
42 }
43
44 $phpiniContentOr = file_get_contents($bearsamppBins->getPhp()->getConf());
45 if ($phpiniContent == $phpiniContentOr && file_exists($bearsamppBins->getPhp()->getSymlinkPath() . '/ext/php_' . $args[0] . '.dll')) {
46 $extsIni = $bearsamppBins->getPhp()->getExtensionsFromConf();
47 $latestExt = (end($extsIni) == '0' ? ';' : '');
48 if (version_compare($bearsamppBins->getPhp()->getVersion(), '7.2', '<')) {
49 $latestExt .= 'extension=php_' . key($extsIni) . '.dll';
50 } else {
51 $latestExt .= 'extension=' . key($extsIni);
52 }
53 $phpiniContent = str_replace(
54 $latestExt,
55 $latestExt . PHP_EOL . $onContent,
56 $phpiniContent
57 );
58 }
59
60 file_put_contents($bearsamppBins->getPhp()->getConf(), $phpiniContent);
61 }
62 }
global $bearsamppBins

References $bearsamppBins.

Field Documentation

◆ SWITCH_OFF

const ActionSwitchPhpExtension::SWITCH_OFF = 'off'

◆ SWITCH_ON


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