You are here

class TransactionNameEnhancer in New Relic 2.0.x

Same name and namespace in other branches
  1. 8 src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer
  2. 2.x src/RouteEnhancer/TransactionNameEnhancer.php \Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer

Enhances routes with a dynamic transaction name.

Hierarchy

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'
new_relic_rpm.services.yml in ./new_relic_rpm.services.yml
new_relic_rpm.services.yml
1 service uses TransactionNameEnhancer
newrelic.route_enhancer.transaction_name in ./new_relic_rpm.services.yml
Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer

File

src/RouteEnhancer/TransactionNameEnhancer.php, line 14

Namespace

Drupal\new_relic_rpm\RouteEnhancer
View 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

Namesort descending Modifiers Type Description Overrides
TransactionNameEnhancer::$argumentResolver private property Argument resolver service.
TransactionNameEnhancer::$controllerResolver private property Controller resolver service.
TransactionNameEnhancer::enhance public function Updates the defaults for a route definition based on the request. Overrides EnhancerInterface::enhance
TransactionNameEnhancer::__construct public function Constructor.