diff options
Diffstat (limited to '')
-rw-r--r-- | library/Director/Web/Form/Validate/NamePattern.php | 38 |
1 files changed, 38 insertions, 0 deletions
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; + } + } +} |