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
897f8cc8
Commit
897f8cc8
authored
9 months ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
build-base-class: php8 only; added variable types; short array syntax
parent
77b5bdb2
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/build_base.class.php
+137
-86
137 additions, 86 deletions
public_html/deployment/classes/build_base.class.php
with
137 additions
and
86 deletions
public_html/deployment/classes/build_base.class.php
+
137
−
86
View file @
897f8cc8
...
...
@@ -6,17 +6,47 @@ require_once 'build.interface.php';
* see deployment/plugins/build/*
*
* @author axel
*
* 2024-08-23 v1.1 Axel Hahn php8 only; added variable types; short array syntax
*/
class
build_base
implements
iBuildplugin
{
protected
$_sBuildDir
=
false
;
protected
$_sOutfile
=
false
;
protected
$_sPluginId
=
false
;
protected
$_aPlugininfos
=
false
;
class
build_base
implements
iBuildplugin
{
protected
$_sLang
=
"en-en"
;
protected
$_aLang
=
[];
/**
* path of the build directory
* @var string
*/
protected
string
$_sBuildDir
=
''
;
/**
* outputfile during build
* @var string
*/
protected
string
$_sOutfile
=
''
;
/**
* id of the plugin
* @var string
*/
protected
string
$_sPluginId
=
''
;
/**
* array with plugin infos
* @var array
*/
protected
array
$_aPlugininfos
=
[];
/**
* language of ui; default is "en-en"
* @var string
*/
protected
string
$_sLang
=
"en-en"
;
/**
* array of language texts
* @var array
*/
protected
array
$_aLang
=
[];
// ---------------------------------------------------------------
...
...
@@ -24,58 +54,58 @@ class build_base implements iBuildplugin{
// ---------------------------------------------------------------
/**
*
i
nitialize build plugin
*
I
nitialize build plugin
* @param array $aParams hash with those possible keys
* lang string language, i.e. 'de'
* phase string name of phase in a project
* globalcfg array given global config $aConfig
* projectcfg array project config to generate config
* for project and all phases
* @return boolean
*/
public
function
__construct
(
$aParams
)
{
public
function
__construct
(
array
$aParams
)
{
// set current plugin id - taken from plugin directory name above
$oReflection
=
new
ReflectionClass
(
$this
);
$this
->
_sPluginId
=
basename
(
dirname
(
$oReflection
->
getFileName
()));
$oReflection
=
new
ReflectionClass
(
$this
);
$this
->
_sPluginId
=
basename
(
dirname
(
$oReflection
->
getFileName
()));
// ----- init language
if
(
isset
(
$aParams
[
'lang'
])){
if
(
isset
(
$aParams
[
'lang'
]))
{
$this
->
setLang
(
$aParams
[
'lang'
]);
}
else
{
$this
->
setLang
();
}
if
(
isset
(
$aParams
[
'workdir'
])){
if
(
isset
(
$aParams
[
'workdir'
]))
{
$this
->
setWorkdir
(
$aParams
[
'workdir'
]);
}
if
(
isset
(
$aParams
[
'outfile'
])){
if
(
isset
(
$aParams
[
'outfile'
]))
{
$this
->
setOutfile
(
$aParams
[
'outfile'
]);
}
return
true
;
}
// ---------------------------------------------------------------
// LANGUAGE TEXTS
// ---------------------------------------------------------------
/**
*
g
et a translated text from lang_XX.json in plugin dir;
*
G
et a translated text from lang_XX.json in plugin dir;
* If the key is missed it returns "[KEY :: LANG]"
*
* @see setLang()
* @param string $sKey key to find in lang file
* @return string
*/
protected
function
_t
(
$sKey
){
protected
function
_t
(
string
$sKey
):
string
{
return
(
isset
(
$this
->
_aLang
[
$sKey
])
&&
$this
->
_aLang
[
$sKey
])
?
$this
->
_aLang
[
$sKey
]
:
"[
$sKey
::
$this->_sLang
]"
?
$this
->
_aLang
[
$sKey
]
:
"[
$sKey
::
$this->_sLang
]"
;
}
/**
*
s
et language for output of formdata and other texts.
*
S
et language for output of formdata and other texts.
* This method loads the language file into a hash. The output of
* translated texts can be done with $this->_t("your_key")
*
...
...
@@ -83,12 +113,13 @@ class build_base implements iBuildplugin{
* @param string $sLang language code, i.e. "de"
* @return boolean
*/
public
function
setLang
(
$sLang
=
false
){
$this
->
_sLang
=
$sLang
?
$sLang
:
$this
->
_sLang
;
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/lang_'
.
$this
->
_sLang
.
'.json'
;
$this
->
_aLang
=
(
file_exists
(
$sFile
))
?
json_decode
(
file_get_contents
(
$sFile
),
1
)
:
$this
->
_aLang
;
public
function
setLang
(
string
$sLang
=
''
):
bool
{
$this
->
_sLang
=
$sLang
?
$sLang
:
$this
->
_sLang
;
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/lang_'
.
$this
->
_sLang
.
'.json'
;
$this
->
_aLang
=
(
file_exists
(
$sFile
))
?
json_decode
(
file_get_contents
(
$sFile
),
1
)
:
$this
->
_aLang
;
return
true
;
}
// ---------------------------------------------------------------
...
...
@@ -97,123 +128,143 @@ class build_base implements iBuildplugin{
/**
*
s
et build dir with sources
*
S
et build dir with sources
* @param string $sBuildDir full path of the build directory
* @return
array
* @return
bool
*/
public
function
setWorkdir
(
$sBuildDir
){
return
$this
->
_sBuildDir
=
$sBuildDir
?
$sBuildDir
:
$this
->
_sBuildDir
;
public
function
setWorkdir
(
string
$sBuildDir
):
bool
{
$this
->
_sBuildDir
=
$sBuildDir
?
$sBuildDir
:
$this
->
_sBuildDir
;
return
true
;
}
/**
*
s
et outfile name
*
S
et outfile name
* @param string $sOutFilename filename for output (without extension)
* @return
array
* @return
bool
*/
public
function
setOutfile
(
$sOutFilename
){
return
$this
->
_sOutfile
=
$sOutFilename
?
$sOutFilename
:
$this
->
_sOutfile
;
public
function
setOutfile
(
string
$sOutFilename
)
{
$this
->
_sOutfile
=
$sOutFilename
?
$sOutFilename
:
$this
->
_sOutfile
;
return
true
;
}
// ---------------------------------------------------------------
// GETTER
// ---------------------------------------------------------------
/**
*
c
heck requirements if the plugin could work
*
C
heck requirements if the plugin could work
* @return array
*/
public
function
checkRequirements
()
{
public
function
checkRequirements
():
array
{
return
[
'echo "ERROR: The method checkRequirements() was not implemented in the build plugin ['
.
$this
->
getId
()
.
']"'
,
'echo "ERROR: The method checkRequirements() was not implemented in the build plugin ['
.
$this
->
getId
()
.
']"'
,
'exit 1'
];
];
}
/**
*
g
et an array with shell commands to execute
*
G
et an array with shell commands to execute
* @return array
*/
public
function
getBuildCommands
(){
public
function
getBuildCommands
():
array
{
return
[
'echo "ERROR: The method getBuildCommamds() was not implemented in the build plugin ['
.
$this
->
getId
()
.
']"'
,
'echo "ERROR: The method getBuildCommamds() was not implemented in the build plugin ['
.
$this
->
getId
()
.
']"'
,
'exit 1'
];
];
}
/**
*
g
et string with current ID
*
G
et string with current ID
* @return string
*/
public
function
getId
(){
public
function
getId
():
string
{
return
$this
->
_sPluginId
;
}
/**
*
g
et string with plugin name (taken from plugin language file)
*
G
et string with plugin name (taken from plugin language file)
* @return string
*/
public
function
getName
(){
public
function
getName
():
string
{
return
$this
->
_t
(
'plugin_name'
);
}
/**
*
g
et string with plugin description (taken from plugin language file)
*
G
et string with plugin description (taken from plugin language file)
* @return string
*/
public
function
getDescription
(){
public
function
getDescription
():
string
{
return
$this
->
_t
(
'description'
);
}
/**
*
g
et array read from info.json
* @return
type
*
G
et array read from info.json
* @return
array
*/
public
function
getPluginInfos
(){
public
function
getPluginInfos
():
array
{
if
(
$this
->
_aPlugininfos
){
if
(
$this
->
_aPlugininfos
)
{
return
$this
->
_aPlugininfos
;
}
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/info.json'
;
$this
->
_aPlugininfos
=
(
file_exists
(
$sFile
))
$oReflection
=
new
ReflectionClass
(
$this
);
$sFile
=
dirname
(
$oReflection
->
getFileName
())
.
'/info.json'
;
$this
->
_aPlugininfos
=
(
file_exists
(
$sFile
))
?
json_decode
(
file_get_contents
(
$sFile
),
1
)
:
array
(
'error'
=>
'
unable to read info file [
'
.
$sFile
.
'].'
)
:
[
'error'
=>
"
unable to read info file [
$sFile
]."
]
;
return
$this
->
_aPlugininfos
;
}
/**
* get the file extension of created output file (from plugin info.json)
* Get the file extension of created output file (from plugin info.json)
* @return string
*/
public
function
getExtension
(){
$aInfos
=
$this
->
getPluginInfos
();
return
isset
(
$aInfos
[
'extension'
])
?
'.'
.
$aInfos
[
'extension'
]
:
''
;
public
function
getExtension
():
string
{
$aInfos
=
$this
->
getPluginInfos
();
return
isset
(
$aInfos
[
'extension'
])
?
'.'
.
$aInfos
[
'extension'
]
:
''
;
}
/**
* set outfile name including extension (from plugin metadata)
* @param string $sOutFilename filename for output (without extension)
* @return array
* Get outfile name including extension (from plugin metadata)
* @return string
*/
public
function
getOutfile
(){
return
$this
->
_sOutfile
.
$this
->
getExtension
();
public
function
getOutfile
():
string
{
return
$this
->
_sOutfile
.
$this
->
getExtension
();
}
/**
* set outfile name
* @param string $sOutFilename filename for output (without extension)
* @return array
* get current build dir
* @return string
*/
public
function
getBuildDir
(){
public
function
getBuildDir
():
string
{
return
$this
->
_sBuildDir
;
}
// ----------------------------------------------------------------------
// INTERFACE :: RENDERER
// ----------------------------------------------------------------------
public
function
renderPluginBox
(){
$sReturn
=
''
;
$aInfos
=
$this
->
getPluginInfos
();
return
'<strong>'
.
$this
->
getName
()
.
'</strong> ('
.
$this
->
getId
()
.
')<br>
'
.
$this
->
getDescription
();
/**
* Render plugin box as HTML to show in plugin overview
* @return string
*/
public
function
renderPluginBox
():
string
{
$aInfos
=
$this
->
getPluginInfos
();
return
'<strong>'
.
$this
->
getName
()
.
'</strong> ('
.
$this
->
getId
()
.
')<br>
'
.
$this
->
getDescription
();
}
}
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