Skip to content

Instantly share code, notes, and snippets.

@jrdnrc
Created March 10, 2017 10:32
Show Gist options
  • Save jrdnrc/ab5a351b3213f9c86821db2fb5fd0a1d to your computer and use it in GitHub Desktop.
Save jrdnrc/ab5a351b3213f9c86821db2fb5fd0a1d to your computer and use it in GitHub Desktop.
Invokable Controllers
<?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);
}
}
<?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