Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Atatus Middleware for Lumen Framework
<?php
// bootstrap/app.php
//...
$app->middleware([
//...
\App\Http\Middleware\AtatusLumenMiddleware::class,
]);
<?php
// app/Http/Middleware/AtatusLumenMiddleware.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
/**
* Class AtatusLumenMiddleware
*/
class AtatusLumenMiddleware
{
/**
* Set Custom Transaction Name
*
* @param Request $request
* @param Closure $next
*/
public function handle(Request $request, Closure $next)
{
$response = $next($request);
if (extension_loaded('atatus')) {
atatus_set_transaction_name($this->txnNameFromRequest($request));
}
return $response;
}
/**
* Transaction name from request.
*
* @param Request $request
* @return string
*/
public function txnNameFromRequest(Request $request)
{
$route = $request->route();
if (is_array($route)) {
if (isset($route[1]) && isset($route[1]['uses'])) {
return $route[1]['uses'];
}
elseif (isset($route[1]) && isset($route[1]['as'])) {
return $route[1]['as'];
}
}
return 'index.php';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment