Created
March 10, 2017 10:32
-
-
Save jrdnrc/ab5a351b3213f9c86821db2fb5fd0a1d to your computer and use it in GitHub Desktop.
Invokable Controllers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types = 1); | |
namespace App\Http\Controllers\Api; | |
use App\CommandBus; | |
use App\Commands\LogRequest; | |
use App\Http\Requests\Api\LogCoinbaseNotification; | |
use Symfony\Component\HttpFoundation\Response; | |
/** | |
* Class PerformAction | |
* @package App\Http\Controllers\Api | |
* @author jrdn crocker <jrdn@jcrocker.uk> | |
*/ | |
final class PerformAction | |
{ | |
/** @var CommandBus */ | |
private $bus; | |
/** | |
* @param CommandBus $bus | |
*/ | |
public function __construct(CommandBus $bus) | |
{ | |
$this->bus = $bus; | |
} | |
/** | |
* @param LogCoinbaseNotification $request | |
* @return Response | |
*/ | |
public function __invoke(LogCoinbaseNotification $request) : Response | |
{ | |
$this->bus->execute(new LogRequest($request)); | |
return response()->json(['result' => 'accepted'], Response::HTTP_ACCEPTED); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\Http\Controllers; | |
use Illuminate\Routing\Router; | |
/* | |
|-------------------------------------------------------------------------- | |
| API Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register API routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| is assigned the "api" middleware group. Enjoy building your API! | |
| | |
*/ | |
/** @var Router $router */ | |
$router->group( | |
[ | |
'api', | |
], | |
function (Router $router) { | |
$router->post('/', Controllers\Api\PerformAction::class); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment