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/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 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