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 1818use ReflectionNamedType ;
1919use RuntimeException ;
2020use Toolkit \Stdlib \Helper \PhpHelper ;
21+ use Toolkit \Stdlib \Str \StringHelper ;
2122use Traversable ;
2223use UnexpectedValueException ;
2324use function base64_decode ;
@@ -57,18 +58,24 @@ class ObjectHelper
5758 * - 会先尝试用 setter 方法设置属性
5859 * - 再尝试直接设置属性
5960 *
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
6265 *
63- * @return object
66+ * @return T
6467 */
65- public static function init (object $ object , array $ options ): object
68+ public static function init (object $ object , array $ config , bool $ toCaml = false ): object
6669 {
67- foreach ($ options as $ property => $ value ) {
70+ foreach ($ config as $ property => $ value ) {
6871 if (is_numeric ($ property )) {
6972 continue ;
7073 }
7174
75+ if ($ toCaml ) {
76+ $ property = StringHelper::camelCase ($ property , false , '_ ' );
77+ }
78+
7279 $ setter = 'set ' . ucfirst ($ property );
7380
7481 // has setter
Original file line number Diff line number Diff line change @@ -167,24 +167,24 @@ public static function ucwords($str): string
167167
168168 /**
169169 * @param string $str
170- * @param bool $upperFirstChar
170+ * @param bool $upperFirst
171171 *
172- * @return mixed
172+ * @return string
173173 */
174- public static function camel (string $ str , bool $ upperFirstChar = false ): string
174+ public static function camel (string $ str , bool $ upperFirst = false ): string
175175 {
176- return self ::toCamelCase ($ str , $ upperFirstChar );
176+ return self ::toCamelCase ($ str , $ upperFirst );
177177 }
178178
179179 /**
180180 * @param string $str
181- * @param bool $upperFirstChar
181+ * @param bool $upperFirst
182182 *
183- * @return mixed
183+ * @return string
184184 */
185- public static function toCamel (string $ str , bool $ upperFirstChar = false ): string
185+ public static function toCamel (string $ str , bool $ upperFirst = false ): string
186186 {
187- return self ::toCamelCase ($ str , $ upperFirstChar );
187+ return self ::toCamelCase ($ str , $ upperFirst );
188188 }
189189
190190 /**
You can’t perform that action at this time.
0 commit comments