RegExp.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
16 
17 /**
18  * RegExp validates against the given regular expression.
19  *
20  * Configuration example:
21  * @code
22  * // integer or empty
23  * regexp:{"pattern":"^[0-9]*$"}
24  * @endcode
25  *
26  * @author ingo herwig <ingo@wemove.com>
27  */
28 class RegExp implements ValidateType {
29 
30  /**
31  * @see ValidateType::validate
32  * $options is an associative array with key 'pattern'
33  */
34  public function validate($value, Message $message, $options=null) {
35  if (!isset($options['pattern'])) {
36  throw new ConfigurationException($message->getText("No 'pattern' given in regexp options: %1%"),
37  array(json_encode($options)));
38  }
39  return preg_match("/".$options['pattern']."/m", $value);
40  }
41 }
42 ?>
ValidateType defines the interface for all validator classes.
Message is used to get localized messages to be used in the user interface.
Definition: Message.php:23
getText($message, $parameters=null, $lang='')
Get a localized string.
RegExp validates against the given regular expression.
Definition: RegExp.php:28
ConfigurationException signals an exception in the configuration.
validate($value, Message $message, $options=null)
Definition: RegExp.php:34