Skip to content

Commit 520354d

Browse files
Merge pull request #9 from Treblle/feature/global-ignore
Adding ignore configuration for URLs
2 parents 199154c + 1a81f0a commit 520354d

File tree

8 files changed

+53
-11
lines changed

8 files changed

+53
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor
22
/tools/phpunit/.phpunit.result.cache
33
composer.lock
4+
/.idea

src/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function onKernelRequest(RequestEvent $event): void
5050
return;
5151
}
5252

53-
if (method_exists($event, 'isMasterRequest')) { // Symfony < 5.3
54-
if ($event->isMasterRequest()) {
53+
if (method_exists($event, 'isMainRequest')) { // Symfony < 5.3
54+
if ($event->isMainRequest()) {
5555
$this->httpRequest = $event->getRequest();
5656
$this->timestampStart = microtime(true);
5757
}

src/DependencyInjection/TreblleConfiguration.php

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,87 @@
66

77
class TreblleConfiguration
88
{
9+
/** @var string $apiKey */
910
private string $apiKey;
11+
12+
/** @var string $projectId */
1013
private string $projectId;
14+
15+
/** @var string $endpointUrl */
1116
private string $endpointUrl;
12-
/**
13-
* @var list<string>
14-
*/
17+
18+
/** @var list<string> $masked */
1519
private array $masked;
20+
21+
/** @var list<string> $ignore */
22+
private array $ignore;
23+
24+
/** @var bool $debug */
1625
private bool $debug;
1726

1827
/**
19-
* @param list<string> $masked
28+
* @param string $apiKey
29+
* @param string $projectId
30+
* @param string $endpointUrl
31+
* @param array<int,string> $masked
32+
* @param bool $debug
33+
* @param array<int,string> $ignore
2034
*/
21-
public function __construct(string $apiKey, string $projectId, string $endpointUrl, array $masked, bool $debug)
35+
public function __construct(string $apiKey, string $projectId, string $endpointUrl, array $masked, bool $debug, array $ignore = [])
2236
{
2337
$this->apiKey = $apiKey;
2438
$this->projectId = $projectId;
2539
$this->endpointUrl = $endpointUrl;
2640
$this->masked = $masked;
41+
$this->ignore = $ignore;
2742
$this->debug = $debug;
2843
}
2944

45+
/**
46+
* @return string
47+
*/
3048
public function getApiKey(): string
3149
{
3250
return $this->apiKey;
3351
}
3452

53+
/**
54+
* @return string
55+
*/
3556
public function getProjectId(): string
3657
{
3758
return $this->projectId;
3859
}
3960

61+
/**
62+
* @return string
63+
*/
4064
public function getEndpointUrl(): string
4165
{
4266
return $this->endpointUrl;
4367
}
4468

4569
/**
46-
* @return list<string>
70+
* @return array<int,string>
4771
*/
4872
public function getMasked(): array
4973
{
5074
return $this->masked;
5175
}
5276

77+
/**
78+
* @return bool
79+
*/
5380
public function isDebug(): bool
5481
{
5582
return $this->debug;
5683
}
84+
85+
/**
86+
* @return array<int,string>
87+
*/
88+
public function getIgnored(): array
89+
{
90+
return $this->ignore;
91+
}
5792
}

src/DependencyInjection/TreblleExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function load(array $configs, ContainerBuilder $container): void
2727
'$endpointUrl' => $config['endpoint_url'],
2828
'$masked' => $config['masked'],
2929
'$debug' => $config['debug'],
30+
'$ignore' => $config['ignore'],
3031
]);
3132
$container->setDefinition(TreblleConfiguration::class, $definition);
3233

src/DependencyInjection/TreblleFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public static function createTreblle(
3333
$requestDataProvider,
3434
$responseDataProvider,
3535
$errorDataProvider,
36-
$configuration->isDebug()
36+
$configuration->isDebug(),
37+
$configuration->getIgnored(),
3738
);
3839
}
3940

src/EventSubscriber/TreblleEventSubscriber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public static function getSubscribedEvents(): array
3535

3636
public function onKernelTerminate(KernelEvent $event): void
3737
{
38+
if (in_array($event->getRequest()->getRequestUri(), $this->treblle->ignoredUris(), true)) {
39+
return;
40+
}
41+
3842
try {
3943
$this->treblle->onShutdown();
4044
} catch (\Throwable $throwable) {

tests/DataProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function test_it_throws_exception_when_accesing_response_without_setting_
5555
public function test_it_builds_request_correctly(): void
5656
{
5757
$event = $this->createMock(RequestEvent::class);
58-
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
58+
$event->expects($this->once())->method('isMainRequest')->willReturn(true);
5959
$event->expects($this->once())->method('getRequest')->willReturn(new Request());
6060

6161
$this->subjectUnderTest->onKernelRequest($event);

tests/TreblleIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public function test_it_correctly_serializes_request_data_on_shutdown(
342342
->willReturn($language);
343343

344344
$requestEvent = $this->createMock(RequestEvent::class);
345-
$requestEvent->expects($this->once())->method('isMasterRequest')->willReturn(true);
345+
$requestEvent->expects($this->once())->method('isMainRequest')->willReturn(true);
346346
$requestEvent->expects($this->once())->method('getRequest')->willReturn($httpRequest);
347347
$this->dataProvider->onKernelRequest($requestEvent);
348348

0 commit comments

Comments
 (0)