2014-09-02 09:39:21 -04:00
|
|
|
<?php
|
2015-02-04 04:46:36 -05:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2014-09-02 09:39:21 -04:00
|
|
|
|
2014-11-14 04:57:14 -05:00
|
|
|
namespace Icinga\Forms\Config\Resource;
|
2014-09-02 09:39:21 -04:00
|
|
|
|
2015-03-06 03:49:15 -05:00
|
|
|
use Zend_Validate_Callback;
|
2014-09-02 09:39:21 -04:00
|
|
|
use Icinga\Web\Form;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Form class for adding/modifying file resources
|
|
|
|
|
*/
|
|
|
|
|
class FileResourceForm extends Form
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Initialize this form
|
|
|
|
|
*/
|
|
|
|
|
public function init()
|
|
|
|
|
{
|
|
|
|
|
$this->setName('form_config_resource_file');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Form::createElements()
|
|
|
|
|
*/
|
|
|
|
|
public function createElements(array $formData)
|
|
|
|
|
{
|
2014-09-29 05:20:39 -04:00
|
|
|
$this->addElement(
|
|
|
|
|
'text',
|
|
|
|
|
'name',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Resource Name'),
|
|
|
|
|
'description' => $this->translate('The unique name of this resource')
|
2014-09-29 05:20:39 -04:00
|
|
|
)
|
|
|
|
|
);
|
2014-09-03 06:21:31 -04:00
|
|
|
$this->addElement(
|
|
|
|
|
'text',
|
|
|
|
|
'filename',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Filepath'),
|
|
|
|
|
'description' => $this->translate('The filename to fetch information from'),
|
2015-02-11 03:51:28 -05:00
|
|
|
'validators' => array('ReadablePathValidator')
|
2014-09-02 09:39:21 -04:00
|
|
|
)
|
|
|
|
|
);
|
2015-03-06 03:49:15 -05:00
|
|
|
$callbackValidator = new Zend_Validate_Callback(function ($value) {
|
|
|
|
|
return @preg_match($value, '') !== false;
|
|
|
|
|
});
|
|
|
|
|
$callbackValidator->setMessage(
|
|
|
|
|
$this->translate('"%value%" is not a valid regular expression.'),
|
|
|
|
|
Zend_Validate_Callback::INVALID_VALUE
|
|
|
|
|
);
|
2014-09-03 06:21:31 -04:00
|
|
|
$this->addElement(
|
|
|
|
|
'text',
|
|
|
|
|
'fields',
|
|
|
|
|
array(
|
|
|
|
|
'required' => true,
|
2015-01-19 05:26:23 -05:00
|
|
|
'label' => $this->translate('Pattern'),
|
2015-03-06 03:49:15 -05:00
|
|
|
'description' => $this->translate('The pattern by which to identify columns.'),
|
|
|
|
|
'requirement' => $this->translate('The column pattern must be a valid regular expression.'),
|
|
|
|
|
'validators' => array($callbackValidator)
|
2014-09-03 06:21:31 -04:00
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $this;
|
2014-09-02 09:39:21 -04:00
|
|
|
}
|
|
|
|
|
}
|