2015-07-04 12:24:48 +09:30
|
|
|
<?php namespace Flarum\Api;
|
2015-06-03 02:39:01 +02:00
|
|
|
|
2015-07-04 12:24:48 +09:30
|
|
|
use Flarum\Core\Users\User;
|
2015-06-03 02:39:01 +02:00
|
|
|
use Illuminate\Contracts\Container\Container;
|
|
|
|
|
|
|
|
class Client
|
|
|
|
{
|
2015-07-04 12:24:48 +09:30
|
|
|
/**
|
|
|
|
* @var Container
|
|
|
|
*/
|
2015-06-03 02:39:01 +02:00
|
|
|
protected $container;
|
|
|
|
|
2015-07-04 12:24:48 +09:30
|
|
|
/**
|
|
|
|
* @param Container $container
|
|
|
|
*/
|
|
|
|
public function __construct(Container $container)
|
2015-06-03 02:39:01 +02:00
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the given API action class, pass the input and return its response.
|
|
|
|
*
|
2015-07-04 12:24:48 +09:30
|
|
|
* @param User $actor
|
2015-06-03 02:39:01 +02:00
|
|
|
* @param string $actionClass
|
|
|
|
* @param array $input
|
|
|
|
* @return object
|
|
|
|
*/
|
2015-07-04 12:24:48 +09:30
|
|
|
public function send(User $actor, $actionClass, array $input = [])
|
2015-06-03 02:39:01 +02:00
|
|
|
{
|
|
|
|
/** @var \Flarum\Api\Actions\JsonApiAction $action */
|
|
|
|
$action = $this->container->make($actionClass);
|
|
|
|
|
2015-07-04 12:24:48 +09:30
|
|
|
$response = $action->handle(new Request($input, $actor));
|
2015-06-03 02:39:01 +02:00
|
|
|
|
|
|
|
return json_decode($response->getBody());
|
|
|
|
}
|
|
|
|
}
|