Bearsampp 2026.9.23
Loading...
Searching...
No Matches
class.action.switchPhpParam.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2026 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
17{
18 const SWITCH_ON = 'on';
19 const SWITCH_OFF = 'off';
20
26 public function __construct($args)
27 {
28 global $bearsamppLang, $bearsamppBins, $bearsamppWinbinder;
29
30 // Check if the required arguments are provided and not empty
31 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
32 // Check if the PHP setting exists
33 if (!$bearsamppBins->getPhp()->isSettingExists($args[0])) {
34 $bearsamppWinbinder->messageBoxError(
35 sprintf($bearsamppLang->getValue(Lang::SWITCH_PHP_SETTING_NOT_FOUND), $args[0], $bearsamppBins->getPhp()->getVersion()),
37 );
38
39 return;
40 }
41
42 // Retrieve the current settings values
43 $settingsValues = $bearsamppBins->getPhp()->getSettingsValues();
44 if (isset($settingsValues[$args[0]])) {
45 $onContent = $args[0] . ' = ' . $settingsValues[$args[0]][0];
46 $offContent = $args[0] . ' = ' . $settingsValues[$args[0]][1];
47
48 // Read the current PHP configuration file content
49 $phpiniContent = file_get_contents($bearsamppBins->getPhp()->getConf());
50 if ($args[1] == self::SWITCH_ON) {
51 // Replace the off setting with the on setting
52 $phpiniContent = str_replace($offContent, $onContent, $phpiniContent);
53 } elseif ($args[1] == self::SWITCH_OFF) {
54 // Replace the on setting with the off setting
55 $phpiniContent = str_replace($onContent, $offContent, $phpiniContent);
56 }
57
58 // Write the updated content back to the PHP configuration file
59 file_put_contents($bearsamppBins->getPhp()->getConf(), $phpiniContent);
60 }
61 }
62 }
63}
64
global $bearsamppBins
global $bearsamppLang
const SWITCH_PHP_SETTING_TITLE
const SWITCH_PHP_SETTING_NOT_FOUND