Skip to content

Instantly share code, notes, and snippets.

@fizerkhan
Created February 8, 2018 13:11
Show Gist options
  • Save fizerkhan/fab19d93b8f45e0e425febcf04b4c2d5 to your computer and use it in GitHub Desktop.
Save fizerkhan/fab19d93b8f45e0e425febcf04b4c2d5 to your computer and use it in GitHub Desktop.
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