Use API client class in admin action, too

This commit is contained in:
Franz Liedke 2015-06-03 03:18:33 +02:00
parent 68f68171cc
commit ab18af34ff

View File

@ -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);
} }
} }