-
Notifications
You must be signed in to change notification settings - Fork 1
/
Newrelic.php
72 lines (64 loc) · 1.95 KB
/
Newrelic.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace li3_newrelic\extensions;
use lithium\core\Environment;
use lithium\core\Libraries;
use lithium\core\StaticObject;
class Newrelic extends StaticObject {
/**
* Simple class to call newrelic method if call standard is met.
*
* This also provides a simple oo wraper to make newrelic calls appear less
* functional. This is the main public API for clients.
*
* {{{
* newrelic_custom_metric(); // Old usage
* Newrelic::custom_metric(); // Shiny new usage
* }}}
*
* @link https://newrelic.com/docs/php/the-php-api
* @param string $method Method called
* @param array $params Args passed to method
* @return mixed Function called, or false if `shouldRun` is false
*/
public static function __callStatic($method, array $params = array()) {
if (static::shouldRun()) {
return call_user_func_array("newrelic_{$method}", $params);
}
return false;
}
/**
*
* Determines if we should run any `newrelic_` methods.
*
* If the configuration for the plugin `shouldRun` does not exist, set
* a generic one.
*
* @return bool
*/
public static function shouldRun() {
if (!is_callable(Libraries::get('li3_newrelic', 'shouldRun'))) {
$config = Libraries::get('li3_newrelic');
$config['shouldRun'] = function() {
return Environment::is('production') && extension_loaded('newrelic');
};
Libraries::add('li3_newrelic', $config);
}
return Libraries::get('li3_newrelic', 'shouldRun')->__invoke();
}
/**
* Main dispatch filter to name the transaction.
*
* Put into a method for better testability.
*
* @return void
*/
public static function filterDispatcher($controller, $params) {
$class = get_class($controller);
$class = substr($class, strrpos($class, '\\') + 1);
$action = $params['request']->params['action'];
$controllerName = preg_replace('/Controller$/', '', $class);
$transactionName = "{$controllerName}/{$action}";
static::name_transaction($transactionName);
}
}
?>