From ff2b3704988dc3fd117f8b08e7a6b12331bafe44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IT=E5=B0=8F=E5=BC=BAxqitw=2Ecn?= <360237521@qq.com> Date: Tue, 5 Jun 2018 11:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E8=A1=8C=E8=A7=A3=E6=9E=90=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/ParseLine.php | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/lib/ParseLine.php diff --git a/src/lib/ParseLine.php b/src/lib/ParseLine.php new file mode 100644 index 0000000..4f6eb0d --- /dev/null +++ b/src/lib/ParseLine.php @@ -0,0 +1,74 @@ + $line[0], 'content' => $line[1]]; + } + + /** + * 解析param + * @param $line + * @return array + */ + public function parseLineParam($line) { + return [ + 'type' => 'param', + 'param_type' => $line[1], + 'param_name' => $line[2], + 'param_title' => $line[3], + 'param_default' => isset($line[4]) ? $line[4] : '无', + ]; + } + + /** + * 下划线命名转驼峰命名 + * @param $str - 下划线命名字符串 + * @param $is_first - 是否为大驼峰(即首字母也大写) + * @return mixed + */ + public function underlineToHump($str, $is_first = false) { + $str = preg_replace_callback('/([\-\_]+([a-z]{1}))/i', function ($matches) { + return strtoupper($matches[2]); + }, $str); + if ($is_first) { + $str = ucfirst($str); + } + return $str; + } + + /** + * 驼峰命名转下划线命名 + * @param $str + * @return mixed + */ + public function humpToUnderline($str) { + $str = preg_replace_callback('/([A-Z]{1})/', function ($matches) { + return '_' . strtolower($matches[0]); + }, $str); + $str = preg_replace('/^\_/', '', $str); + return $str; + } +} \ No newline at end of file