Skip to content

Commit

Permalink
Removed AppName to presenter mapping feature which wasn't working in …
Browse files Browse the repository at this point in the history
…the first place
  • Loading branch information
foxycode committed Jan 10, 2021
1 parent 6f47ec4 commit d8931b0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 53 deletions.
39 changes: 1 addition & 38 deletions src/Callbacks/OnRequestCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,23 @@

namespace Contributte\NewRelic\Callbacks;

use Contributte\NewRelic\Tracy\Bootstrap;
use Nette\Application\Application;
use Nette\Application\Request;
use Nette\Application\UI\Presenter;
use Nette\Utils\Strings;

class OnRequestCallback
{

/**
* @var array
*/
private $map;

/**
* @var string
*/
private $license;

/**
* @var string
*/
private $actionKey;

/**
* @param array $map
* @param string $license
* @param string $actionKey
*/
public function __construct(array $map, $license, $actionKey = Presenter::ACTION_KEY)
public function __construct($actionKey = Presenter::ACTION_KEY)
{
$this->map = $map;
$this->license = $license;
$this->actionKey = $actionKey;
}

Expand All @@ -56,27 +40,6 @@ public function __invoke(Application $application, Request $request)
$action = sprintf('%s:%s', $action, $params[$this->actionKey]);
}

if ($this->map) {
foreach ($this->map as $pattern => $appName) {
if ($pattern === '*') {
continue;
}

if (Strings::endsWith($pattern, '*')) {
$pattern = Strings::substring($pattern, 0, -1);
}

if (Strings::startsWith($pattern, ':')) {
$pattern = Strings::substring($pattern, 1);
}

if (Strings::startsWith($action, $pattern)) {
Bootstrap::setup($appName, $this->license);
break;
}
}
}

newrelic_name_transaction($action);
newrelic_disable_autorum();
}
Expand Down
17 changes: 2 additions & 15 deletions src/DI/NewRelicExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getConfigSchema(): Schema
{
return Expect::structure([
'enabled' => Expect::bool(true),
'appName' => Expect::type('string|array'),
'appName' => Expect::string(),
'license' => Expect::string(),
'actionKey' => Expect::string(),
'logLevel' => Expect::listOf(Expect::string(Expect::anyOf([
Expand Down Expand Up @@ -121,20 +121,11 @@ public function afterCompile(ClassType $class)
$initialize = $class->getMethod('initialize');

// AppName and license
if ($config->appName && !is_array($config->appName)) {
if ($config->appName) {
$initialize->addBody('\Contributte\NewRelic\Tracy\Bootstrap::setup(?, ?);', [
$config->appName,
$config->license,
]);
} elseif ($config->appName && is_array($config->appName)) {
if (!isset($config->appName['*'])) {
throw new \RuntimeException('Missing default app name as "*"');
}

$initialize->addBody('\Contributte\NewRelic\Tracy\Bootstrap::setup(?, ?);', [
$config->appName['*'],
$config->license,
]);
}

// Logger
Expand Down Expand Up @@ -189,12 +180,8 @@ private function setupApplicationOnRequest()
$builder = $this->getContainerBuilder();
$config = $this->getConfig();

$map = $config->appName && is_array($config->appName) ? $config->appName : [];

$builder->addDefinition($this->prefix('onRequestCallback'))
->setFactory(OnRequestCallback::class, [
$map,
$config->license,
$config->actionKey ?? Presenter::ACTION_KEY,
]);

Expand Down

0 comments on commit d8931b0

Please sign in to comment.