1: <?php
 2: 
 3: /**
 4:  * @copyright Copyright (c) 2009-2022 ThemeCatcher (https://www.themecatcher.net)
 5:  */
 6: abstract class Quform_Filter_Abstract implements Quform_Filter_Interface
 7: {
 8:     /**
 9:      * The filter settings
10:      *
11:      * @var array
12:      */
13:     protected $config = array();
14: 
15:     /**
16:      * @param array $options
17:      */
18:     public function __construct(array $options = array())
19:     {
20:         $this->setConfig($options);
21:     }
22: 
23:     /**
24:      * Returns the config value for the given $key
25:      *
26:      * @param   string|null  $key
27:      * @param   null|mixed   $default
28:      * @return  mixed        The config value or $default if not set
29:      */
30:     public function config($key = null, $default = null)
31:     {
32:         $value = Quform::get($this->config, $key, $default);
33: 
34:         if ($value === null) {
35:             $value = Quform::get(call_user_func(array(get_class($this), 'getDefaultConfig')), $key, $default);
36:         }
37: 
38:         return $value;
39:     }
40: 
41:     /**
42:      * Set the config value for the given $key or multiple values using an array
43:      *
44:      * @param   string|array  $key    Key or array of key/values
45:      * @param   mixed         $value  Value or null if $key is array
46:      * @return  $this
47:      */
48:     public function setConfig($key, $value = null)
49:     {
50:         if (is_array($key)) {
51:             foreach ($key as $k => $v) {
52:                 $this->config[$k] = $v;
53:             }
54:         } else {
55:             $this->config[$key] = $value;
56:         }
57: 
58:         return $this;
59:     }
60: }
61: