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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
Imldeployment
Commits
644761a2
Commit
644761a2
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
plugins.class: php8 only; added variable types
parent
d8580ffc
No related branches found
No related tags found
1 merge request
!66
php8 only; added variable types; short array syntax; remove glyphicons
Changes
1
Hide 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,90 +17,94 @@
*
*
* @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)
* @var string
*/
protected
$_sPlugindir
=
false
;
protected
string
$_sPlugindir
=
''
;
/**
* path of the currently set plugin
* @var string
*/
protected
$_sSelfdir
=
false
;
protected
string
$_sSelfdir
=
''
;
/**
* url of set plugin
* @var string
*/
protected
$_sSelfurl
=
false
;
protected
string
$_sSelfurl
=
''
;
/**
* current plugin type - can be set via setType or setPlugin
* @var string
*/
protected
$_sType
=
false
;
protected
string
$_sType
=
''
;
/**
* current plugin name - can be set via setPlugin
* @var string
*/
protected
$_sPluginname
=
false
;
protected
string
$_sPluginname
=
''
;
/**
* plugin language
* @var string
*/
protected
$_sLang
=
"en-en"
;
protected
string
$_sLang
=
"en-en"
;
/**
* plugin language texts (lang*.json)
* @var array
*/
protected
$_aLang
=
[];
protected
array
$_aLang
=
[];
/**
* plugin configuration data (config.json)
* @var array
*/
protected
$_aConfig
=
[];
protected
array
$_aConfig
=
[];
/**
* global plugins config
* see config/config_custom.php - key plugins
* @var array
*/
protected
$_aGlobals
=
[];
protected
array
$_aGlobals
=
[];
// ---------------------------------------------------------------
// CONSTRUCTOR
// ---------------------------------------------------------------
/**
* Constructor
* initialize plugins
*
* @param array $aGlobals global settings for plugins
* @return boolean
*/
public
function
__construct
(
$aGlobals
=
[])
{
$this
->
_sPlugindir
=
dirname
(
__DIR__
)
.
'/plugins'
;
public
function
__construct
(
array
$aGlobals
=
[])
{
$this
->
_sPlugindir
=
dirname
(
__DIR__
)
.
'/plugins'
;
$this
->
setGlobalCustoms
(
$aGlobals
);
}
/**
*
g
lobal configs
*
G
lobal configs
* see config/config_custom.php - key plugins
*
* @param array $aGlobals global settings for plugins
* @return boolean
*/
public
function
setGlobalCustoms
(
$aGlobals
){
$this
->
_aGlobals
=
$aGlobals
;
public
function
setGlobalCustoms
(
array
$aGlobals
):
bool
{
$this
->
_aGlobals
=
$aGlobals
;
return
true
;
}
// ---------------------------------------------------------------
...
...
@@ -108,61 +112,65 @@ 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
*/
public
function
getPluginTypes
(){
$aReturn
=
[];
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aReturn
[]
=
basename
(
$sMydir
);
public
function
getPluginTypes
():
array
{
$aReturn
=
[];
foreach
(
glob
(
$this
->
_sPlugindir
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
)
{
$aReturn
[]
=
basename
(
$sMydir
);
}
return
$aReturn
;
}
/**
*
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
* @return array
*/
public
function
getPlugins
(
$sType
=
false
){
$aReturn
=
[];
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
public
function
getPlugins
(
string
$sType
=
''
):
array
{
$aReturn
=
[];
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
return
$aReturn
;
}
}
foreach
(
glob
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
){
$aReturn
[]
=
basename
(
$sMydir
);
foreach
(
glob
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/*'
,
GLOB_ONLYDIR
)
as
$sMydir
)
{
$aReturn
[]
=
basename
(
$sMydir
);
}
return
$aReturn
;
}
/**
*
g
et an array of enabled plugins
*
G
et an array of enabled plugins
* config/config_custom.php - key "plugins" -> [type] -> [plugin] -> enabled
* and it must be physically available
*
* @param string $sType set a new type of plugin; default: use current type
* @return array
*/
public
function
getEnabledPlugins
(
$sType
=
false
){
public
function
getEnabledPlugins
(
string
$sType
=
''
):
array
{
$aReturn
=
[];
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
return
$aReturn
;
}
}
if
(
isset
(
$this
->
_aGlobals
[
$this
->
_sType
])
if
(
isset
(
$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
)
{
if
(
isset
(
$aData
[
'enabled'
])
isset
(
$aData
[
'enabled'
])
&&
$aData
[
'enabled'
]
&&
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
)
){
$aReturn
[]
=
$sPluginName
;
&&
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
)
)
{
$aReturn
[]
=
$sPluginName
;
}
}
}
...
...
@@ -180,73 +188,80 @@ class ciplugins {
// ---------------------------------------------------------------
/**
* 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
* 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
* @return bool
*/
public
function
setType
(
$sType
){
$this
->
_sType
=
false
;
if
(
!
$sType
||
!
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$sType
)){
public
function
setType
(
string
$sType
):
bool
{
$this
->
_sType
=
''
;
if
(
!
$sType
||
!
is_dir
(
$this
->
_sPlugindir
.
'/'
.
$sType
))
{
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()
* @return boolean
*/
protected
function
_resetPluginData
(){
$this
->
_sPluginname
=
false
;
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfurl
=
false
;
$this
->
_aLang
=
[];
$this
->
_aConfig
=
[];
protected
function
_resetPluginData
():
bool
{
$this
->
_sPluginname
=
false
;
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfurl
=
false
;
$this
->
_aLang
=
[];
$this
->
_aConfig
=
[];
return
true
;
}
/**
* 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
* or boolean false if it does not exist
*
* This can be used standalone to embed html code
* without loading any php code of the plugin class.
*
* @param
{
string
}
$sPluginName name of the plugin
* @param
{
string
}
$sType optional: set a type
* @param string $sPluginName name of the plugin
* @param string $sType optional: set a type
* @return bool|string
*/
public
function
testPlugin
(
$sPluginName
,
$sType
=
false
){
public
function
testPlugin
(
string
$sPluginName
,
string
$sType
=
''
):
bool
|
string
{
$this
->
_resetPluginData
();
if
(
$sType
){
if
(
!
$this
->
setType
(
$sType
)){
if
(
$sType
)
{
if
(
!
$this
->
setType
(
$sType
))
{
return
false
;
}
}
$this
->
_sSelfdir
=
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
$sFile
=
$this
->
_sSelfdir
.
'/plugin.php'
;
if
(
!
file_exists
(
$sFile
)){
$this
->
_sSelfdir
=
$this
->
_sPlugindir
.
'/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
$sFile
=
$this
->
_sSelfdir
.
'/plugin.php'
;
if
(
!
file_exists
(
$sFile
))
{
// die(' MISS '.$sFile);
$this
->
_sSelfdir
=
false
;
$this
->
_sSelfdir
=
false
;
return
false
;
}
$this
->
_sPluginname
=
$sPluginName
;
$this
->
_sSelfurl
=
'/deployment/plugins/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
$this
->
_sPluginname
=
$sPluginName
;
$this
->
_sSelfurl
=
'/deployment/plugins/'
.
$this
->
_sType
.
'/'
.
$sPluginName
;
return
$sFile
;
}
/**
*
s
et a plugin with autoload of its php class
*
S
et a plugin with autoload of its php class
* It returns a boolean
*
* @param
{
string
}
$sPluginName name of the plugin
* @param
{
string
}
$sType optional: set a type
* @param string $sPluginName name of the plugin
* @param string $sType optional: set a type
* @return bool
*/
public
function
setPlugin
(
$sPluginName
,
$sType
=
false
){
$sFile
=
$this
->
testPlugin
(
$sPluginName
,
$sType
);
if
(
!
$sFile
){
public
function
setPlugin
(
string
$sPluginName
,
string
$sType
=
''
):
bool
{
$sFile
=
$this
->
testPlugin
(
$sPluginName
,
$sType
);
if
(
!
$sFile
)
{
return
false
;
}
include_once
$sFile
;
...
...
@@ -256,25 +271,28 @@ class ciplugins {
// getter for plugin
// ---------------------------------------------------------------
/**
*
g
et config entry
*
G
et config entry
of a plugin
* @param string $sKey name of config value
* @return mixed
*/
public
function
getConfigitem
(
$sKey
){
return
isset
(
$this
->
_aConfig
[
$sKey
])
?
$this
->
_aConfig
[
$sKey
]
:
false
;
}
public
function
getConfigitem
(
string
$sKey
):
mixed
{
return
$this
->
_aConfig
[
$sKey
]
??
false
;
}
/**
* get plugin config from its config.json
* works with
* - shellcmd plugin
* - shellcmd plugin
s
* @return array
*/
public
function
getPluginConfig
(){
if
(
count
(
$this
->
_aConfig
)){
public
function
getPluginConfig
():
array
{
if
(
count
(
$this
->
_aConfig
))
{
return
$this
->
_aConfig
;
}
$this
->
_aConfig
=
(
file_exists
(
$this
->
_sSelfdir
.
'/config.json'
))
?
json_decode
(
file_get_contents
(
$this
->
_sSelfdir
.
'/config.json'
),
1
)
:
[
"error"
=>
"config.json not found in "
.
$this
->
_sSelfdir
]
$this
->
_aConfig
=
(
file_exists
(
$this
->
_sSelfdir
.
'/config.json'
))
?
json_decode
(
file_get_contents
(
$this
->
_sSelfdir
.
'/config.json'
),
1
)
:
[
"error"
=>
"config.json not found in "
.
$this
->
_sSelfdir
]
;
return
$this
->
_aConfig
;
}
...
...
@@ -283,18 +301,12 @@ class ciplugins {
// ---------------------------------------------------------------
/**
* get a location of a plugin file with full path
* @param {bool} $bAutoload flag: autoload needed plugin file
* Get the classname of a plugin (it is generated by type and plugin name)
* @return string
*/
public
function
getPluginClassname
(){
return
$this
->
_sType
.
'_'
.
$this
->
_sPluginname
;
}
public
function
initPlugin__unused
(){
$sClassname
=
$this
->
_sType
.
'_'
.
$this
->
_sPlugindir
;
$TmpRolloutPlugin
=
new
$sClassname
([]);
public
function
getPluginClassname
():
string
{
return
$this
->
_sType
.
'_'
.
$this
->
_sPluginname
;
}
}
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