Skip to content

Commit

Permalink
Merge pull request #14 from ndj888/dev
Browse files Browse the repository at this point in the history
加入一些AnnotationFun
  • Loading branch information
ndj888 authored Dec 2, 2017
2 parents bc8eeda + aba97c7 commit 00d026e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/com_jjcbs/env/AnnotationConf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => ''
]
];
29 changes: 29 additions & 0 deletions src/com_jjcbs/fun/AnnotationFun.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

}
20 changes: 20 additions & 0 deletions src/com_jjcbs/lib/AnnotationMethodAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 00d026e

Please sign in to comment.