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; } } }