2024.8.23
Loading...
Searching...
No Matches
class.app.webgrind.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 AppWebgrind
12
*
13
* This class represents the Webgrind application module within the Bearsampp application.
14
* It extends the Module class and provides functionalities specific to Webgrind, such as
15
* configuration management and version handling.
16
*/
17
class
AppWebgrind
extends
Module
18
{
19
/**
20
* Constant for the root configuration version key.
21
*/
22
const
ROOT_CFG_VERSION
=
'webgrindVersion'
;
23
24
/**
25
* Constant for the local configuration file key.
26
*/
27
const
LOCAL_CFG_CONF
=
'webgrindConf'
;
28
29
/**
30
* @var string The path to the Webgrind configuration file.
31
*/
32
private
$conf
;
33
34
/**
35
* Constructor for the AppWebgrind class.
36
*
37
* @param string $id The ID of the module.
38
* @param string $type The type of the module.
39
*/
40
public
function
__construct
(
$id
,
$type
) {
41
Util::logInitClass
($this);
42
$this->
reload
(
$id
,
$type
);
43
}
44
45
/**
46
* Reloads the Webgrind module configuration based on the provided ID and type.
47
*
48
* @param string|null $id The ID of the module. If null, the current ID is used.
49
* @param string|null $type The type of the module. If null, the current type is used.
50
*/
51
public
function
reload
(
$id
=
null
,
$type
=
null
) {
52
global
$bearsamppConfig
,
$bearsamppLang
;
53
Util::logReloadClass
($this);
54
55
$this->name =
$bearsamppLang
->getValue(
Lang::WEBGRIND
);
56
$this->version =
$bearsamppConfig
->getRaw(self::ROOT_CFG_VERSION);
57
parent::reload(
$id
,
$type
);
58
59
if
($this->bearsamppConfRaw !==
false
) {
60
$this->conf = $this->symlinkPath .
'/'
. $this->bearsamppConfRaw[
self::LOCAL_CFG_CONF
];
61
}
62
63
if
(!$this->enable) {
64
Util::logInfo
($this->name .
' is not enabled!'
);
65
return
;
66
}
67
if
(!is_dir($this->currentPath)) {
68
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->currentPath));
69
}
70
if
(!is_dir($this->symlinkPath)) {
71
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_FILE_NOT_FOUND
), $this->name .
' '
. $this->version, $this->symlinkPath));
72
return
;
73
}
74
if
(!is_file($this->bearsamppConf)) {
75
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_CONF_NOT_FOUND
), $this->name .
' '
. $this->version, $this->bearsamppConf));
76
}
77
if
(!is_file($this->conf)) {
78
Util::logError
(sprintf(
$bearsamppLang
->getValue(
Lang::ERROR_CONF_NOT_FOUND
), $this->name .
' '
. $this->version, $this->conf));
79
}
80
}
81
82
/**
83
* Updates the Webgrind module configuration.
84
*
85
* @param string|null $version The version to update to. If null, the current version is used.
86
* @param int $sub The sub-level for logging indentation.
87
* @param bool $showWindow Whether to show a window during the update process.
88
* @return bool True if the update was successful, false otherwise.
89
*/
90
protected
function
updateConfig
(
$version
=
null
, $sub = 0, $showWindow =
false
) {
91
global
$bearsamppRoot
;
92
93
if
(!$this->enable) {
94
return
true
;
95
}
96
97
$version
=
$version
==
null
? $this->version :
$version
;
98
Util::logDebug
(($sub > 0 ? str_repeat(
' '
, 2 * $sub) :
''
) .
'Update '
. $this->name .
' '
.
$version
.
' config'
);
99
100
$alias =
$bearsamppRoot
->getAliasPath() .
'/webgrind.conf'
;
101
if
(is_file($alias)) {
102
Util::replaceInFile
($alias, array(
103
'/^Alias\s\/webgrind\s.*/'
=>
'Alias /webgrind "'
. $this->
getSymlinkPath
() .
'/"'
,
104
'/^<Directory\s.*/'
=>
'<Directory "'
. $this->
getSymlinkPath
() .
'/">'
,
105
));
106
}
else
{
107
Util::logError
($this->
getName
() .
' alias not found : '
. $alias);
108
}
109
110
return
true
;
111
}
112
113
/**
114
* Sets the version of the Webgrind module.
115
*
116
* @param string $version The version to set.
117
*/
118
public
function
setVersion
(
$version
) {
119
global
$bearsamppConfig
;
120
$this->version =
$version
;
121
$bearsamppConfig
->replace(self::ROOT_CFG_VERSION,
$version
);
122
$this->
reload
();
123
}
124
125
/**
126
* Gets the path to the Webgrind configuration file.
127
*
128
* @return string The path to the Webgrind configuration file.
129
*/
130
public
function
getConf
() {
131
return
$this->conf
;
132
}
133
}
$bearsamppLang
global $bearsamppLang
Definition
ajax.apache.php:16
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
AppWebgrind
Definition
class.app.webgrind.php:18
AppWebgrind\updateConfig
updateConfig($version=null, $sub=0, $showWindow=false)
Definition
class.app.webgrind.php:90
AppWebgrind\$conf
$conf
Definition
class.app.webgrind.php:32
AppWebgrind\LOCAL_CFG_CONF
const LOCAL_CFG_CONF
Definition
class.app.webgrind.php:27
AppWebgrind\reload
reload($id=null, $type=null)
Definition
class.app.webgrind.php:51
AppWebgrind\setVersion
setVersion($version)
Definition
class.app.webgrind.php:118
AppWebgrind\getConf
getConf()
Definition
class.app.webgrind.php:130
AppWebgrind\__construct
__construct($id, $type)
Definition
class.app.webgrind.php:40
AppWebgrind\ROOT_CFG_VERSION
const ROOT_CFG_VERSION
Definition
class.app.webgrind.php:22
Lang\ERROR_FILE_NOT_FOUND
const ERROR_FILE_NOT_FOUND
Definition
class.lang.php:160
Lang\WEBGRIND
const WEBGRIND
Definition
class.lang.php:141
Lang\ERROR_CONF_NOT_FOUND
const ERROR_CONF_NOT_FOUND
Definition
class.lang.php:158
Module
Definition
class.module.php:15
Module\$type
$type
Definition
class.module.php:18
Module\getName
getName()
Definition
class.module.php:189
Module\$version
$version
Definition
class.module.php:22
Module\$id
$id
Definition
class.module.php:19
Module\getSymlinkPath
getSymlinkPath()
Definition
class.module.php:250
Util\logReloadClass
static logReloadClass($classInstance)
Definition
class.util.php:822
Util\replaceInFile
static replaceInFile($path, $replaceList)
Definition
class.util.php:389
Util\logError
static logError($data, $file=null)
Definition
class.util.php:802
Util\logDebug
static logDebug($data, $file=null)
Definition
class.util.php:766
Util\logInitClass
static logInitClass($classInstance)
Definition
class.util.php:812
Util\logInfo
static logInfo($data, $file=null)
Definition
class.util.php:778
$bearsamppConfig
global $bearsamppConfig
Definition
homepage.php:26
Bearsampp-development
sandbox
core
classes
apps
class.app.webgrind.php
Generated by
1.11.0