Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
style(Request): Move route as a part of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rhilip committed Apr 20, 2020
1 parent 2c4459c commit f63ed00
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- **Requests:** Make Request Component extends from `Symfony\Component\HttpFoundation\Request` (9cd715b)
- **Torrent:** Per-add torrent edit (f06b342)
- **Torrents:** Allow search in user's favour (or you can say bookmark) (c0aa627)
- **Validator:** Add magic function __get() as alias of getInput() (86e69f7)
- **composer:** Add `nesbot/carbon` to deal with Date and Time (9e37c41)
- **i18n:** Use symfony/translation and JSON format for locale (02cc251)
- **layout:** Add anti-robots html meta tag (9c21e73)
Expand Down
2 changes: 1 addition & 1 deletion application/Controllers/TrackerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function actionIndex()

$this->blockClient();

$action = strtolower(app()->request->route('{tracker_action}'));
$action = strtolower(app()->request->attributes->get('route')['{tracker_action}']);
$this->checkUserAgent($action == 'scrape');

$this->checkPasskey($userInfo);
Expand Down
2 changes: 1 addition & 1 deletion framework/Http/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function runAction($method, $action)
foreach ($result as $item) {
list($route, $queryParams) = $item;
// 路由参数导入请求类
\Rid::app()->request->setRoute($queryParams);
\Rid::app()->request->attributes->set('route', $queryParams);
// 实例化控制器
list($shortClass, $shortAction) = $route;
$controllerDir = \Rid\Helpers\FileSystemHelper::dirname($shortClass);
Expand Down
18 changes: 2 additions & 16 deletions framework/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Request extends HttpFoundationRequest implements Base\StaticInstanceInterf
use Base\StaticInstanceTrait, Base\ComponentTrait;

protected \Swoole\Http\Request $_swoole_request;
protected $_route = [];

/**
* Uploaded files from Swoole.
Expand All @@ -23,8 +22,6 @@ class Request extends HttpFoundationRequest implements Base\StaticInstanceInterf
*/
public $raw_files;

public $start_at;

/** @noinspection PhpMissingParentConstructorInspection */
public function __construct($config = [])
{
Expand All @@ -44,8 +41,8 @@ private function setTrustedField($config = [])
// 设置请求对象
public function setRequester(\Swoole\Http\Request $request)
{
$start_at = microtime(true);
$this->_swoole_request = $request;
$this->start_at = microtime(true);

$server = \array_change_key_case($request->server, CASE_UPPER);

Expand All @@ -57,7 +54,7 @@ public function setRequester(\Swoole\Http\Request $request)
$this->initialize(
$request->get ?? [],
$request->post ?? [],
[],
['start_at' => $start_at],
$request->cookie ?? [],
$request->files ?? [],
$server,
Expand All @@ -66,17 +63,6 @@ public function setRequester(\Swoole\Http\Request $request)
$this->raw_files = $request->files;
}

// 设置 ROUTE 值
public function setRoute($route)
{
$this->_route = $route;
}

public function route($name = null, $default = null)
{
return is_null($name) ? $this->_route : ($this->_route[$name] ?? $default);
}

public function getSwooleRequest(): \Swoole\Http\Request
{
return $this->_swoole_request;
Expand Down
2 changes: 1 addition & 1 deletion templates/layout/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
&copy; <a href="/" target="_self"><?= config('base.site_name') ?></a> 2019-2020 Powered by <a href="https://github.com/Rhilip/RidPT" target="_blank">RidPT</a>
</p>
<p class="debug-info">
[ Page created in <b><?= number_format(microtime(true) - app()->request->start_at, 6) ?></b> sec
[ Page created in <b><?= number_format(microtime(true) - app()->request->attributes->get('start_at'), 6) ?></b> sec
with <b><?= $this->e(memory_get_usage(), 'format_bytes') ?></b> ram used,
<b><?= count(app()->pdo->getExecuteData()) ?></b> db queries,
<b><?= array_sum(app()->redis->getCalledData())?></b> calls of Redis ]
Expand Down

0 comments on commit f63ed00

Please sign in to comment.