File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -736,7 +736,7 @@ public function must($value, $rule = null): bool
736736 */
737737 public function is ($ value , $ rule , array $ data = []): bool
738738 {
739- switch (App:: parseName ($ rule , 1 , false )) {
739+ switch ($ this -> parseName ($ rule , 1 , false )) {
740740 case 'require ' :
741741 // 必须
742742 $ result = !empty ($ value ) || '0 ' == $ value ;
@@ -1392,6 +1392,27 @@ protected function getScene(string $scene): void
13921392 }
13931393 }
13941394
1395+ /**
1396+ * 字符串命名风格转换
1397+ * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格
1398+ * @access protected
1399+ * @param string $name 字符串
1400+ * @param integer $type 转换类型
1401+ * @param bool $ucfirst 首字母是否大写(驼峰规则)
1402+ * @return string
1403+ */
1404+ protected function parseName (string $ name = null , int $ type = 0 , bool $ ucfirst = true ): string
1405+ {
1406+ if ($ type ) {
1407+ $ name = preg_replace_callback ('/_([a-zA-Z])/ ' , function ($ match ) {
1408+ return strtoupper ($ match [1 ]);
1409+ }, $ name );
1410+ return $ ucfirst ? ucfirst ($ name ) : lcfirst ($ name );
1411+ }
1412+
1413+ return strtolower (trim (preg_replace ("/[A-Z]/ " , "_ \\0 " , $ name ), "_ " ));
1414+ }
1415+
13951416 /**
13961417 * 动态方法 直接调用is方法进行验证
13971418 * @access public
You can’t perform that action at this time.
0 commit comments