2024.8.23
Loading...
Searching...
No Matches
class.action.switchApacheModule.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 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
10/**
11 * Class ActionSwitchApacheModule
12 *
13 * This class is responsible for enabling or disabling Apache modules by modifying the Apache configuration file.
14 */
16{
17 const SWITCH_ON = 'on';
18 const SWITCH_OFF = 'off';
19
20 /**
21 * ActionSwitchApacheModule constructor.
22 *
23 * @param array $args An array containing the module name and the action (either 'on' or 'off').
24 */
25 public function __construct($args)
26 {
27 global $bearsamppBins;
28
29 if (isset($args[0]) && !empty($args[0]) && isset($args[1]) && !empty($args[1])) {
30 $onContent = 'LoadModule ' . $args[0];
31 $offContent = '#LoadModule ' . $args[0];
32
33 $httpdContent = file_get_contents($bearsamppBins->getApache()->getConf());
34 if ($args[1] == self::SWITCH_ON) {
35 $httpdContent = str_replace($offContent, $onContent, $httpdContent);
36 } elseif ($args[1] == self::SWITCH_OFF) {
37 $httpdContent = str_replace($onContent, $offContent, $httpdContent);
38 }
39
40 file_put_contents($bearsamppBins->getApache()->getConf(), $httpdContent);
41 }
42 }
43}
global $bearsamppBins