File tree Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Expand file tree Collapse file tree 2 files changed +20
-13
lines changed Original file line number Diff line number Diff line change 18
18
use ReflectionNamedType ;
19
19
use RuntimeException ;
20
20
use Toolkit \Stdlib \Helper \PhpHelper ;
21
+ use Toolkit \Stdlib \Str \StringHelper ;
21
22
use Traversable ;
22
23
use UnexpectedValueException ;
23
24
use function base64_decode ;
@@ -57,18 +58,24 @@ class ObjectHelper
57
58
* - 会先尝试用 setter 方法设置属性
58
59
* - 再尝试直接设置属性
59
60
*
60
- * @param object $object An object instance
61
- * @param array $options
61
+ * @template T object
62
+ * @param T $object An object instance
63
+ * @param array $config
64
+ * @param bool $toCaml
62
65
*
63
- * @return object
66
+ * @return T
64
67
*/
65
- public static function init (object $ object , array $ options ): object
68
+ public static function init (object $ object , array $ config , bool $ toCaml = false ): object
66
69
{
67
- foreach ($ options as $ property => $ value ) {
70
+ foreach ($ config as $ property => $ value ) {
68
71
if (is_numeric ($ property )) {
69
72
continue ;
70
73
}
71
74
75
+ if ($ toCaml ) {
76
+ $ property = StringHelper::camelCase ($ property , false , '_ ' );
77
+ }
78
+
72
79
$ setter = 'set ' . ucfirst ($ property );
73
80
74
81
// has setter
Original file line number Diff line number Diff line change @@ -167,24 +167,24 @@ public static function ucwords($str): string
167
167
168
168
/**
169
169
* @param string $str
170
- * @param bool $upperFirstChar
170
+ * @param bool $upperFirst
171
171
*
172
- * @return mixed
172
+ * @return string
173
173
*/
174
- public static function camel (string $ str , bool $ upperFirstChar = false ): string
174
+ public static function camel (string $ str , bool $ upperFirst = false ): string
175
175
{
176
- return self ::toCamelCase ($ str , $ upperFirstChar );
176
+ return self ::toCamelCase ($ str , $ upperFirst );
177
177
}
178
178
179
179
/**
180
180
* @param string $str
181
- * @param bool $upperFirstChar
181
+ * @param bool $upperFirst
182
182
*
183
- * @return mixed
183
+ * @return string
184
184
*/
185
- public static function toCamel (string $ str , bool $ upperFirstChar = false ): string
185
+ public static function toCamel (string $ str , bool $ upperFirst = false ): string
186
186
{
187
- return self ::toCamelCase ($ str , $ upperFirstChar );
187
+ return self ::toCamelCase ($ str , $ upperFirst );
188
188
}
189
189
190
190
/**
You can’t perform that action at this time.
0 commit comments