模型类DynamicModel主要用于实现模型内的数据验证yii2\base\DynamicModel.php
<span style="color: #008080;"> 1</span> <span style="color: #000000;">php </span><span style="color: #008080;"> 2</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;"> 3</span> <span style="color: #008000;"> * @link </span><span style="color: #008000; text-decoration: underline;">http://www.yiiframework.com/</span> <span style="color: #008080;"> 4</span> <span style="color: #008000;"> * @copyright Copyright (c) 2008 Yii Software LLC </span><span style="color: #008080;"> 5</span> <span style="color: #008000;"> * @license </span><span style="color: #008000; text-decoration: underline;">http://www.yiiframework.com/license/</span> <span style="color: #008080;"> 6</span> <span style="color: #008000;">*/</span> <span style="color: #008080;"> 7</span> <span style="color: #0000ff;">namespace</span> yii\<span style="color: #0000ff;">base</span><span style="color: #000000;">; </span><span style="color: #008080;"> 8</span> <span style="color: #008080;"> 9</span> <span style="color: #000000;">use yii\validators\Validator; </span><span style="color: #008080;"> 10</span> <span style="color: #008080;"> 11</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;"> 12</span> <span style="color: #008000;"> * DynamicModel is a model class primarily used to support ad hoc data validation. </span><span style="color: #008080;"> 13</span> <span style="color: #008000;"> * DynamicModel是一种主要用于支持ad hoc数据验证模型类 </span><span style="color: #008080;"> 14</span> <span style="color: #008000;"> * The typical usage of DynamicModel is as follows, </span><span style="color: #008080;"> 15</span> <span style="color: #008000;"> * </span><span style="color: #008080;"> 16</span> <span style="color: #008000;"> * ```php </span><span style="color: #008080;"> 17</span> <span style="color: #008000;"> * public function actionSearch($name, $email) </span><span style="color: #008080;"> 18</span> <span style="color: #008000;"> * { </span><span style="color: #008080;"> 19</span> <span style="color: #008000;"> * $model = DynamicModel::validateData(compact('name', 'email'), [ </span><span style="color: #008080;"> 20</span> <span style="color: #008000;"> * [['name', 'email'], 'string', 'max' => 128], </span><span style="color: #008080;"> 21</span> <span style="color: #008000;"> * ['email', 'email'], </span><span style="color: #008080;"> 22</span> <span style="color: #008000;"> * ]); </span><span style="color: #008080;"> 23</span> <span style="color: #008000;"> * if ($model->hasErrors()) { </span><span style="color: #008080;"> 24</span> <span style="color: #008000;"> * // validation fails </span><span style="color: #008080;"> 25</span> <span style="color: #008000;"> * } else { </span><span style="color: #008080;"> 26</span> <span style="color: #008000;"> * // validation succeeds </span><span style="color: #008080;"> 27</span> <span style="color: #008000;"> * } </span><span style="color: #008080;"> 28</span> <span style="color: #008000;"> * } </span><span style="color: #008080;"> 29</span> <span style="color: #008000;"> * ``` </span><span style="color: #008080;"> 30</span> <span style="color: #008000;"> * </span><span style="color: #008080;"> 31</span> <span style="color: #008000;"> * The above example shows how to validate `$name` and `$email` with the help of DynamicModel. </span><span style="color: #008080;"> 32</span> <span style="color: #008000;"> * 上面的例子演示了如何用DynamicModel验证用户名`$name`和邮箱`$email` </span><span style="color: #008080;"> 33</span> <span style="color: #008000;"> * The [[validateData()]] method creates an instance of DynamicModel, defines the attributes </span><span style="color: #008080;"> 34</span> <span style="color: #008000;"> * using the given data (`name` and `email` in this example), and then calls [[Model::validate()]]. </span><span style="color: #008080;"> 35</span> <span style="color: #008000;"> * validateData() 方法会创建一个 DynamicModel 的实例对象。通过给定数据定义模型特性,之后调用Model::validate() 方法。 </span><span style="color: #008080;"> 36</span> <span style="color: #008000;"> * You can check the validation result by [[hasErrors()]], like you do with a normal model. </span><span style="color: #008080;"> 37</span> <span style="color: #008000;"> * You may also access the dynamic attributes defined through the model instance, e.g., </span><span style="color: #008080;"> 38</span> <span style="color: #008000;"> * 可以通过[[hasErrors()]]方法获取验证结果 </span><span style="color: #008080;"> 39</span> <span style="color: #008000;"> * `$model->name` and `$model->email`. </span><span style="color: #008080;"> 40</span> <span style="color: #008000;"> * </span><span style="color: #008080;"> 41</span> <span style="color: #008000;"> * Alternatively, you may use the following more "classic" syntax to perform ad-hoc data validation: </span><span style="color: #008080;"> 42</span> <span style="color: #008000;"> * 除此之外,你也可以用如下的更加“classic(传统)”的语法来执行临时数据验 </span><span style="color: #008080;"> 43</span> <span style="color: #008000;"> * ```php </span><span style="color: #008080;"> 44</span> <span style="color: #008000;"> * $model = new DynamicModel(compact('name', 'email')); </span><span style="color: #008080;"> 45</span> <span style="color: #008000;"> * $model->addRule(['name', 'email'], 'string', ['max' => 128]) </span><span style="color: #008080;"> 46</span> <span style="color: #008000;"> * ->addRule('email', 'email') </span><span style="color: #008080;"> 47</span> <span style="color: #008000;"> * ->validate(); </span><span style="color: #008080;"> 48</span> <span style="color: #008000;"> * ``` </span><span style="color: #008080;"> 49</span> <span style="color: #008000;"> * </span><span style="color: #008080;"> 50</span> <span style="color: #008000;"> * DynamicModel implements the above ad-hoc data validation feature by supporting the so-called </span><span style="color: #008080;"> 51</span> <span style="color: #008000;"> * "dynamic attributes". It basically allows an attribute to be defined dynamically through its constructor </span><span style="color: #008080;"> 52</span> <span style="color: #008000;"> * or [[defineAttribute()]]. </span><span style="color: #008080;"> 53</span> <span style="color: #008000;"> * 实现了上述特殊数据模型验证功能支持的“动态属性”。允许通过它的构造函数或 [[defineAttribute()]]来定义一个属性 </span><span style="color: #008080;"> 54</span> <span style="color: #008000;"> * @author Qiang Xue <qiang.xue> </qiang.xue></span><span style="color: #008080;"> 55</span> <span style="color: #008000;"> * @since 2.0 </span><span style="color: #008080;"> 56</span> <span style="color: #008000;">*/</span> <span style="color: #008080;"> 57</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> DynamicModel extends Model </span><span style="color: #008080;"> 58</span> <span style="color: #000000;">{ </span><span style="color: #008080;"> 59</span> <span style="color: #0000ff;">private</span> $_attributes = [];<span style="color: #008000;">//</span><span style="color: #008000;">动态模型内动态属性</span> <span style="color: #008080;"> 60</span> <span style="color: #008080;"> 61</span> <span style="color: #008080;"> 62</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;"> 63</span> <span style="color: #008000;"> * Constructors.构造函数,用于将传入的属性赋值给_attributes,便于使用 </span><span style="color: #008080;"> 64</span> <span style="color: #008000;"> * @param array $attributes the dynamic attributes (name-value pairs, or names) being defined被定义的动态属性 </span><span style="color: #008080;"> 65</span> <span style="color: #008000;"> * @param array $config the configuration array to be applied to this object.用于该对象的配置数组。 </span><span style="color: #008080;"> 66</span> <span style="color: #008000;">*/</span> <span style="color: #008080;"> 67</span> <span style="color: #0000ff;">public</span> function __construct(array $attributes = [], $config =<span style="color: #000000;"> []) </span><span style="color: #008080;"> 68</span> <span style="color: #000000;"> { </span><span style="color: #008080;"> 69</span> <span style="color: #0000ff;">foreach</span> ($attributes <span style="color: #0000ff;">as</span> $name => $value) {<span style="color: #008000;">//</span><span style="color: #008000;">遍历传入的属性</span> <span style="color: #008080;"> 70</span> <span style="color: #0000ff;">if</span> (is_integer($name)) {<span style="color: #008000;">//</span><span style="color: #008000;">如果是整型,说明只传入了属性名,将属性名写入_attributes</span> <span style="color: #008080;"> 71</span> $<span style="color: #0000ff;">this</span>->_attributes[$value] = <span style="color: #0000ff;">null</span><span style="color: #000000;">; </span><span style="color: #008080;"> 72</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #008080;"> 73</span> $<span style="color: #0000ff;">this</span>->_attributes[$name] = $value;<span style="color: #008000;">//</span><span style="color: #008000;">按键值对的形式写入</span> <span style="color: #008080;"> 74</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 75</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 76</span> parent::__construct($config);<span style="color: #008000;">//</span><span style="color: #008000;">调用父类的配置</span> <span style="color: #008080;"> 77</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 78</span> <span style="color: #008080;"> 79</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;"> 80</span> <span style="color: #008000;"> * @inheritdoc 重写__get方法,从_attributes中取值 </span><span style="color: #008080;"> 81</span> <span style="color: #008000;">*/</span> <span style="color: #008080;"> 82</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function __get($name) </span><span style="color: #008080;"> 83</span> <span style="color: #000000;"> { </span><span style="color: #008080;"> 84</span> <span style="color: #0000ff;">if</span> (array_key_exists($name, $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes)) { </span><span style="color: #008080;"> 85</span> <span style="color: #008000;">//</span><span style="color: #008000;">如果传入的$name在数组_attributes中存在,则从_attributes中取值</span> <span style="color: #008080;"> 86</span> <span style="color: #0000ff;">return</span> $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes[$name]; </span><span style="color: #008080;"> 87</span> } <span style="color: #0000ff;">else</span> {<span style="color: #008000;">//</span><span style="color: #008000;">否则调用父类的__get方法取属性值</span> <span style="color: #008080;"> 88</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> parent::__get($name); </span><span style="color: #008080;"> 89</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 90</span> <span style="color: #000000;"> } </span><span style="color: #008080;"> 91</span> <span style="color: #008080;"> 92</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;"> 93</span> <span style="color: #008000;"> * @inheritdoc 重写__set方法,给_attributes设置值 </span><span style="color: #008080;"> 94</span> <span style="color: #008000;">*/</span> <span style="color: #008080;"> 95</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function __set($name, $value) </span><span style="color: #008080;"> 96</span> <span style="color: #000000;"> { </span><span style="color: #008080;"> 97</span> <span style="color: #0000ff;">if</span> (array_key_exists($name, $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes)) { </span><span style="color: #008080;"> 98</span> <span style="color: #008000;">//</span><span style="color: #008000;">如果传入的$name在数组_attributes中存在,则将动态属性$name的值设置为$value</span> <span style="color: #008080;"> 99</span> $<span style="color: #0000ff;">this</span>->_attributes[$name] =<span style="color: #000000;"> $value; </span><span style="color: #008080;">100</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #008080;">101</span> parent::__set($name, $value);<span style="color: #008000;">//</span><span style="color: #008000;">调用父类的__set方法设置属性值</span> <span style="color: #008080;">102</span> <span style="color: #000000;"> } </span><span style="color: #008080;">103</span> <span style="color: #000000;"> } </span><span style="color: #008080;">104</span> <span style="color: #008080;">105</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">106</span> <span style="color: #008000;"> * @inheritdoc 同上 重写__isset方法,判断_attributes中是否设置$name值 </span><span style="color: #008080;">107</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">108</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function __isset($name) </span><span style="color: #008080;">109</span> <span style="color: #000000;"> { </span><span style="color: #008080;">110</span> <span style="color: #0000ff;">if</span> (array_key_exists($name, $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes)) { </span><span style="color: #008080;">111</span> <span style="color: #0000ff;">return</span> isset($<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes[$name]); </span><span style="color: #008080;">112</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #008080;">113</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> parent::__isset($name); </span><span style="color: #008080;">114</span> <span style="color: #000000;"> } </span><span style="color: #008080;">115</span> <span style="color: #000000;"> } </span><span style="color: #008080;">116</span> <span style="color: #008080;">117</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">118</span> <span style="color: #008000;"> * @inheritdoc 同上,重写__unset方法,删除_attributes中的$name属性值 </span><span style="color: #008080;">119</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">120</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function __unset($name) </span><span style="color: #008080;">121</span> <span style="color: #000000;"> { </span><span style="color: #008080;">122</span> <span style="color: #0000ff;">if</span> (array_key_exists($name, $<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes)) { </span><span style="color: #008080;">123</span> unset($<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes[$name]); </span><span style="color: #008080;">124</span> } <span style="color: #0000ff;">else</span><span style="color: #000000;"> { </span><span style="color: #008080;">125</span> <span style="color: #000000;"> parent::__unset($name); </span><span style="color: #008080;">126</span> <span style="color: #000000;"> } </span><span style="color: #008080;">127</span> <span style="color: #000000;"> } </span><span style="color: #008080;">128</span> <span style="color: #008080;">129</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">130</span> <span style="color: #008000;"> * Defines an attribute. 定义动态属性的方法 </span><span style="color: #008080;">131</span> <span style="color: #008000;"> * @param string $name the attribute name 属性名 </span><span style="color: #008080;">132</span> <span style="color: #008000;"> * @param mixed $value the attribute value 属性值 </span><span style="color: #008080;">133</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">134</span> <span style="color: #0000ff;">public</span> function defineAttribute($name, $value = <span style="color: #0000ff;">null</span><span style="color: #000000;">) </span><span style="color: #008080;">135</span> <span style="color: #000000;"> { </span><span style="color: #008080;">136</span> $<span style="color: #0000ff;">this</span>->_attributes[$name] =<span style="color: #000000;"> $value; </span><span style="color: #008080;">137</span> <span style="color: #000000;"> } </span><span style="color: #008080;">138</span> <span style="color: #008080;">139</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">140</span> <span style="color: #008000;"> * Undefines an attribute. 用于删除动态属性的方法 </span><span style="color: #008080;">141</span> <span style="color: #008000;"> * @param string $name the attribute name 属性名 </span><span style="color: #008080;">142</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">143</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function undefineAttribute($name) </span><span style="color: #008080;">144</span> <span style="color: #000000;"> { </span><span style="color: #008080;">145</span> unset($<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes[$name]); </span><span style="color: #008080;">146</span> <span style="color: #000000;"> } </span><span style="color: #008080;">147</span> <span style="color: #008080;">148</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">149</span> <span style="color: #008000;"> * Adds a validation rule to this model. 添加验证规则 </span><span style="color: #008080;">150</span> <span style="color: #008000;"> * You can also directly manipulate [[validators]] to add or remove validation rules. </span><span style="color: #008080;">151</span> <span style="color: #008000;"> * This method provides a shortcut. </span><span style="color: #008080;">152</span> <span style="color: #008000;"> * 可以直接调用[[validators]]来添加或者删除验证规则,本方法提供了一个短方法 </span><span style="color: #008080;">153</span> <span style="color: #008000;"> * @param string|array $attributes the attribute(s) to be validated by the rule 进行验证的属性 </span><span style="color: #008080;">154</span> <span style="color: #008000;"> * @param mixed $validator the validator for the rule.This can be a built-in validator name, </span><span style="color: #008080;">155</span> <span style="color: #008000;"> * a method name of the model class, an anonymous function, or a validator class name. </span><span style="color: #008080;">156</span> <span style="color: #008000;"> * 规则的验证。这是一个内置验证器的名字, 一个模型类的方法名,一个匿名函数或一个验证器类的名称。 </span><span style="color: #008080;">157</span> <span style="color: #008000;"> * @param array $options the options (name-value pairs) to be applied to the validator </span><span style="color: #008080;">158</span> <span style="color: #008000;"> * (name-value)被应用到验证器 </span><span style="color: #008080;">159</span> <span style="color: #008000;"> * @return static the model itself 模型本身 </span><span style="color: #008080;">160</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">161</span> <span style="color: #0000ff;">public</span> function addRule($attributes, $validator, $options =<span style="color: #000000;"> []) </span><span style="color: #008080;">162</span> <span style="color: #000000;"> { </span><span style="color: #008080;">163</span> $validators = $<span style="color: #0000ff;">this</span>->getValidators();<span style="color: #008000;">//</span><span style="color: #008000;">所有的验证规则对象 </span><span style="color: #008080;">164</span> <span style="color: #008000;">//</span><span style="color: #008000;">生成Validator对象,并且插入 $validators中</span> <span style="color: #008080;">165</span> $validators->append(Validator::createValidator($validator, $<span style="color: #0000ff;">this</span><span style="color: #000000;">, (array) $attributes, $options)); </span><span style="color: #008080;">166</span> <span style="color: #008080;">167</span> <span style="color: #0000ff;">return</span> $<span style="color: #0000ff;">this</span><span style="color: #000000;">; </span><span style="color: #008080;">168</span> <span style="color: #000000;"> } </span><span style="color: #008080;">169</span> <span style="color: #008080;">170</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">171</span> <span style="color: #008000;"> * Validates the given data with the specified validation rules.通过指定的规则验证给定的数据 </span><span style="color: #008080;">172</span> <span style="color: #008000;"> * This method will create a DynamicModel instance, populate it with the data to be validated, </span><span style="color: #008080;">173</span> <span style="color: #008000;"> * create the specified validation rules, and then validate the data using these rules. </span><span style="color: #008080;">174</span> <span style="color: #008000;"> * @param array $data the data (name-value pairs) to be validated </span><span style="color: #008080;">175</span> <span style="color: #008000;"> * @param array $rules the validation rules. Please refer to [[Model::rules()]] on the format of this parameter. </span><span style="color: #008080;">176</span> <span style="color: #008000;"> * @return static the model instance that contains the data being validated </span><span style="color: #008080;">177</span> <span style="color: #008000;"> * @throws InvalidConfigException if a validation rule is not specified correctly. </span><span style="color: #008080;">178</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">179</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> function validateData(array $data, $rules =<span style="color: #000000;"> []) </span><span style="color: #008080;">180</span> <span style="color: #000000;"> { </span><span style="color: #008080;">181</span> <span style="color: #008000;">/*</span><span style="color: #008000;"> @var $model DynamicModel </span><span style="color: #008000;">*/</span> <span style="color: #008080;">182</span> $model = <span style="color: #0000ff;">new</span> <span style="color: #0000ff;">static</span>($data);<span style="color: #008000;">//</span><span style="color: #008000;">实例化调用类,将$data赋值给_attributes</span> <span style="color: #008080;">183</span> <span style="color: #0000ff;">if</span> (!<span style="color: #000000;">empty($rules)) { </span><span style="color: #008080;">184</span> $validators = $model->getValidators();<span style="color: #008000;">//</span><span style="color: #008000;">获取所有定义的验证规则</span> <span style="color: #008080;">185</span> <span style="color: #0000ff;">foreach</span> ($rules <span style="color: #0000ff;">as</span><span style="color: #000000;"> $rule) { </span><span style="color: #008080;">186</span> <span style="color: #0000ff;">if</span><span style="color: #000000;"> ($rule instanceof Validator) { </span><span style="color: #008080;">187</span> $validators->append($rule);<span style="color: #008000;">//</span><span style="color: #008000;">如果$rule是Validator的实例,则添加到$validators中</span> <span style="color: #008080;">188</span> } elseif (is_array($rule) && isset($rule[<span style="color: #800080;">0</span>], $rule[<span style="color: #800080;">1</span>])) { <span style="color: #008000;">//</span><span style="color: #008000;"> attributes, validator type </span><span style="color: #008080;">189</span> <span style="color: #008000;">//</span><span style="color: #008000;">如果$rule是数组,则判断动态属性和验证类型是否存在,创建Validator对象,添加到$validators中</span> <span style="color: #008080;">190</span> $validator = Validator::createValidator($rule[<span style="color: #800080;">1</span>], $model, (array) $rule[<span style="color: #800080;">0</span>], array_slice($rule, <span style="color: #800080;">2</span><span style="color: #000000;">)); </span><span style="color: #008080;">191</span> $validators-><span style="color: #000000;">append($validator); </span><span style="color: #008080;">192</span> } <span style="color: #0000ff;">else</span> {<span style="color: #008000;">//</span><span style="color: #008000;">抛出异常</span> <span style="color: #008080;">193</span> <span style="color: #0000ff;">throw</span> <span style="color: #0000ff;">new</span> InvalidConfigException(<span style="color: #800000;">'</span><span style="color: #800000;">Invalid validation rule: a rule must specify both attribute names and validator type.</span><span style="color: #800000;">'</span><span style="color: #000000;">); </span><span style="color: #008080;">194</span> <span style="color: #000000;"> } </span><span style="color: #008080;">195</span> <span style="color: #000000;"> } </span><span style="color: #008080;">196</span> <span style="color: #000000;"> } </span><span style="color: #008080;">197</span> <span style="color: #008080;">198</span> $model->validate();<span style="color: #008000;">//</span><span style="color: #008000;">执行验证</span> <span style="color: #008080;">199</span> <span style="color: #008080;">200</span> <span style="color: #0000ff;">return</span><span style="color: #000000;"> $model; </span><span style="color: #008080;">201</span> <span style="color: #000000;"> } </span><span style="color: #008080;">202</span> <span style="color: #008080;">203</span> <span style="color: #008000;">/*</span><span style="color: #008000;">* </span><span style="color: #008080;">204</span> <span style="color: #008000;"> * @inheritdoc 返回所有的动态属性 </span><span style="color: #008080;">205</span> <span style="color: #008000;">*/</span> <span style="color: #008080;">206</span> <span style="color: #0000ff;">public</span><span style="color: #000000;"> function attributes() </span><span style="color: #008080;">207</span> <span style="color: #000000;"> { </span><span style="color: #008080;">208</span> <span style="color: #0000ff;">return</span> array_keys($<span style="color: #0000ff;">this</span>-><span style="color: #000000;">_attributes); </span><span style="color: #008080;">209</span> <span style="color: #000000;"> } </span><span style="color: #008080;">210</span> }