mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-07-31 01:34:09 +02:00
Merge branch 'master' into bugfix/monitoring-list-duplicates-7057
This commit is contained in:
commit
5143c78f1a
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Protocol\File;
|
namespace Icinga\Protocol\File;
|
||||||
|
|
||||||
use FilterIterator;
|
use Icinga\Util\EnumeratingFilterIterator;
|
||||||
use Icinga\Util\File;
|
use Icinga\Util\File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -12,7 +12,7 @@ use Icinga\Util\File;
|
|||||||
*
|
*
|
||||||
* Iterate over a file, yielding only fields of non-empty lines which match a PCRE expression
|
* Iterate over a file, yielding only fields of non-empty lines which match a PCRE expression
|
||||||
*/
|
*/
|
||||||
class FileIterator extends FilterIterator
|
class FileIterator extends EnumeratingFilterIterator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A PCRE string with the fields to extract from the file's lines as named subpatterns
|
* A PCRE string with the fields to extract from the file's lines as named subpatterns
|
||||||
|
@ -6,7 +6,6 @@ namespace Icinga\Protocol\File;
|
|||||||
|
|
||||||
use Icinga\Data\Selectable;
|
use Icinga\Data\Selectable;
|
||||||
use Countable;
|
use Countable;
|
||||||
use Icinga\Util\Enumerate;
|
|
||||||
use Zend_Config;
|
use Zend_Config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,9 +52,7 @@ class FileReader implements Selectable, Countable
|
|||||||
*/
|
*/
|
||||||
public function iterate()
|
public function iterate()
|
||||||
{
|
{
|
||||||
return new Enumerate(
|
return new FileIterator($this->filename, $this->fields);
|
||||||
new FileIterator($this->filename, $this->fields)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
// {{{ICINGA_LICENSE_HEADER}}}
|
|
||||||
|
|
||||||
namespace Icinga\Util;
|
|
||||||
|
|
||||||
use Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class Enumerate
|
|
||||||
*
|
|
||||||
* @see https://docs.python.org/2/library/functions.html#enumerate
|
|
||||||
*
|
|
||||||
* @package Icinga\Util
|
|
||||||
*/
|
|
||||||
class Enumerate implements Iterator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var Iterator
|
|
||||||
*/
|
|
||||||
protected $iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int
|
|
||||||
*/
|
|
||||||
protected $key;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Iterator $iterator
|
|
||||||
*/
|
|
||||||
public function __construct(Iterator $iterator)
|
|
||||||
{
|
|
||||||
$this->iterator = $iterator;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function rewind()
|
|
||||||
{
|
|
||||||
$this->iterator->rewind();
|
|
||||||
$this->key = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function next()
|
|
||||||
{
|
|
||||||
$this->iterator->next();
|
|
||||||
++$this->key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function valid()
|
|
||||||
{
|
|
||||||
return $this->iterator->valid();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function current()
|
|
||||||
{
|
|
||||||
return $this->iterator->current();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function key()
|
|
||||||
{
|
|
||||||
return $this->key;
|
|
||||||
}
|
|
||||||
}
|
|
37
library/Icinga/Util/EnumeratingFilterIterator.php
Normal file
37
library/Icinga/Util/EnumeratingFilterIterator.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Util;
|
||||||
|
|
||||||
|
use FilterIterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EnumeratingFilterIterator
|
||||||
|
*
|
||||||
|
* FilterIterator with continuous numeric key (index)
|
||||||
|
*/
|
||||||
|
abstract class EnumeratingFilterIterator extends FilterIterator
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
private $index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function rewind()
|
||||||
|
{
|
||||||
|
parent::rewind();
|
||||||
|
$this->index = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function key()
|
||||||
|
{
|
||||||
|
return $this->index++;
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,7 @@
|
|||||||
namespace Icinga\Web;
|
namespace Icinga\Web;
|
||||||
|
|
||||||
use LogicException;
|
use LogicException;
|
||||||
|
use Zend_Config;
|
||||||
use Zend_Form;
|
use Zend_Form;
|
||||||
use Zend_View_Interface;
|
use Zend_View_Interface;
|
||||||
use Icinga\Application\Icinga;
|
use Icinga\Application\Icinga;
|
||||||
@ -81,6 +82,19 @@ class Form extends Zend_Form
|
|||||||
*/
|
*/
|
||||||
protected $uidElementName = 'formUID';
|
protected $uidElementName = 'formUID';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default element decorators
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $defaultElementDecorators = array(
|
||||||
|
'ViewHelper',
|
||||||
|
'Errors',
|
||||||
|
array('Description', array('tag' => 'span', 'class' => 'description')),
|
||||||
|
'Label',
|
||||||
|
array('HtmlTag', array('tag' => 'div'))
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new form
|
* Create a new form
|
||||||
*
|
*
|
||||||
@ -105,16 +119,6 @@ class Form extends Zend_Form
|
|||||||
throw new LogicException('The option `onSuccess\' is not callable');
|
throw new LogicException('The option `onSuccess\' is not callable');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isset($options['elementDecorators'])) {
|
|
||||||
$options['elementDecorators'] = array(
|
|
||||||
'ViewHelper',
|
|
||||||
'Errors',
|
|
||||||
array('Description', array('tag' => 'span', 'class' => 'description')),
|
|
||||||
'Label',
|
|
||||||
array('HtmlTag', array('tag' => 'div'))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($options);
|
parent::__construct($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,23 +421,35 @@ class Form extends Zend_Form
|
|||||||
/**
|
/**
|
||||||
* Create a new element
|
* Create a new element
|
||||||
*
|
*
|
||||||
* Additionally, all structural form element decorators by Zend are replaced with our own ones.
|
* Icinga Web 2 loads its own default element decorators. For loading Zend's default element decorators set the
|
||||||
|
* `disableLoadDefaultDecorators' option to any other value than `true'. For loading custom element decorators use
|
||||||
|
* the 'decorators' option.
|
||||||
*
|
*
|
||||||
* @param string $type String element type
|
* @param string $type String element type
|
||||||
* @param string $name The name of the element to add
|
* @param string $name The name of the element to add
|
||||||
* @param array $options The options for the element
|
* @param mixed $options The options for the element
|
||||||
*
|
*
|
||||||
* @return Zend_Form_Element
|
* @return Zend_Form_Element
|
||||||
*
|
*
|
||||||
* @see Zend_Form::createElement()
|
* @see Form::$defaultElementDecorators For Icinga Web 2's default element decorators.
|
||||||
*/
|
*/
|
||||||
public function createElement($type, $name, $options = null)
|
public function createElement($type, $name, $options = null)
|
||||||
{
|
{
|
||||||
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
|
if ($options !== null) {
|
||||||
$options['disableLoadDefaultDecorators'] = true;
|
if ($options instanceof Zend_Config) {
|
||||||
|
$options = $options->toArray();
|
||||||
|
}
|
||||||
|
if (! isset($options['decorators'])
|
||||||
|
&& ! array_key_exists('disabledLoadDefaultDecorators', $options)
|
||||||
|
) {
|
||||||
|
$options['decorators'] = static::$defaultElementDecorators;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$options = array('decorators' => static::$defaultElementDecorators);
|
||||||
}
|
}
|
||||||
|
|
||||||
$el = parent::createElement($type, $name, $options);
|
$el = parent::createElement($type, $name, $options);
|
||||||
|
|
||||||
if ($el && $el->getAttrib('autosubmit')) {
|
if ($el && $el->getAttrib('autosubmit')) {
|
||||||
$el->addDecorator(new NoScriptApply()); // Non-JS environments
|
$el->addDecorator(new NoScriptApply()); // Non-JS environments
|
||||||
$class = $el->getAttrib('class');
|
$class = $el->getAttrib('class');
|
||||||
|
@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
namespace Icinga\Web\Form\Element;
|
namespace Icinga\Web\Form\Element;
|
||||||
|
|
||||||
use Zend_Form_Element_Xhtml;
|
|
||||||
use Icinga\Web\Session;
|
use Icinga\Web\Session;
|
||||||
|
use Icinga\Web\Form\FormElement;
|
||||||
use Icinga\Web\Form\InvalidCSRFTokenException;
|
use Icinga\Web\Form\InvalidCSRFTokenException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,7 +13,7 @@ use Icinga\Web\Form\InvalidCSRFTokenException;
|
|||||||
*
|
*
|
||||||
* You must not set a value to successfully use this element, just give it a name and you're good to go.
|
* You must not set a value to successfully use this element, just give it a name and you're good to go.
|
||||||
*/
|
*/
|
||||||
class CsrfCounterMeasure extends Zend_Form_Element_Xhtml
|
class CsrfCounterMeasure extends FormElement
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Default form view helper to use for rendering
|
* Default form view helper to use for rendering
|
||||||
@ -22,14 +22,26 @@ class CsrfCounterMeasure extends Zend_Form_Element_Xhtml
|
|||||||
*/
|
*/
|
||||||
public $helper = 'formHidden';
|
public $helper = 'formHidden';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counter measure element is required
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $_ignore = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ignore element when retrieving values at form level
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $_required = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize this form element
|
* Initialize this form element
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->setRequired(true); // Not requiring this element would not make any sense
|
$this->addDecorator('ViewHelper');
|
||||||
$this->setIgnore(true); // We do not want this element's value being retrieved by Form::getValues()
|
|
||||||
$this->setDecorators(array('ViewHelper'));
|
|
||||||
$this->setValue($this->generateCsrfToken());
|
$this->setValue($this->generateCsrfToken());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,27 +5,15 @@
|
|||||||
namespace Icinga\Web\Form\Element;
|
namespace Icinga\Web\Form\Element;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Zend_Form_Element;
|
use Icinga\Web\Form;
|
||||||
|
use Icinga\Web\Form\FormElement;
|
||||||
use Icinga\Web\Form\Validator\DateTimeValidator;
|
use Icinga\Web\Form\Validator\DateTimeValidator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A date-and-time input control
|
* A date-and-time input control
|
||||||
*
|
|
||||||
* @method DateTime getValue()
|
|
||||||
*/
|
*/
|
||||||
class DateTimePicker extends Zend_Form_Element
|
class DateTimePicker extends FormElement
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Disable default decorators
|
|
||||||
*
|
|
||||||
* \Icinga\Web\Form sets default decorators for elements.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*
|
|
||||||
* @see \Icinga\Web\Form::__construct() For default element decorators.
|
|
||||||
*/
|
|
||||||
protected $_disableLoadDefaultDecorators = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form view helper to use for rendering
|
* Form view helper to use for rendering
|
||||||
*
|
*
|
||||||
@ -54,7 +42,7 @@ class DateTimePicker extends Zend_Form_Element
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* (non-PHPDoc)
|
* (non-PHPDoc)
|
||||||
* @see \Zend_Form_Element::init() For the method documentation.
|
* @see Zend_Form_Element::init() For the method documentation.
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
|
@ -5,23 +5,13 @@
|
|||||||
namespace Icinga\Web\Form\Element;
|
namespace Icinga\Web\Form\Element;
|
||||||
|
|
||||||
use Zend_Form_Element;
|
use Zend_Form_Element;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A note
|
* A note
|
||||||
*/
|
*/
|
||||||
class Note extends Zend_Form_Element
|
class Note extends Zend_Form_Element
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Disable default decorators
|
|
||||||
*
|
|
||||||
* \Icinga\Web\Form sets default decorators for elements.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*
|
|
||||||
* @see \Icinga\Web\Form::__construct() For default element decorators.
|
|
||||||
*/
|
|
||||||
protected $_disableLoadDefaultDecorators = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form view helper to use for rendering
|
* Form view helper to use for rendering
|
||||||
*
|
*
|
||||||
@ -36,6 +26,15 @@ class Note extends Zend_Form_Element
|
|||||||
*/
|
*/
|
||||||
protected $_ignore = true;
|
protected $_ignore = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (non-PHPDoc)
|
||||||
|
* @see Zend_Form_Element::init() For the method documentation.
|
||||||
|
*/
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
$this->setDecorators(Form::$defaultElementDecorators);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate element value (pseudo)
|
* Validate element value (pseudo)
|
||||||
*
|
*
|
||||||
|
@ -4,24 +4,13 @@
|
|||||||
|
|
||||||
namespace Icinga\Web\Form\Element;
|
namespace Icinga\Web\Form\Element;
|
||||||
|
|
||||||
use Zend_Form_Element;
|
use Icinga\Web\Form\FormElement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A number input control
|
* A number input control
|
||||||
*/
|
*/
|
||||||
class Number extends Zend_Form_Element
|
class Number extends FormElement
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Disable default decorators
|
|
||||||
*
|
|
||||||
* \Icinga\Web\Form sets default decorators for elements.
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*
|
|
||||||
* @see \Icinga\Web\Form::__construct() For default element decorators.
|
|
||||||
*/
|
|
||||||
protected $_disableLoadDefaultDecorators = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Form view helper to use for rendering
|
* Form view helper to use for rendering
|
||||||
*
|
*
|
||||||
|
62
library/Icinga/Web/Form/FormElement.php
Normal file
62
library/Icinga/Web/Form/FormElement.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
// {{{ICINGA_LICENSE_HEADER}}}
|
||||||
|
|
||||||
|
namespace Icinga\Web\Form;
|
||||||
|
|
||||||
|
use Zend_Form_Element;
|
||||||
|
use Icinga\Web\Form;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for Icinga Web 2 form elements
|
||||||
|
*/
|
||||||
|
class FormElement extends Zend_Form_Element
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Whether loading default decorators is disabled
|
||||||
|
*
|
||||||
|
* Icinga Web 2 loads its own default element decorators. For loading Zend's default element decorators set this
|
||||||
|
* property to false.
|
||||||
|
*
|
||||||
|
* @var null|bool
|
||||||
|
*/
|
||||||
|
protected $_disableLoadDefaultDecorators;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether loading default decorators is disabled
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function loadDefaultDecoratorsIsDisabled()
|
||||||
|
{
|
||||||
|
return $this->_disableLoadDefaultDecorators === true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load default decorators
|
||||||
|
*
|
||||||
|
* Icinga Web 2 loads its own default element decorators. For loading Zend's default element decorators set
|
||||||
|
* FormElement::$_disableLoadDefaultDecorators to false.
|
||||||
|
*
|
||||||
|
* @return this
|
||||||
|
* @see Form::$defaultElementDecorators For Icinga Web 2's default element decorators.
|
||||||
|
*/
|
||||||
|
public function loadDefaultDecorators()
|
||||||
|
{
|
||||||
|
if ($this->loadDefaultDecoratorsIsDisabled()) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! isset($this->_disableLoadDefaultDecorators)) {
|
||||||
|
$decorators = $this->getDecorators();
|
||||||
|
if (empty($decorators)) {
|
||||||
|
// Load Icinga Web 2's default element decorators
|
||||||
|
$this->addDecorators(Form::$defaultElementDecorators);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Load Zend's default decorators
|
||||||
|
parent::loadDefaultDecorators();
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user