From 8ba99b8a59adacaebdb9bfaa8e582b076a132bf6 Mon Sep 17 00:00:00 2001 From: ndj888 Date: Fri, 1 Dec 2017 13:58:44 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E6=A8=A1=E6=9D=BF?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com_jjcbs/env/AnnotationConf.php | 14 ++++++++++++- .../lib/AnnotationMethodAbstract.php | 20 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/com_jjcbs/env/AnnotationConf.php b/src/com_jjcbs/env/AnnotationConf.php index c39579c..3c423b6 100644 --- a/src/com_jjcbs/env/AnnotationConf.php +++ b/src/com_jjcbs/env/AnnotationConf.php @@ -20,5 +20,17 @@ "com_jjcbs\\lib" => "src/com_jjcbs/lib" ], 'appPath' => COM_JJCBS_ROOT_PATH, - 'buildPath' => COM_JJCBS_ROOT_PATH . '/build/' + 'buildPath' => COM_JJCBS_ROOT_PATH . '/build/', + 'testConf' => [ + 'testDir' =>'', + 'testNamespace' => 'tests\cases' + ], + 'tplConf' => [ + //公共模板数据 + 'TPL_DATA' => [], + 'TPL_SIGN_START' => '{{', + 'TPL_SIGN_END' => '}}', + // tpl dir + 'TPL_DIR' => '' + ] ]; \ No newline at end of file diff --git a/src/com_jjcbs/lib/AnnotationMethodAbstract.php b/src/com_jjcbs/lib/AnnotationMethodAbstract.php index 335ff9d..40bbe2a 100644 --- a/src/com_jjcbs/lib/AnnotationMethodAbstract.php +++ b/src/com_jjcbs/lib/AnnotationMethodAbstract.php @@ -111,4 +111,24 @@ protected static function varMethodReplace(string $body){ self::$input = str_replace(self::METHOD_TEMPLATE , $body , self::$input); } + /** + * 简易模版解析 + * @param array $data + * @param string $tplName + * @param string $str + * @return string $str + */ + protected static function tplParse($data = [], $tplName = '', $str = '') + { + $data = array_merge(static::$config['tplConf']['TPL_DATA'], $data); + if (empty($str)) { + $fileName = static::$config['tplConf']['TPL_DIR'] . $tplName; + $str = file_get_contents($fileName); + } + foreach ($data as $k => $v) { + $k = static::$config['tplConf']['TPL_SIGN_START'] . $k . static::$config['tplConf']['TPL_SIGN_END']; + $str = str_replace($k, $v, $str); + } + return $str; + } } \ No newline at end of file From aba97c72b820cd4e840ff4cc0cad1714620f8747 Mon Sep 17 00:00:00 2001 From: ndj888 Date: Sat, 2 Dec 2017 11:52:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=B3=A8=E8=A7=A3=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com_jjcbs/fun/AnnotationFun.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/com_jjcbs/fun/AnnotationFun.php b/src/com_jjcbs/fun/AnnotationFun.php index 482e97a..53aca7f 100644 --- a/src/com_jjcbs/fun/AnnotationFun.php +++ b/src/com_jjcbs/fun/AnnotationFun.php @@ -93,4 +93,33 @@ public static function noParamType(string $str){ } return ''; } + + /** + * 解析数组类型值 + * @return array + * @param string $str + * 安卓:android|苹果:ios|全部:all + */ + public static function arrayValueParse(string $str) : array { + $data = []; + $tempArr = explode('|' , $str); + foreach ($tempArr as $v){ + $dataArr = explode(':' , $v); + $data[$dataArr[0]] = $dataArr[1]; + } + return $data; + } + + /** + * create dir by file + * @param $path + */ + public static function createFileDir($path) + { + if (!file_exists($path)) { + self::createFileDir(dirname($path)); + mkdir($path, 0777); + } + } + } \ No newline at end of file