class RoutingTransactionNameSubscriber in New Relic 8
Same name and namespace in other branches
- 2.x src/EventSubscriber/RoutingTransactionNameSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber
- 2.0.x src/EventSubscriber/RoutingTransactionNameSubscriber.php \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber
Enhances routes with a transaction name or transaction name callback.
The transaction name defaults to the route name, but can be overridden later by further routing alterations. A transaction name callback may be set, and will be invoked by a Route Enhancer.
Hierarchy
- class \Drupal\new_relic_rpm\EventSubscriber\RoutingTransactionNameSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of RoutingTransactionNameSubscriber
See also
\Drupal\new_relic_rpm\RouteEnhancer\TransactionNameEnhancer
1 file declares its use of RoutingTransactionNameSubscriber
- RoutingTransactionNameSubscriberTest.php in tests/
src/ Unit/ EventListener/ RoutingTransactionNameSubscriberTest.php
1 string reference to 'RoutingTransactionNameSubscriber'
1 service uses RoutingTransactionNameSubscriber
File
- src/
EventSubscriber/ RoutingTransactionNameSubscriber.php, line 20
Namespace
Drupal\new_relic_rpm\EventSubscriberView source
class RoutingTransactionNameSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
RoutingEvents::ALTER => [
'addTransactionNamesToRoutes',
],
];
}
/**
* Add transaction names/callbacks to individual routes.
*/
public function addTransactionNamesToRoutes(RouteBuildEvent $event) {
$collection = $event
->getRouteCollection();
// Set a transaction name for the route.
foreach ($collection as $route_name => $route) {
$route
->setDefault('_transaction_name', $route_name);
}
$entity_bundle_routes = [
'entity.node.canonical',
'entity.node.edit_form',
'entity.taxonomy_term.canonical',
'entity.taxonomy_term.edit_form',
'entity.taxonomy_term.add_form',
];
foreach ($entity_bundle_routes as $entity_bundle_route) {
if ($route = $collection
->get($entity_bundle_route)) {
$route
->setDefault('_transaction_name_callback', [
self::class,
'entityBundleRouteTransactionName',
]);
}
}
if ($route = $collection
->get('node.add')) {
$route
->setDefault('_transaction_name_callback', [
self::class,
'nodeAddTransactionName',
]);
}
}
/**
* Get the transaction name for an "entity.$TYPE.$OP" route.
*/
public static function entityBundleRouteTransactionName(Request $request) {
$name = $request->attributes
->get('_transaction_name');
if (preg_match('/^entity\\.([a-z_]+)\\./', $name, $matches)) {
$entity_type = $matches[1];
if (($entity = $request->attributes
->get($entity_type)) && $entity instanceof EntityInterface) {
return sprintf('%s:%s', $name, $entity
->bundle());
}
}
return $name;
}
/**
* Get the transaction name for an "node.add" route.
*/
public static function nodeAddTransactionName(Request $request) {
$name = $request->attributes
->get('_transaction_name');
if (($node_type = $request->attributes
->get('node_type')) && $node_type instanceof EntityInterface) {
return sprintf('%s:%s', $name, $node_type
->id());
}
return $name;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RoutingTransactionNameSubscriber:: |
public | function | Add transaction names/callbacks to individual routes. | |
RoutingTransactionNameSubscriber:: |
public static | function | Get the transaction name for an "entity.$TYPE.$OP" route. | |
RoutingTransactionNameSubscriber:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
RoutingTransactionNameSubscriber:: |
public static | function | Get the transaction name for an "node.add" route. |