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

View File

@ -76,10 +76,10 @@ class DirectorDatafield extends DbObjectWithSettings
return $el; return $el;
} }
/** @var DataTypeHook $datatype */ /** @var DataTypeHook $dataType */
$datatype = new $className; $dataType = new $className;
$datatype->setSettings($this->getSettings()); $dataType->setSettings($this->getSettings());
$el = $datatype->getFormElement($name, $form); $el = $dataType->getFormElement($name, $form);
if ($this->getSetting('is_required') === 'y') { if ($this->getSetting('is_required') === 'y') {
$el->setRequired(true); $el->setRequired(true);
@ -112,11 +112,6 @@ class DirectorDatafield extends DbObjectWithSettings
$object->getInheritedVar($varname), $object->getInheritedVar($varname),
$object->getOriginForVar($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 * Works in a failsafe way, when a field does not exist the value will be
* silently ignored * 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 * @param String $prefix An optional prefix that would be stripped from keys
* *
* @return self * @return self
@ -76,13 +76,15 @@ class IcingaObjectFieldLoader
return $this; return $this;
} }
if ($prefix !== null) { if ($prefix === null) {
$len = null;
} else {
$len = strlen($prefix); $len = strlen($prefix);
} }
$vars = $this->object->vars(); $vars = $this->object->vars();
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if ($prefix) { if ($len !== null) {
if (substr($key, 0, $len) === $prefix) { if (substr($key, 0, $len) === $prefix) {
$key = substr($key, $len); $key = substr($key, $len);
} else { } else {
@ -172,8 +174,10 @@ class IcingaObjectFieldLoader
* Attach our form fields to the given form * Attach our form fields to the given form
* *
* This will also create a 'Custom properties' display group * 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); $elements = $this->getElements($form);
foreach ($elements as $element) { foreach ($elements as $element) {
@ -217,6 +221,8 @@ class IcingaObjectFieldLoader
/** /**
* Get the form elements based on the given form * Get the form elements based on the given form
* *
* @param QuickForm $form
*
* @return ZfElement[] * @return ZfElement[]
*/ */
protected function createElements(QuickForm $form) protected function createElements(QuickForm $form)