2015-08-26 14:48:58 +08:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Flarum\Api;
|
2015-06-03 08:39:01 +08:00
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
use Flarum\Core\Users\User;
|
2015-06-03 08:39:01 +08:00
|
|
|
use Illuminate\Contracts\Container\Container;
|
|
|
|
|
|
|
|
class Client
|
|
|
|
{
|
2015-07-04 10:54:48 +08:00
|
|
|
/**
|
|
|
|
* @var Container
|
|
|
|
*/
|
2015-06-03 08:39:01 +08:00
|
|
|
protected $container;
|
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
/**
|
|
|
|
* @param Container $container
|
|
|
|
*/
|
|
|
|
public function __construct(Container $container)
|
2015-06-03 08:39:01 +08:00
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the given API action class, pass the input and return its response.
|
|
|
|
*
|
2015-07-04 10:54:48 +08:00
|
|
|
* @param User $actor
|
2015-06-03 08:39:01 +08:00
|
|
|
* @param string $actionClass
|
|
|
|
* @param array $input
|
|
|
|
* @return object
|
|
|
|
*/
|
2015-07-04 10:54:48 +08:00
|
|
|
public function send(User $actor, $actionClass, array $input = [])
|
2015-06-03 08:39:01 +08:00
|
|
|
{
|
|
|
|
/** @var \Flarum\Api\Actions\JsonApiAction $action */
|
|
|
|
$action = $this->container->make($actionClass);
|
|
|
|
|
2015-07-04 10:54:48 +08:00
|
|
|
$response = $action->handle(new Request($input, $actor));
|
2015-06-03 08:39:01 +08:00
|
|
|
|
2015-07-07 13:59:21 +08:00
|
|
|
return new Response($response);
|
2015-06-03 08:39:01 +08:00
|
|
|
}
|
|
|
|
}
|