class TransactionNameEnhancer in New Relic 8
Same name and namespace in other branches
- 2.x src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer
- 2.0.x src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer
Enhances routes with a dynamic transaction name.
Hierarchy
- class \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer implements EnhancerInterface
Expanded class hierarchy of TransactionNameEnhancer
1 file declares its use of TransactionNameEnhancer
- TransactionNameEnhancerTest.php in tests/
src/ Unit/ RouteEnhancer/ TransactionNameEnhancerTest.php
1 string reference to 'TransactionNameEnhancer'
1 service uses TransactionNameEnhancer
File
- src/
RouteEnhancer/ TransactionNameEnhancer.php, line 14
Namespace
Drupal\new_relic_rpm\RouteEnhancerView source
class TransactionNameEnhancer implements EnhancerInterface {
/**
* Controller resolver service.
*
* @var \Drupal\Core\Controller\ControllerResolverInterface
*/
private $controllerResolver;
/**
* Argument resolver service.
*
* @var \Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface
*/
private $argumentResolver;
/**
* Constructor.
*/
public function __construct(ControllerResolverInterface $controller_resolver, ArgumentResolverInterface $argument_resolver) {
$this->controllerResolver = $controller_resolver;
$this->argumentResolver = $argument_resolver;
}
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
/** @var \Symfony\Component\Routing\Route $route */
$route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
if (!$route
->hasDefault('_transaction_name_callback')) {
return $defaults;
}
$cb = $route
->getDefault('_transaction_name_callback');
$callable = $this->controllerResolver
->getControllerFromDefinition($cb);
// Clone the request so we can set the attributes now. Otherwise,
// attributes aren't populated until after the route is enhanced.
$cloned = clone $request;
$cloned->attributes
->replace($defaults);
$arguments = $this->argumentResolver
->getArguments($cloned, $callable);
$defaults['_transaction_name'] = call_user_func_array($callable, $arguments);
return $defaults;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TransactionNameEnhancer:: |
private | property | Argument resolver service. | |
TransactionNameEnhancer:: |
private | property | Controller resolver service. | |
TransactionNameEnhancer:: |
public | function | Update the defaults based on its own data and the request. | |
TransactionNameEnhancer:: |
public | function | Constructor. |