1: <?php
2:
3: 4: 5:
6: class Quform_Validator_Identical extends Quform_Validator_Abstract
7: {
8: const INVALID = 'identicalInvalid';
9: const NOT_SAME = 'notSame';
10:
11: 12: 13: 14: 15: 16: 17:
18: public function isValid($value)
19: {
20: $this->reset();
21:
22: if ( ! is_string($value)) {
23: $this->error(self::INVALID);
24: return false;
25: }
26:
27: $token = $this->config('token');
28:
29: if ($value !== $token) {
30: $this->error(self::NOT_SAME, compact('token', 'value'));
31: return false;
32: }
33:
34: return true;
35: }
36:
37: 38: 39: 40: 41: 42:
43: public static function getMessageTemplates($key = null)
44: {
45: $messageTemplates = array(
46: self::INVALID => __('Invalid data type, string expected', 'quform'),
47: self::NOT_SAME => __('The value does not match', 'quform')
48: );
49:
50: if (is_string($key)) {
51: return array_key_exists($key, $messageTemplates) ? $messageTemplates[$key] : null;
52: }
53:
54: return $messageTemplates;
55: }
56:
57: 58: 59: 60: 61: 62:
63: public static function getDefaultConfig($key = null)
64: {
65: $config = apply_filters('quform_default_config_validator_identical', array(
66: 'token' => '',
67: 'messages' => array(
68: self::INVALID => '',
69: self::NOT_SAME => ''
70: )
71: ));
72:
73: $config['type'] = 'identical';
74:
75: if (Quform::isNonEmptyString($key)) {
76: return Quform::get($config, $key);
77: }
78:
79: return $config;
80: }
81: }
82: