1: <?php
2:
3: /**
4: * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
5: */
6: class Quform_Filter_Trim extends Quform_Filter_Abstract
7: {
8: /**
9: * Trims whitespace from the beginning and end of the given value
10: *
11: * If the value provided is not a string, the value will remain unfiltered
12: *
13: * @param string $value The value to filter
14: * @return string The filtered value
15: */
16: public function filter($value)
17: {
18: if ( ! is_string($value)) {
19: return $value;
20: }
21:
22: return trim($value);
23: }
24:
25: /**
26: * Get the default config for this filter
27: *
28: * @param string|null $key Get the config by key, if omitted the full config is returned
29: * @return array
30: */
31: public static function getDefaultConfig($key = null)
32: {
33: $config = apply_filters('quform_default_config_filter_trim', array());
34:
35: $config['type'] = 'trim';
36:
37: if (Quform::isNonEmptyString($key)) {
38: return Quform::get($config, $key);
39: }
40:
41: return $config;
42: }
43: }
44: