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

fix php parser problems

parent 80aa991d
No related branches found
No related tags found
1 merge request!66php8 only; added variable types; short array syntax; remove glyphicons
Showing with 471 additions and 389 deletions
......@@ -90,7 +90,6 @@ class ciplugins {
$this->_sPlugindir=dirname(__DIR__).'/plugins';
$this->setGlobalCustoms($aGlobals);
return true;
}
/**
......
......@@ -18,7 +18,8 @@ require_once('plugins.class.php');
*
* @author axel
*/
class plugin_renderer extends ciplugins {
class plugin_renderer extends ciplugins
{
// ---------------------------------------------------------------
//
......@@ -32,14 +33,15 @@ class plugin_renderer extends ciplugins {
// ---------------------------------------------------------------
/**
* 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]"
*
* @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 ]"
......@@ -47,21 +49,23 @@ class plugin_renderer extends ciplugins {
}
/**
* 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
* translated texts can be done with $this->_t("your_key")
*
* @see _t()
*
* @param string $sLang language code, i.e. "de"
* @return boolean
*/
public function setLang($sLang=false){
$this->_sLang=$sLang ? $sLang : $this->_sLang;
public function setLang(string $sLang = ''): bool
{
$this->_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;
return !!count($this->_aLang);
}
// ---------------------------------------------------------------
// SETTER
......@@ -73,11 +77,14 @@ class plugin_renderer extends ciplugins {
// ---------------------------------------------------------------
/**
* for shellcmd plugins: get html code to load javascript file
* For shellcmd plugins: get html code to load javascript file
* The file must exist in the plugin directory
* @params string $sFile (basename of) filename, eg. render.js
*
* @param string $sFile (basename of) filename, eg. render.js
* @return string
*/
public function getHtmlLoadScript($sFile){
public function getHtmlLoadScript(string $sFile): string
{
return (file_exists($this->_sSelfdir . '/' . $sFile))
? '<script src="' . $this->_sSelfurl . '/' . $sFile . '"></script>' . "\n"
: ''
......@@ -85,24 +92,29 @@ class plugin_renderer extends ciplugins {
}
/**
* get id for an output div
* Get id for an output div
* @return string
*/
public function getHtmlOutId(){
public function getHtmlOutId(): string
{
return $this->_sPluginname ? 'divPlugin' . $this->_sType . '' . $this->_sPluginname : false;
}
/**
* get id for the wrapper div of an output div
* Get id for the wrapper div of an output div
* @return string
*/
public function getHtmlOutIdWrapper(){
public function getHtmlOutIdWrapper(): string
{
return $this->getHtmlOutId() . 'Wrapper';
}
/**
* get html code for a shellcmd output window
* Get html code for a shellcmd output window
* @return string The HTML code
*/
public function getHtmlOutwindow(){
public function getHtmlOutwindow(): string
{
$aConfig = $this->getPluginConfig();
return '<div id="' . $this->getHtmlOutIdWrapper() . '" class="cmdoutbox">'
. '<div id="' . $this->getHtmlOutId() . '" '
......
......@@ -11,13 +11,41 @@ require_once('plugins.class.php');
class req_shellcmd {
/**
* plugin name
* @var string
*/
protected $_sPlugin=false;
/**
* pligin object
* @var object
*/
protected $_oPlugin=false;
protected $_aReturn=false;
/**
* Array of return items
* TODO: might be removed
* @var array
*/
protected $_aReturn=[];
/**
* Configuration for the plugin
* @var array
*/
protected $_aPluginConfig=[];
/**
* Result after execution
* @var array
*/
protected $_aResult=[];
/**
* Flag: enable debug? Default: false
* @var bool
*/
protected $_debug=false;
/**
......@@ -31,11 +59,10 @@ class req_shellcmd {
// ---------------------------------------------------------------
/**
* constructor
* @return bool
* Constructor
*/
public function __construct(){
return $this->detectPlugin();
$this->detectPlugin();
}
// ---------------------------------------------------------------
......
......@@ -12,8 +12,9 @@ interface iRolloutplugin {
/**
* check requirements if the plugin could work
* @return array
*/
public function checkRequirements();
public function checkRequirements(): array;
/**
* check access to a deploy target
......
......@@ -8,7 +8,8 @@ require_once __DIR__.'/../../vendor/axelhahn/ahcache/cache.class.php';
*
* @author axel
*/
class rollout_base implements iRolloutplugin{
class rollout_base implements iRolloutplugin
{
// ---------------------------------------------------------------
// VARIABLES
......@@ -27,9 +28,9 @@ class rollout_base implements iRolloutplugin{
/**
* array with translation texts
* @var type
* @var array
*/
protected $_aLang=false;
protected $_aLang = [];
/**
* set language; 2 letter code, i.e. "de"; default language is "en" ; a
......@@ -47,7 +48,7 @@ class rollout_base implements iRolloutplugin{
/**
* string with phase of project; one of preview|stage|live
* @var type
* @var string
*/
protected $_sPhase = false;
......@@ -79,7 +80,8 @@ class rollout_base implements iRolloutplugin{
* for project and all phases
* @return boolean
*/
public function __construct($aParams) {
public function __construct($aParams)
{
// set current plugin id - taken from plugin directory name above
$oReflection = new ReflectionClass($this);
......@@ -105,7 +107,6 @@ class rollout_base implements iRolloutplugin{
if (isset($aParams['projectcfg'])) {
$this->setProjectConfig($aParams['projectcfg']);
}
return true;
}
// ---------------------------------------------------------------
......@@ -116,10 +117,11 @@ class rollout_base implements iRolloutplugin{
* get a string for a prefix for name attribute in form vars.
* It is important to store the value in the wanted structure.
*
* @param type $sPhase
* @return type
* @param string $sPhase
* @return string
*/
protected function _getNamePrefix($sPhase=false){
protected function _getNamePrefix($sPhase = false)
{
return ($sPhase
? 'phases[' . $sPhase . '][plugins][rollout][' . $this->getId() . ']'
: 'plugins[rollout][' . $this->getId() . ']'
......@@ -132,11 +134,12 @@ class rollout_base implements iRolloutplugin{
*
* @param string $sFunctionname name of the callback function
* @param string $sKey name of the key; "project" or name of phase
* @param integr $iTtl ttl value = how many seconds to use cache
* @param integr $iTtlOnError ttl value = how many seconds to use cache if there was no response
* @return type
* @param integer $iTtl ttl value = how many seconds to use cache
* @param integer $iTtlOnError ttl value = how many seconds to use cache if there was no response
* @return mixed
*/
protected function _getCallback($sFunctionname, $sKey, $iTtl=15,$iTtlOnError=10){
protected function _getCallback($sFunctionname, $sKey, $iTtl = 15, $iTtlOnError = 10)
{
$oCache = new AhCache('rollout-' . $this->getId(), 'callback-' . $sFunctionname . '-' . $sKey);
if ($oCache->isExpired()) {
$aMydata = call_user_func(array($this, $sFunctionname));
......@@ -155,7 +158,8 @@ class rollout_base implements iRolloutplugin{
* @param string $sKey part of the identifier used in id of the input field
* @return string
*/
protected function _renderForm($aFormdata, $sKey){
protected function _renderForm($aFormdata, $sKey)
{
static $i;
if (!isset($i)) {
$i = 0;
......@@ -178,7 +182,8 @@ class rollout_base implements iRolloutplugin{
* @param string $sPhase optional: render global vars in a phase; if no phase was set it renders form fields for project based settings
* @return string
*/
protected function _renderForm4Vars($sScope, $sPhase=false){
protected function _renderForm4Vars($sScope, $sPhase = false)
{
$sReturn = '';
// test vars from info.json file
......@@ -292,7 +297,8 @@ class rollout_base implements iRolloutplugin{
'label' => $this->_t($sVarname . '-label'),
'ondblclick' => ($aDefaultValues[$sVarname] ? 'if (this.value==\'\') { this.value=\'' . $aDefaultValues[$sVarname] . '\' }' : ''),
'onfocusout' => ($aDefaultValues[$sVarname] ? 'if (this.value==\'' . $aDefaultValues[$sVarname] . '\') { this.value=\'\' }' : ''),
'title' => htmlentities($this->_t($sVarname.'-hint')."\n"
'title' => htmlentities(
$this->_t($sVarname . '-hint') . "\n"
. ($this->_aCfgGlobal[$sVarname] ? '- global: ' . $this->_aCfgGlobal[$sVarname] . "\n" : '')
. ($this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname] ? '- project: ' . $this->_aCfgProject['plugins']['rollout'][$this->getId()][$sVarname] . "\n" : '')
)
......@@ -328,7 +334,8 @@ class rollout_base implements iRolloutplugin{
* @param string $sKey key to find in lang file
* @return string
*/
protected function _t($sKey){
protected function _t($sKey)
{
return (isset($this->_aLang[$sKey]) && $this->_aLang[$sKey])
? $this->_aLang[$sKey]
: "[ $sKey :: $this->_sLang ]"
......@@ -348,7 +355,8 @@ class rollout_base implements iRolloutplugin{
* @param string $sLang language code, i.e. "de-de"
* @return boolean
*/
public function setLang($sLang=false){
public function setLang($sLang = false)
{
$this->_sLang = $sLang ? $sLang : $this->_sLang;
$oReflection = new ReflectionClass($this);
......@@ -364,7 +372,8 @@ class rollout_base implements iRolloutplugin{
/**
* set a phase for automatic use GETTER methods
*/
public function setPhase($sPhase){
public function setPhase($sPhase)
{
$this->_sPhase = $sPhase;
return true;
}
......@@ -376,16 +385,19 @@ class rollout_base implements iRolloutplugin{
/**
* check requirements if the plugin could work
* @return array
*/
public function checkRequirements(){
// no specific checks needed ... always true
return true;
public function checkRequirements(): array
{
// no specific checks needed ... always empty
return [];
}
/**
* check access to a deploy target
*/
public function checkConnectionToTarget(){
public function checkConnectionToTarget()
{
// do nothing ... always true
return true;
}
......@@ -399,7 +411,8 @@ class rollout_base implements iRolloutplugin{
* set Config ... by given global config of the current plugin
* @param array $aConfigArray
*/
public function setGlobalConfig($aConfigArray){
public function setGlobalConfig($aConfigArray)
{
return $this->_aCfgGlobal = $aConfigArray;
}
......@@ -408,7 +421,8 @@ class rollout_base implements iRolloutplugin{
/**
* set Config ... by given project config
*/
public function setProjectConfig($aProjectConfigArray){
public function setProjectConfig($aProjectConfigArray)
{
$this->_aCfgProject = $aProjectConfigArray;
// echo '<pre>'.print_r($aProjectConfigArray, 1).'</pre>';
// ----- ensure that the config structure exists
......@@ -456,7 +470,8 @@ class rollout_base implements iRolloutplugin{
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getConfig($sPhase=false, $bMask=false){
public function getConfig($sPhase = false, $bMask = false)
{
$aReturn = array_merge($this->_aCfgGlobal, $this->_aCfgProject['plugins']['rollout'][$this->getId()]);
if ($sPhase && isset($this->_aCfgProject['phases'][$sPhase]['plugins']['rollout'][$this->getId()])) {
......@@ -480,7 +495,8 @@ class rollout_base implements iRolloutplugin{
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase, $bMask=false){
public function getDeployCommands($sPhase, $bMask = false)
{
return [
'echo "ERROR: The method getDeployCommamds($sPhase) was not implemented in the rollout plugin [' . $this->getId() . ']"',
'exit 1'
......@@ -491,7 +507,8 @@ class rollout_base implements iRolloutplugin{
* get string with current ID
* @return string
*/
public function getId(){
public function getId()
{
return $this->_sPluginId;
}
......@@ -499,7 +516,8 @@ class rollout_base implements iRolloutplugin{
* get string with plugin name (taken from plugin language file)
* @return string
*/
public function getName(){
public function getName()
{
return $this->_t('plugin_name');
}
......@@ -507,14 +525,16 @@ class rollout_base implements iRolloutplugin{
* get string with plugin description (taken from plugin language file)
* @return string
*/
public function getDescription(){
public function getDescription()
{
return $this->_t('description');
}
/**
* get array read from info.json
* @return type
* @return array
*/
public function getPluginInfos(){
public function getPluginInfos()
{
if ($this->_aPlugininfos) {
return $this->_aPlugininfos;
......@@ -532,7 +552,8 @@ class rollout_base implements iRolloutplugin{
// ----------------------------------------------------------------------
// INTERFACE :: RENDERER
// ----------------------------------------------------------------------
public function renderCfgExample(){
public function renderCfgExample()
{
$sReturn = '';
$sPre = ' ';
......@@ -571,7 +592,8 @@ class rollout_base implements iRolloutplugin{
);</pre>';
return $sReturn;
}
protected function _renderMoreToggler($sContent){
protected function _renderMoreToggler($sContent)
{
$sDivId = 'rollout-more-toggler-' . $this->getId() . '-' . md5($sContent);
return ''
. '<button onclick="$(\'#' . $sDivId . '\').slideToggle(); return false;" class="btn btn-secondary"> ... </button>'
......@@ -581,7 +603,8 @@ class rollout_base implements iRolloutplugin{
;
}
public function renderFormdata4Project() {
public function renderFormdata4Project()
{
return ''
. $this->_renderForm4Vars('project', false)
. $this->_renderForm4Vars('global', false)
......@@ -591,7 +614,8 @@ class rollout_base implements iRolloutplugin{
// .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>'
;
}
public function renderFormdata4Phase($sPhase){
public function renderFormdata4Phase($sPhase)
{
static $iCounter;
if (!isset($iCounter)) {
$iCounter = 0;
......
......@@ -6,13 +6,15 @@
*
* @author <axel.hahn@iml.unibe.ch>
*/
class build_tgz extends build_base {
class build_tgz extends build_base
{
/**
* check requirements if the plugin could work
* @return array
*/
public function checkRequirements() {
public function checkRequirements(): array
{
return [
'which tar'
];
......@@ -22,7 +24,8 @@ class build_tgz extends build_base {
* get an array with shell commands to execute
* @return array
*/
public function getBuildCommands(){
public function getBuildCommands(): array
{
return [
'cd "' . $this->getBuildDir() . '" && tar -czf "' . $this->getOutfile() . '" .'
];
......
......@@ -6,13 +6,15 @@
*
* @author <axel.hahn@iml.unibe.ch>
*/
class build_zip extends build_base {
class build_zip extends build_base
{
/**
* check requirements if the plugin could work
* @return array
*/
public function checkRequirements() {
public function checkRequirements(): array
{
return [
'which zip'
];
......@@ -26,7 +28,8 @@ class build_zip extends build_base {
* -r recurse into directories
* @return array
*/
public function getBuildCommands(){
public function getBuildCommands(): array
{
return [
'cd "' . $this->getBuildDir() . '" && zip -9qr "' . $this->getOutfile() . '" .'
];
......
......@@ -8,7 +8,8 @@
*
* @author <axel.hahn@iml.unibe.ch>
*/
class rollout_awx extends rollout_base {
class rollout_awx extends rollout_base
{
// url part for AWX API request to set count of results per page
protected $_sAwxApiPaging = '&page_size=10000&page=1';
......@@ -16,17 +17,19 @@ class rollout_awx extends rollout_base {
/**
* check requirements if the plugin could work
*/
public function checkRequirements() {
// no specific checks needed ... always true
return true;
public function checkRequirements(): array
{
// no specific checks needed ... always empty
return [];
}
/**
* check access to a deploy target
*/
public function checkConnectionToTarget() {
// do nothing ... always true
return true;
public function checkConnectionToTarget()
{
// do nothing ... always empty
return [];
}
/**
......@@ -38,9 +41,10 @@ class rollout_awx extends rollout_base {
* - postdata; for POST only
*
* @param array $aRequest arrayurl for Foreman API
* @return string
* @return array
*/
protected function _httpRequest($aRequest=false, $iTimeout = 5) {
protected function _httpRequest($aRequest = false, $iTimeout = 5)
{
if (!function_exists("curl_init")) {
die("ERROR: PHP CURL module is not installed.");
......@@ -51,7 +55,7 @@ class rollout_awx extends rollout_base {
$ch = curl_init($aConfig['url'] . $aRequest['url']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $aRequest['method']);
if ($this->_aRequest['method']==='POST'){
if ($aRequest['method'] === 'POST') {
curl_setopt($ch, CURLOPT_POSTFIELDS, $aRequest['postdata']);
}
......@@ -71,7 +75,7 @@ class rollout_awx extends rollout_base {
$res = curl_exec($ch);
$aReturn=array('info'=>curl_getinfo($ch), 'error'=>curl_error($ch));
$aReturn = ['info' => curl_getinfo($ch), 'error' => curl_error($ch)];
curl_close($ch);
$sHeader = substr($res, 0, $aReturn['info']['header_size']);
......@@ -85,10 +89,12 @@ class rollout_awx extends rollout_base {
/**
* get AWX inventories and return them as array for select box
* [id] => array('value' => [ID], 'label' => [NAME] [ID])
* @return array
* @return bool|array
*/
public function getAwxInventories(){
$aResponse=$this->_httpRequest(array(
public function getAwxInventories()
{
$aResponse = $this->_httpRequest(
array(
'url' => '/inventories/?order_by=name' . $this->_sAwxApiPaging,
'method' => 'GET',
)
......@@ -126,10 +132,12 @@ class rollout_awx extends rollout_base {
/**
* get AWX Job Templates and return them as array for select box
* [id] => array('value' => [ID], 'label' => [PLAYBOOK] [ID])
* @return array
* @return bool|array
*/
public function getAwxJobTemplates(){
$aResponse=$this->_httpRequest(array(
public function getAwxJobTemplates()
{
$aResponse = $this->_httpRequest(
array(
'url' => '/job_templates/?order_by=name' . $this->_sAwxApiPaging,
'method' => 'GET',
)
......@@ -171,7 +179,8 @@ class rollout_awx extends rollout_base {
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase, $bMask=false){
public function getDeployCommands($sPhase, $bMask = false)
{
$aReturn = array();
$aConfig = $this->getConfig($sPhase, $bMask);
......
......@@ -7,22 +7,25 @@
*
* @author <axel.hahn@iml.unibe.ch>
*/
class rollout_default extends rollout_base {
class rollout_default extends rollout_base
{
/**
* check requirements if the plugin could work
*/
public function checkRequirements(){
// no specific checks needed ... always true
return true;
public function checkRequirements(): array
{
// no specific checks needed ... always empty
return [];
}
/**
* check access to a deploy target
*/
public function checkConnectionToTarget(){
// do nothing ... always true
return true;
public function checkConnectionToTarget()
{
// do nothing ... always empty
return [];
}
/**
......@@ -32,7 +35,8 @@ class rollout_default extends rollout_base {
* @param boolean $bMask Flag for public output; if true then mask your secrets
* @return array
*/
public function getDeployCommands($sPhase, $bMask=false){
public function getDeployCommands($sPhase, $bMask = false)
{
return [
'echo "SKIP"'
];
......@@ -44,7 +48,8 @@ class rollout_default extends rollout_base {
*
* @return string
*/
public function renderFormdata4Project() {
public function renderFormdata4Project()
{
return $this->_t('no-cfg');
}
......@@ -54,7 +59,8 @@ class rollout_default extends rollout_base {
*
* @return string
*/
public function renderFormdata4Phase($sPhase) {
public function renderFormdata4Phase($sPhase)
{
return $this->_t('no-cfg');
}
}
......@@ -160,5 +160,3 @@ class ShookerTrigger {
array_push($this->actions, $fxn);
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment