php: just some comments and cleanup

This commit is contained in:
Thomas Gelf 2016-12-13 18:24:11 +01:00
parent 04f9b360da
commit 4c1ab4dae6
3 changed files with 28 additions and 19 deletions

View File

@ -11,12 +11,16 @@ use Icinga\Module\Director\Objects\IcingaServiceSet;
class IcingaServiceForm extends DirectorObjectForm
{
/** @var IcingaHost */
private $host;
private $set;
private $apply;
/** @var IcingaService */
protected $object;
private $hostGenerated = false;
private $inheritedFrom;
@ -36,15 +40,18 @@ class IcingaServiceForm extends DirectorObjectForm
public function setup()
{
if ($this->object && $this->object->usesVarOverrides()) {
return $this->setupForVarOverrides();
$this->setupForVarOverrides();
return;
}
if ($this->hostGenerated) {
return $this->setupHostGenerated();
$this->setupHostGenerated();
return;
}
if ($this->inheritedFrom) {
return $this->setupInherited();
$this->setupInherited();
return;
}
try {
@ -186,7 +193,8 @@ class IcingaServiceForm extends DirectorObjectForm
}
if ($this->isNew() && empty($imports)) {
return $this->groupMainProperties();
$this->groupMainProperties();
return;
}
$this->addNameElement()
@ -223,7 +231,8 @@ class IcingaServiceForm extends DirectorObjectForm
}
if ($this->isNew() && empty($imports)) {
return $this->groupMainProperties();
$this->groupMainProperties();
return;
}
$this->addNameElement()
@ -384,7 +393,6 @@ class IcingaServiceForm extends DirectorObjectForm
protected function succeedForOverrides()
{
$vars = array();
foreach ($this->object->vars() as $key => $var) {
$vars[$key] = $var->getValue();

View File

@ -76,10 +76,10 @@ class DirectorDatafield extends DbObjectWithSettings
return $el;
}
/** @var DataTypeHook $datatype */
$datatype = new $className;
$datatype->setSettings($this->getSettings());
$el = $datatype->getFormElement($name, $form);
/** @var DataTypeHook $dataType */
$dataType = new $className;
$dataType->setSettings($this->getSettings());
$el = $dataType->getFormElement($name, $form);
if ($this->getSetting('is_required') === 'y') {
$el->setRequired(true);
@ -112,11 +112,6 @@ class DirectorDatafield extends DbObjectWithSettings
$object->getInheritedVar($varname),
$object->getOriginForVar($varname)
);
} else {
if ($this->required) {
$el->setRequired(true);
}
}
}
}

View File

@ -65,7 +65,7 @@ class IcingaObjectFieldLoader
* Works in a failsafe way, when a field does not exist the value will be
* silently ignored
*
* @param Array $values key/value pairs with variable names and their value
* @param array $values key/value pairs with variable names and their value
* @param String $prefix An optional prefix that would be stripped from keys
*
* @return self
@ -76,13 +76,15 @@ class IcingaObjectFieldLoader
return $this;
}
if ($prefix !== null) {
if ($prefix === null) {
$len = null;
} else {
$len = strlen($prefix);
}
$vars = $this->object->vars();
foreach ($values as $key => $value) {
if ($prefix) {
if ($len !== null) {
if (substr($key, 0, $len) === $prefix) {
$key = substr($key, $len);
} else {
@ -172,8 +174,10 @@ class IcingaObjectFieldLoader
* Attach our form fields to the given form
*
* This will also create a 'Custom properties' display group
*
* @param DirectorObjectForm $form
*/
protected function attachFieldsToForm(QuickForm $form)
protected function attachFieldsToForm(DirectorObjectForm $form)
{
$elements = $this->getElements($form);
foreach ($elements as $element) {
@ -217,6 +221,8 @@ class IcingaObjectFieldLoader
/**
* Get the form elements based on the given form
*
* @param QuickForm $form
*
* @return ZfElement[]
*/
protected function createElements(QuickForm $form)