Skip to content
Snippets Groups Projects
Commit 897f8cc8 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

build-base-class: php8 only; added variable types; short array syntax

parent 77b5bdb2
No related branches found
No related tags found
1 merge request!66php8 only; added variable types; short array syntax; remove glyphicons
...@@ -6,17 +6,47 @@ require_once 'build.interface.php'; ...@@ -6,17 +6,47 @@ require_once 'build.interface.php';
* see deployment/plugins/build/* * see deployment/plugins/build/*
* *
* @author axel * @author axel
*
* 2024-08-23 v1.1 Axel Hahn php8 only; added variable types; short array syntax
*/ */
class build_base implements iBuildplugin{ class build_base implements iBuildplugin
{
protected $_sBuildDir = false; /**
protected $_sOutfile = false; * path of the build directory
* @var string
*/
protected string $_sBuildDir = '';
protected $_sPluginId = false; /**
protected $_aPlugininfos = false; * outputfile during build
* @var string
*/
protected string $_sOutfile = '';
protected $_sLang = "en-en"; /**
protected $_aLang = []; * 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,16 +54,16 @@ class build_base implements iBuildplugin{ ...@@ -24,16 +54,16 @@ class build_base implements iBuildplugin{
// --------------------------------------------------------------- // ---------------------------------------------------------------
/** /**
* initialize build plugin * Initialize build plugin
* @param array $aParams hash with those possible keys * @param array $aParams hash with those possible keys
* lang string language, i.e. 'de' * lang string language, i.e. 'de'
* phase string name of phase in a project * phase string name of phase in a project
* globalcfg array given global config $aConfig * globalcfg array given global config $aConfig
* projectcfg array project config to generate config * projectcfg array project config to generate config
* for project and all phases * 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 // set current plugin id - taken from plugin directory name above
$oReflection = new ReflectionClass($this); $oReflection = new ReflectionClass($this);
...@@ -52,7 +82,6 @@ class build_base implements iBuildplugin{ ...@@ -52,7 +82,6 @@ class build_base implements iBuildplugin{
$this->setOutfile($aParams['outfile']); $this->setOutfile($aParams['outfile']);
} }
return true;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
...@@ -60,14 +89,15 @@ class build_base implements iBuildplugin{ ...@@ -60,14 +89,15 @@ class build_base implements iBuildplugin{
// --------------------------------------------------------------- // ---------------------------------------------------------------
/** /**
* get a translated text from lang_XX.json in plugin dir; * Get a translated text from lang_XX.json in plugin dir;
* If the key is missed it returns "[KEY :: LANG]" * If the key is missed it returns "[KEY :: LANG]"
* *
* @see setLang() * @see setLang()
* @param string $sKey key to find in lang file * @param string $sKey key to find in lang file
* @return string * @return string
*/ */
protected function _t($sKey){ protected function _t(string $sKey): string
{
return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey]) return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey])
? $this->_aLang[$sKey] ? $this->_aLang[$sKey]
: "[ $sKey :: $this->_sLang ]" : "[ $sKey :: $this->_sLang ]"
...@@ -75,7 +105,7 @@ class build_base implements iBuildplugin{ ...@@ -75,7 +105,7 @@ class build_base implements iBuildplugin{
} }
/** /**
* set language for output of formdata and other texts. * Set language for output of formdata and other texts.
* This method loads the language file into a hash. The output of * This method loads the language file into a hash. The output of
* translated texts can be done with $this->_t("your_key") * translated texts can be done with $this->_t("your_key")
* *
...@@ -83,7 +113,8 @@ class build_base implements iBuildplugin{ ...@@ -83,7 +113,8 @@ class build_base implements iBuildplugin{
* @param string $sLang language code, i.e. "de" * @param string $sLang language code, i.e. "de"
* @return boolean * @return boolean
*/ */
public function setLang($sLang=false){ public function setLang(string $sLang = ''): bool
{
$this->_sLang = $sLang ? $sLang : $this->_sLang; $this->_sLang = $sLang ? $sLang : $this->_sLang;
$oReflection = new ReflectionClass($this); $oReflection = new ReflectionClass($this);
...@@ -97,21 +128,25 @@ class build_base implements iBuildplugin{ ...@@ -97,21 +128,25 @@ class build_base implements iBuildplugin{
/** /**
* set build dir with sources * Set build dir with sources
* @param string $sBuildDir full path of the build directory * @param string $sBuildDir full path of the build directory
* @return array * @return bool
*/ */
public function setWorkdir($sBuildDir){ public function setWorkdir(string $sBuildDir): bool
return $this->_sBuildDir=$sBuildDir ? $sBuildDir : $this->_sBuildDir; {
$this->_sBuildDir = $sBuildDir ? $sBuildDir : $this->_sBuildDir;
return true;
} }
/** /**
* set outfile name * Set outfile name
* @param string $sOutFilename filename for output (without extension) * @param string $sOutFilename filename for output (without extension)
* @return array * @return bool
*/ */
public function setOutfile($sOutFilename){ public function setOutfile(string $sOutFilename)
return $this->_sOutfile=$sOutFilename ? $sOutFilename : $this->_sOutfile; {
$this->_sOutfile = $sOutFilename ? $sOutFilename : $this->_sOutfile;
return true;
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
...@@ -119,10 +154,11 @@ class build_base implements iBuildplugin{ ...@@ -119,10 +154,11 @@ class build_base implements iBuildplugin{
// --------------------------------------------------------------- // ---------------------------------------------------------------
/** /**
* check requirements if the plugin could work * Check requirements if the plugin could work
* @return array * @return array
*/ */
public function checkRequirements() { public function checkRequirements(): array
{
return [ 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' 'exit 1'
...@@ -130,10 +166,11 @@ class build_base implements iBuildplugin{ ...@@ -130,10 +166,11 @@ class build_base implements iBuildplugin{
} }
/** /**
* get an array with shell commands to execute * Get an array with shell commands to execute
* @return array * @return array
*/ */
public function getBuildCommands(){ public function getBuildCommands(): array
{
return [ 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' 'exit 1'
...@@ -141,33 +178,38 @@ class build_base implements iBuildplugin{ ...@@ -141,33 +178,38 @@ class build_base implements iBuildplugin{
} }
/** /**
* get string with current ID * Get string with current ID
* @return string * @return string
*/ */
public function getId(){ public function getId(): string
{
return $this->_sPluginId; return $this->_sPluginId;
} }
/** /**
* get string with plugin name (taken from plugin language file) * Get string with plugin name (taken from plugin language file)
* @return string * @return string
*/ */
public function getName(){ public function getName():string
{
return $this->_t('plugin_name'); return $this->_t('plugin_name');
} }
/** /**
* get string with plugin description (taken from plugin language file) * Get string with plugin description (taken from plugin language file)
* @return string * @return string
*/ */
public function getDescription(){ public function getDescription(): string
{
return $this->_t('description'); return $this->_t('description');
} }
/** /**
* get array read from info.json * Get array read from info.json
* @return type * @return array
*/ */
public function getPluginInfos(){ public function getPluginInfos(): array
{
if ($this->_aPlugininfos) { if ($this->_aPlugininfos) {
return $this->_aPlugininfos; return $this->_aPlugininfos;
...@@ -177,40 +219,49 @@ class build_base implements iBuildplugin{ ...@@ -177,40 +219,49 @@ class build_base implements iBuildplugin{
$sFile = dirname($oReflection->getFileName()) . '/info.json'; $sFile = dirname($oReflection->getFileName()) . '/info.json';
$this->_aPlugininfos = (file_exists($sFile)) $this->_aPlugininfos = (file_exists($sFile))
? json_decode(file_get_contents($sFile), 1) ? 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; 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(){ public function getExtension(): string
{
$aInfos = $this->getPluginInfos(); $aInfos = $this->getPluginInfos();
return isset($aInfos['extension']) ? '.' . $aInfos['extension'] : ''; return isset($aInfos['extension']) ? '.' . $aInfos['extension'] : '';
} }
/** /**
* set outfile name including extension (from plugin metadata) * Get outfile name including extension (from plugin metadata)
* @param string $sOutFilename filename for output (without extension) * @return string
* @return array
*/ */
public function getOutfile(){ public function getOutfile(): string
{
return $this->_sOutfile . $this->getExtension(); return $this->_sOutfile . $this->getExtension();
} }
/** /**
* set outfile name * get current build dir
* @param string $sOutFilename filename for output (without extension) * @return string
* @return array
*/ */
public function getBuildDir(){ public function getBuildDir(): string
{
return $this->_sBuildDir; return $this->_sBuildDir;
} }
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// INTERFACE :: RENDERER // INTERFACE :: RENDERER
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
public function renderPluginBox(){
$sReturn=''; /**
* Render plugin box as HTML to show in plugin overview
* @return string
*/
public function renderPluginBox(): string
{
$aInfos = $this->getPluginInfos(); $aInfos = $this->getPluginInfos();
return '<strong>' . $this->getName() . '</strong> (' . $this->getId() . ')<br> return '<strong>' . $this->getName() . '</strong> (' . $this->getId() . ')<br>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment