Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/monitoring-list-duplicates-7057
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Fuhr committed Oct 6, 2014
2 parents a012276 + 2956d9e commit 5143c78
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 128 deletions.
4 changes: 2 additions & 2 deletions library/Icinga/Protocol/File/FileIterator.php
Expand Up @@ -4,15 +4,15 @@

namespace Icinga\Protocol\File;

use FilterIterator;
use Icinga\Util\EnumeratingFilterIterator;
use Icinga\Util\File;

/**
* Class FileIterator
*
* 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
Expand Down
5 changes: 1 addition & 4 deletions library/Icinga/Protocol/File/FileReader.php
Expand Up @@ -6,7 +6,6 @@

use Icinga\Data\Selectable;
use Countable;
use Icinga\Util\Enumerate;
use Zend_Config;

/**
Expand Down Expand Up @@ -53,9 +52,7 @@ public function __construct(Zend_Config $config)
*/
public function iterate()
{
return new Enumerate(
new FileIterator($this->filename, $this->fields)
);
return new FileIterator($this->filename, $this->fields);
}

/**
Expand Down
62 changes: 0 additions & 62 deletions library/Icinga/Util/Enumerate.php

This file was deleted.

37 changes: 37 additions & 0 deletions library/Icinga/Util/EnumeratingFilterIterator.php
@@ -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++;
}
}
46 changes: 31 additions & 15 deletions library/Icinga/Web/Form.php
Expand Up @@ -5,6 +5,7 @@
namespace Icinga\Web;

use LogicException;
use Zend_Config;
use Zend_Form;
use Zend_View_Interface;
use Icinga\Application\Icinga;
Expand Down Expand Up @@ -81,6 +82,19 @@ class Form extends Zend_Form
*/
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
*
Expand All @@ -105,16 +119,6 @@ public function __construct($options = null)
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);
}

Expand Down Expand Up @@ -417,23 +421,35 @@ public function addSubForm(Zend_Form $form, $name = null, $order = null)
/**
* 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 $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
*
* @see Zend_Form::createElement()
* @see Form::$defaultElementDecorators For Icinga Web 2's default element decorators.
*/
public function createElement($type, $name, $options = null)
{
if (is_array($options) && ! isset($options['disableLoadDefaultDecorators'])) {
$options['disableLoadDefaultDecorators'] = true;
if ($options !== null) {
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);

if ($el && $el->getAttrib('autosubmit')) {
$el->addDecorator(new NoScriptApply()); // Non-JS environments
$class = $el->getAttrib('class');
Expand Down
22 changes: 17 additions & 5 deletions library/Icinga/Web/Form/Element/CsrfCounterMeasure.php
Expand Up @@ -4,16 +4,16 @@

namespace Icinga\Web\Form\Element;

use Zend_Form_Element_Xhtml;
use Icinga\Web\Session;
use Icinga\Web\Form\FormElement;
use Icinga\Web\Form\InvalidCSRFTokenException;

/**
* CSRF counter measure element
*
* 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
Expand All @@ -22,14 +22,26 @@ class CsrfCounterMeasure extends Zend_Form_Element_Xhtml
*/
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
*/
public function init()
{
$this->setRequired(true); // Not requiring this element would not make any sense
$this->setIgnore(true); // We do not want this element's value being retrieved by Form::getValues()
$this->setDecorators(array('ViewHelper'));
$this->addDecorator('ViewHelper');
$this->setValue($this->generateCsrfToken());
}

Expand Down
20 changes: 4 additions & 16 deletions library/Icinga/Web/Form/Element/DateTimePicker.php
Expand Up @@ -5,27 +5,15 @@
namespace Icinga\Web\Form\Element;

use DateTime;
use Zend_Form_Element;
use Icinga\Web\Form;
use Icinga\Web\Form\FormElement;
use Icinga\Web\Form\Validator\DateTimeValidator;

/**
* 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
*
Expand Down Expand Up @@ -54,7 +42,7 @@ class DateTimePicker extends Zend_Form_Element

/**
* (non-PHPDoc)
* @see \Zend_Form_Element::init() For the method documentation.
* @see Zend_Form_Element::init() For the method documentation.
*/
public function init()
{
Expand Down
21 changes: 10 additions & 11 deletions library/Icinga/Web/Form/Element/Note.php
Expand Up @@ -5,23 +5,13 @@
namespace Icinga\Web\Form\Element;

use Zend_Form_Element;
use Icinga\Web\Form;

/**
* A note
*/
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
*
Expand All @@ -36,6 +26,15 @@ class Note extends Zend_Form_Element
*/
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)
*
Expand Down
15 changes: 2 additions & 13 deletions library/Icinga/Web/Form/Element/Number.php
Expand Up @@ -4,24 +4,13 @@

namespace Icinga\Web\Form\Element;

use Zend_Form_Element;
use Icinga\Web\Form\FormElement;

/**
* 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
*
Expand Down

0 comments on commit 5143c78

Please sign in to comment.