diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/Web/Form/Validate | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/Director/Web/Form/Validate/IsDataListEntry.php | 55 | ||||
-rw-r--r-- | library/Director/Web/Form/Validate/NamePattern.php | 38 |
2 files changed, 93 insertions, 0 deletions
diff --git a/library/Director/Web/Form/Validate/IsDataListEntry.php b/library/Director/Web/Form/Validate/IsDataListEntry.php new file mode 100644 index 0000000..5762d2e --- /dev/null +++ b/library/Director/Web/Form/Validate/IsDataListEntry.php @@ -0,0 +1,55 @@ +<?php + +namespace Icinga\Module\Director\Web\Form\Validate; + +use Icinga\Module\Director\Db; +use Icinga\Module\Director\Objects\DirectorDatalistEntry; +use Zend_Validate_Abstract; + +class IsDataListEntry extends Zend_Validate_Abstract +{ + const INVALID = 'intInvalid'; + + /** @var Db */ + private $db; + + /** @var int */ + private $dataListId; + + public function __construct($dataListId, Db $db) + { + $this->db = $db; + $this->dataListId = (int) $dataListId; + } + + public function isValid($value) + { + if (is_array($value)) { + foreach ($value as $name) { + if (! $this->isListEntry($name)) { + $this->_error(self::INVALID, $value); + + return false; + } + } + + return true; + } + + if ($this->isListEntry($value)) { + return true; + } else { + $this->_error(self::INVALID, $value); + + return false; + } + } + + protected function isListEntry($name) + { + return DirectorDatalistEntry::exists([ + 'list_id' => $this->dataListId, + 'entry_name' => $name, + ], $this->db); + } +} diff --git a/library/Director/Web/Form/Validate/NamePattern.php b/library/Director/Web/Form/Validate/NamePattern.php new file mode 100644 index 0000000..fac44d9 --- /dev/null +++ b/library/Director/Web/Form/Validate/NamePattern.php @@ -0,0 +1,38 @@ +<?php + +namespace Icinga\Module\Director\Web\Form\Validate; + +use Icinga\Module\Director\Restriction\MatchingFilter; +use Zend_Validate_Abstract; + +class NamePattern extends Zend_Validate_Abstract +{ + const INVALID = 'intInvalid'; + + private $filter; + + public function __construct($pattern) + { + if (! is_array($pattern)) { + $pattern = [$pattern]; + } + + $this->filter = MatchingFilter::forPatterns($pattern, 'value'); + + $this->_messageTemplates[self::INVALID] = sprintf( + 'Does not match %s', + (string) $this->filter + ); + } + + public function isValid($value) + { + if ($this->filter->matches((object) ['value' => $value])) { + return true; + } else { + $this->_error(self::INVALID, $value); + + return false; + } + } +} |