Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Imldeployment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
644761a2
Commit
644761a2
authored
11 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
plugins.class: php8 only; added variable types
parent
d8580ffc
Branches
Branches containing commit
No related tags found
1 merge request
!66
php8 only; added variable types; short array syntax; remove glyphicons
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
public_html/deployment/classes/plugins.class.php
+104
-92
104 additions, 92 deletions
public_html/deployment/classes/plugins.class.php
with
104 additions
and
92 deletions
public_html/deployment/classes/plugins.class.php
+
104
−
92
View file @
644761a2
...
@@ -17,89 +17,93 @@
...
@@ -17,89 +17,93 @@
*
*
*
*
* @author axel
* @author axel
*
* 2024-08-26 v1.1 Axel Hahn php8 only; added variable types
*/
*/
class
ciplugins
{
class
ciplugins
{
/**
/**
* start path of all plugin types (as subdirs)
* start path of all plugin types (as subdirs)
* @var string
* @var string
*/
*/
protected
$_sPlugindir
=
false
;
protected
string
$_sPlugindir
=
''
;
/**
/**
* path of the currently set plugin
* path of the currently set plugin
* @var string
* @var string
*/
*/
protected
$_sSelfdir
=
false
;
protected
string
$_sSelfdir
=
''
;
/**
/**
* url of set plugin
* url of set plugin
* @var string
* @var string
*/
*/
protected
$_sSelfurl
=
false
;
protected
string
$_sSelfurl
=
''
;
/**
/**
* current plugin type - can be set via setType or setPlugin
* current plugin type - can be set via setType or setPlugin
* @var string
* @var string
*/
*/
protected
$_sType
=
false
;
protected
string
$_sType
=
''
;
/**
/**
* current plugin name - can be set via setPlugin
* current plugin name - can be set via setPlugin
* @var string
* @var string
*/
*/
protected
$_sPluginname
=
false
;
protected
string
$_sPluginname
=
''
;
/**
/**
* plugin language
* plugin language
* @var string
* @var string
*/
*/
protected
$_sLang
=
"en-en"
;
protected
string
$_sLang
=
"en-en"
;
/**
/**
* plugin language texts (lang*.json)
* plugin language texts (lang*.json)
* @var array
* @var array
*/
*/
protected
$_aLang
=
[];
protected
array
$_aLang
=
[];
/**
/**
* plugin configuration data (config.json)
* plugin configuration data (config.json)
* @var array
* @var array
*/
*/
protected
$_aConfig
=
[];
protected
array
$_aConfig
=
[];
/**
/**
* global plugins config
* global plugins config
* see config/config_custom.php - key plugins
* see config/config_custom.php - key plugins
* @var array
* @var array
*/
*/
protected
$_aGlobals
=
[];
protected
array
$_aGlobals
=
[];
// ---------------------------------------------------------------
// ---------------------------------------------------------------
// CONSTRUCTOR
// CONSTRUCTOR
// ---------------------------------------------------------------
// ---------------------------------------------------------------
/**
/**
* Constructor
* initialize plugins
* initialize plugins
*
*
* @param array $aGlobals global settings for plugins
* @param array $aGlobals global settings for plugins
* @return boolean
* @return boolean
*/
*/
public
function
__construct
(
$aGlobals
=
[])
{
public
function
__construct
(
array
$aGlobals
=
[])
{
$this
->
_sPlugindir
=
dirname
(
__DIR__
)
.
'/plugins'
;
$this
->
_sPlugindir
=
dirname
(
__DIR__
)
.
'/plugins'
;
$this
->
setGlobalCustoms
(
$aGlobals
);
$this
->
setGlobalCustoms
(
$aGlobals
);
}
}
/**
/**
*
g
lobal configs
*
G
lobal configs
* see config/config_custom.php - key plugins
* see config/config_custom.php - key plugins
*
*
* @param array $aGlobals global settings for plugins
* @param array $aGlobals global settings for plugins
* @return boolean
* @return boolean
*/
*/
public
function
setGlobalCustoms
(
$aGlobals
){
public
function
setGlobalCustoms
(
array
$aGlobals
):
bool
{
$this
->
_aGlobals
=
$aGlobals
;
$this
->
_aGlobals
=
$aGlobals
;
return
true
;
return
true
;
}
}
...
@@ -108,10 +112,11 @@ class ciplugins {
...
@@ -108,10 +112,11 @@ class ciplugins {
// ---------------------------------------------------------------
// ---------------------------------------------------------------
/**
/**
*
g
et an array of available plugin types read from filesystem
*
G
et an array of available plugin types read from filesystem
* @return array
* @return array
*/
*/
public
function
getPluginTypes
(){
public
function
getPluginTypes
():
array
{
$aReturn
=
[];
$aReturn
=
[];
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
)
{
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
)
{
$aReturn
[]
=
basename
(
$sMydir
);
$aReturn
[]
=
basename
(
$sMydir
);
...
@@ -120,12 +125,13 @@ class ciplugins {
...
@@ -120,12 +125,13 @@ class ciplugins {
}
}
/**
/**
*
g
et an array of available plugins read from filesystem
*
G
et an array of available plugins read from filesystem
*
*
* @param string $sType set a new type of plugin; default: use current type
* @param string $sType set a new type of plugin; default: use current type
* @return array
* @return array
*/
*/
public
function
getPlugins
(
$sType
=
false
){
public
function
getPlugins
(
string
$sType
=
''
):
array
{
$aReturn
=
[];
$aReturn
=
[];
if
(
$sType
)
{
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
if
(
!
$this
->
setType
(
$sType
))
{
...
@@ -139,21 +145,23 @@ class ciplugins {
...
@@ -139,21 +145,23 @@ class ciplugins {
}
}
/**
/**
*
g
et an array of enabled plugins
*
G
et an array of enabled plugins
* config/config_custom.php - key "plugins" -> [type] -> [plugin] -> enabled
* config/config_custom.php - key "plugins" -> [type] -> [plugin] -> enabled
* and it must be physically available
* and it must be physically available
*
*
* @param string $sType set a new type of plugin; default: use current type
* @param string $sType set a new type of plugin; default: use current type
* @return array
* @return array
*/
*/
public
function
getEnabledPlugins
(
$sType
=
false
){
public
function
getEnabledPlugins
(
string
$sType
=
''
):
array
{
$aReturn
=
[];
$aReturn
=
[];
if
(
$sType
)
{
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
if
(
!
$this
->
setType
(
$sType
))
{
return
$aReturn
;
return
$aReturn
;
}
}
}
}
if
(
isset
(
$this
->
_aGlobals
[
$this
->
_sType
])
if
(
isset
(
$this
->
_aGlobals
[
$this
->
_sType
])
&&
is_array
(
$this
->
_aGlobals
[
$this
->
_sType
])
&&
is_array
(
$this
->
_aGlobals
[
$this
->
_sType
])
)
{
)
{
foreach
(
$this
->
_aGlobals
[
$this
->
_sType
]
as
$sPluginName
=>
$aData
)
{
foreach
(
$this
->
_aGlobals
[
$this
->
_sType
]
as
$sPluginName
=>
$aData
)
{
...
@@ -180,23 +188,27 @@ class ciplugins {
...
@@ -180,23 +188,27 @@ class ciplugins {
// ---------------------------------------------------------------
// ---------------------------------------------------------------
/**
/**
* set a type for plugins ... what is a name of a subdir in the plugins directory
* Set a type for plugins ... what is a name of a subdir in the plugins directory
* @param {string} $sType Name of a plugin type, e.g. build|rollout
* @param string $sType Name of a plugin type, e.g. build|rollout
* @return bool
*/
*/
public
function
setType
(
$sType
){
public
function
setType
(
string
$sType
):
bool
$this
->
_sType
=
false
;
{
$this
->
_sType
=
''
;
if
(
!
$sType
||
!
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$sType
))
{
if
(
!
$sType
||
!
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$sType
))
{
return
false
;
return
false
;
}
}
return
$this
->
_sType
=
$sType
;
$this
->
_sType
=
$sType
;
return
true
;
}
}
/**
/**
*
r
eset vars before setting a new plugin;
*
R
eset vars before setting a new plugin;
* called in testPlugin()
* called in testPlugin()
* @return boolean
* @return boolean
*/
*/
protected
function
_resetPluginData
(){
protected
function
_resetPluginData
():
bool
{
$this
->
_sPluginname
=
false
;
$this
->
_sPluginname
=
false
;
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfurl
=
false
;
$this
->
_sSelfurl
=
false
;
...
@@ -206,18 +218,20 @@ class ciplugins {
...
@@ -206,18 +218,20 @@ class ciplugins {
}
}
/**
/**
* set a plugin without autoload of its php class
* Test if a plugin of given type exists
*
* It returns the path of php class for true
* It returns the path of php class for true
* or boolean false if it does not exist
* or boolean false if it does not exist
*
*
* This can be used standalone to embed html code
* This can be used standalone to embed html code
* without loading any php code of the plugin class.
* without loading any php code of the plugin class.
*
*
* @param
{
string
}
$sPluginName name of the plugin
* @param string $sPluginName name of the plugin
* @param
{
string
}
$sType optional: set a type
* @param string $sType optional: set a type
* @return bool|string
* @return bool|string
*/
*/
public
function
testPlugin
(
$sPluginName
,
$sType
=
false
){
public
function
testPlugin
(
string
$sPluginName
,
string
$sType
=
''
):
bool
|
string
{
$this
->
_resetPluginData
();
$this
->
_resetPluginData
();
if
(
$sType
)
{
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
if
(
!
$this
->
setType
(
$sType
))
{
...
@@ -237,14 +251,15 @@ class ciplugins {
...
@@ -237,14 +251,15 @@ class ciplugins {
}
}
/**
/**
*
s
et a plugin with autoload of its php class
*
S
et a plugin with autoload of its php class
* It returns a boolean
* It returns a boolean
*
*
* @param
{
string
}
$sPluginName name of the plugin
* @param string $sPluginName name of the plugin
* @param
{
string
}
$sType optional: set a type
* @param string $sType optional: set a type
* @return bool
* @return bool
*/
*/
public
function
setPlugin
(
$sPluginName
,
$sType
=
false
){
public
function
setPlugin
(
string
$sPluginName
,
string
$sType
=
''
):
bool
{
$sFile
=
$this
->
testPlugin
(
$sPluginName
,
$sType
);
$sFile
=
$this
->
testPlugin
(
$sPluginName
,
$sType
);
if
(
!
$sFile
)
{
if
(
!
$sFile
)
{
return
false
;
return
false
;
...
@@ -256,19 +271,22 @@ class ciplugins {
...
@@ -256,19 +271,22 @@ class ciplugins {
// getter for plugin
// getter for plugin
// ---------------------------------------------------------------
// ---------------------------------------------------------------
/**
/**
*
g
et config entry
*
G
et config entry
of a plugin
* @param string $sKey name of config value
* @param string $sKey name of config value
* @return mixed
*/
*/
public
function
getConfigitem
(
$sKey
){
public
function
getConfigitem
(
string
$sKey
):
mixed
return
isset
(
$this
->
_aConfig
[
$sKey
])
?
$this
->
_aConfig
[
$sKey
]
:
false
;
{
return
$this
->
_aConfig
[
$sKey
]
??
false
;
}
}
/**
/**
* get plugin config from its config.json
* get plugin config from its config.json
* works with
* works with
* - shellcmd plugin
* - shellcmd plugin
s
* @return array
* @return array
*/
*/
public
function
getPluginConfig
(){
public
function
getPluginConfig
():
array
{
if
(
count
(
$this
->
_aConfig
))
{
if
(
count
(
$this
->
_aConfig
))
{
return
$this
->
_aConfig
;
return
$this
->
_aConfig
;
}
}
...
@@ -283,18 +301,12 @@ class ciplugins {
...
@@ -283,18 +301,12 @@ class ciplugins {
// ---------------------------------------------------------------
// ---------------------------------------------------------------
/**
/**
* get a location of a plugin file with full path
* Get the classname of a plugin (it is generated by type and plugin name)
* @param {bool} $bAutoload flag: autoload needed plugin file
* @return string
* @return string
*/
*/
public
function
getPluginClassname
(){
public
function
getPluginClassname
():
string
{
return
$this
->
_sType
.
'_'
.
$this
->
_sPluginname
;
return
$this
->
_sType
.
'_'
.
$this
->
_sPluginname
;
}
}
public
function
initPlugin__unused
(){
$sClassname
=
$this
->
_sType
.
'_'
.
$this
->
_sPlugindir
;
$TmpRolloutPlugin
=
new
$sClassname
([]);
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment