You are here

public function TransactionNameEnhancer::enhance in New Relic 8

Same name and namespace in other branches
  1. 2.x src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer::enhance()
  2. 2.0.x src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer::enhance()

File

src/RouteEnhancer/TransactionNameEnhancer.php, line 41

Class

TransactionNameEnhancer
Enhances routes with a dynamic transaction name.

Namespace

Drupal\new_relic_rpm\RouteEnhancer

Code

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;
}