mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 07:03:35 +08:00
Use API client class in admin action, too
This commit is contained in:
parent
68f68171cc
commit
ab18af34ff
|
@ -1,16 +1,26 @@
|
||||||
<?php namespace Flarum\Admin\Actions;
|
<?php namespace Flarum\Admin\Actions;
|
||||||
|
|
||||||
|
use Flarum\Api\Client;
|
||||||
|
use Flarum\Support\Actor;
|
||||||
use Flarum\Support\HtmlAction;
|
use Flarum\Support\HtmlAction;
|
||||||
use Session;
|
use Session;
|
||||||
use Auth;
|
|
||||||
use Cookie;
|
use Cookie;
|
||||||
use Config;
|
use Config;
|
||||||
use DB;
|
use DB;
|
||||||
use Flarum\Api\Request as ApiRequest;
|
|
||||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
class IndexAction extends HtmlAction
|
class IndexAction extends HtmlAction
|
||||||
{
|
{
|
||||||
|
protected $apiClient;
|
||||||
|
|
||||||
|
protected $actor;
|
||||||
|
|
||||||
|
public function __construct(Client $apiClient, Actor $actor)
|
||||||
|
{
|
||||||
|
$this->apiClient = $apiClient;
|
||||||
|
$this->actor = $actor;
|
||||||
|
}
|
||||||
|
|
||||||
protected function render(Request $request, $routeParams = [])
|
protected function render(Request $request, $routeParams = [])
|
||||||
{
|
{
|
||||||
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
||||||
|
@ -24,13 +34,11 @@ class IndexAction extends HtmlAction
|
||||||
'token' => Cookie::get('flarum_remember')
|
'token' => Cookie::get('flarum_remember')
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = app('Flarum\Api\Actions\Users\ShowAction')
|
$response = $this->apiClient->send('Flarum\Api\Actions\Users\ShowAction', ['id' => $user->id]);
|
||||||
->handle(new ApiRequest(['id' => $user->id], $this->actor))
|
|
||||||
->content->toArray();
|
|
||||||
|
|
||||||
$data = [$response['data']];
|
$data = [$response->data];
|
||||||
if (isset($response['included'])) {
|
if (isset($response->included)) {
|
||||||
$data = array_merge($data, $response['included']);
|
$data = array_merge($data, $response->included);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user