Skip to content

Commit

Permalink
完善API获取文件路径
Browse files Browse the repository at this point in the history
  • Loading branch information
breath-co2 committed May 4, 2017
1 parent 1db2a33 commit c10d6c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static function loadAction($dir, $group = 'default')
$list = [];
foreach ((array)$dir as $item)
{
if (!is_dir($item))continue;
$item = rtrim($item, '/') . '/';
self::loadActionFileList($list, $item, strlen($item));
}
Expand Down
40 changes: 19 additions & 21 deletions src/WorkerAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ class WorkerAPI extends Worker
*/
public $prefixLength = 5;

/**
* API 文件所在目录, 默认为根目录下 api 目录
*
* @var string
*/
public $dir;

public $actionGroup = 'api';

public function __construct($server, $name)
Expand All @@ -36,20 +29,8 @@ public function __construct($server, $name)
}
$this->prefixLength = strlen($this->prefix);

if (isset($this->setting['dir']) && $this->setting['dir'])
{
$this->dir = $this->setting['dir'];
}
else
{
$this->dir = realpath(__DIR__ .'/../../../../') . '/api/';
}

# 读取列表
if (is_dir($this->dir))
{
Action::loadAction($this->dir, $this->actionGroup);
}
Action::loadAction($this->getActionPath(), $this->actionGroup);
}

/**
Expand Down Expand Up @@ -145,7 +126,7 @@ public function onRequest($request, $response)
*/
public function reloadAction($reloadAll = false)
{
return Action::reloadAction($this->dir, $this->actionGroup, $reloadAll);
return Action::reloadAction($this->getActionPath(), $this->actionGroup, $reloadAll);
}

/**
Expand Down Expand Up @@ -191,6 +172,23 @@ protected function uri($request)
return strtolower(trim($uri, '/'));
}

/**
* 获取目录
*
* @return array
*/
protected function getActionPath()
{
if (isset($this->setting['dir']) && $this->setting['dir'])
{
return (array)$this->setting['dir'];
}
else
{
return [realpath(__DIR__ . '/../../../../') . '/api/'];
}
}

/**
* 验证API是否通过
*
Expand Down

0 comments on commit c10d6c6

Please sign in to comment.