Skip to content

Commit

Permalink
模板bug
Browse files Browse the repository at this point in the history
  • Loading branch information
hurongsheng committed Dec 29, 2016
1 parent afe0249 commit 6b788f4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
7 changes: 5 additions & 2 deletions Controllers/RouteDocController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ protected function replaceHtml($tr, $key, $value = "", $desc = "")
/**
* @description test route
* @param Request $request
* @request $id route_doc_id
* @request $body request body
* @request $headers request headers=[]
* @author hurs
*/
public function postTestRoute(Request $request)
Expand Down Expand Up @@ -204,9 +207,9 @@ protected function formatUrl(Request $request, RouteDocModel $model)
* @description update from route.php
* @author hurs
*/
public function postRefresh()
public function anyRefresh()
{
$doc = new RouteDoc();
$doc->refresh();
return $doc->refresh();
}
}
2 changes: 2 additions & 0 deletions Migrations/2016_12_09_105009_create_route_cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function up()
$table->string('env');
$table->string('domain');
$table->string('uri');
$table->string('route_uri');
$table->string('method');
$table->string('as');
$table->string('uses');
Expand All @@ -37,6 +38,7 @@ public function up()
$table->dateTime('created_at');
$table->dateTime('updated_at');
$table->index(['env', 'domain', 'uri', 'method']);
$table->index(['env', 'domain', 'route_uri', 'method']);
$table->index(['env', 'method']);
$table->index(['env', 'state']);
$table->index(['env', 'controller_name']);
Expand Down
9 changes: 5 additions & 4 deletions Models/RouteDocModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RouteDocModel extends Eloquent
protected $table = 'route_doc';
protected $casts = ['where' => 'array', 'test_data' => 'array', 'params' => 'array'];
protected $fillable = [
'domain', 'uri', 'method'
'domain', 'route_uri', 'method', 'env'
];

public function __construct(array $attributes = [])
Expand All @@ -21,12 +21,13 @@ public function __construct(array $attributes = [])
$this->connection = config('route_doc.table_connection', config('database.default'));
}

public static function getUnique($domain, $uri, $method)
public static function getUnique($domain, $uri, $method, $env)
{
return static::firstOrNew([
'domain' => $domain,
'uri' => $uri,
'method' => $method
'route_uri' => $uri,
'method' => $method,
'env' => $env
]);
}

Expand Down
47 changes: 25 additions & 22 deletions RouteDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,27 @@ public function refresh()
foreach ($routes as $route) {
$this->analyseRoute($route, $method_need, $docs);
}
$this->create($docs);
return $this->create($docs);
}

protected function create($docs)
{
$ids = [];
foreach ($docs as $doc) {
$model = RouteDocModel::getUnique($doc['domain'], $doc['uri'], $doc['method'], App::environment());
foreach ($doc as $key => $value) {
$model->$key = $value;
}
$model->state = RouteDocModel::STATE_WORK;
$model->save();
$ids[] = $model->id;
}
if ($ids) {
$clear = RouteDocModel::clearExcept($ids, App::environment());
} else {
$clear = 0;
}
return ['count' => count($docs), 'clear' => $clear];
}

public static function handleModel(RouteDocModel $model)
Expand Down Expand Up @@ -107,38 +127,21 @@ public static function matchUri(RouteDocModel $model, &$uri_params = [])
return preg_match_all('/(?<=[{])[\S]+?(?=[}])/u', $model->uri, $uri_params);
}

protected function create($docs)
{
$ids = [];
foreach ($docs as $doc) {
$model = RouteDocModel::getUnique($doc['domain'], $doc['uri'], $doc['method']);
foreach ($doc as $key => $value) {
$model->$key = $value;
}
$model->state = RouteDocModel::STATE_WORK;
$model->env = App::environment();
$model->save();
$ids[] = $model->id;
}
if ($ids) {
RouteDocModel::clearExcept($ids, App::environment());
}
}

protected function analyseRoute($route, $method_need, &$docs = [])
{
$methods = $route->getMethods();
$action = $route->getAction();
$wheres = RouteTransClass::getInstance($route)->getWheres() ? : [];
$wheres = RouteTransClass::getInstance($route)->getWheres();
$uri = $this->handleUri($route->getUri());
$action['uri'] = $uri;
foreach ($methods as $method) {
if (!in_array($method, $method_need)) {
continue;
}
$doc['domain'] = $action['domain'] ? : '';
$doc['uri'] = $uri;
$doc['method'] = $method;
$doc['uri'] = $uri ? : '';
$doc['method'] = $method ? : '';
$doc['as'] = $action['as'] ? : '';
if ($action['uses'] instanceof Closure) {
$doc['uses'] = 'Closure';
Expand All @@ -158,7 +161,7 @@ protected function analyseRoute($route, $method_need, &$docs = [])
}
$doc['namespace'] = $action['namespace'] ? : "";
$doc['prefix'] = $action['prefix'] ? : '';
$doc['where'] = $wheres;
$doc['where'] = $wheres ? : [];
$docs[] = $doc;
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hurongsheng/laravel-route-doc",
"type": "library",
"description": "easily create doc based on route.php",
"version": "2.1.2",
"version": "2.1.4",
"keywords": [
"laravel",
"route",
Expand Down

0 comments on commit 6b788f4

Please sign in to comment.