Skip to content

Commit

Permalink
Merge pull request #9 from Treblle/feature/global-ignore
Browse files Browse the repository at this point in the history
Adding ignore configuration for URLs
  • Loading branch information
JustSteveKing authored Oct 6, 2023
2 parents 199154c + 1a81f0a commit 520354d
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor
/tools/phpunit/.phpunit.result.cache
composer.lock
/.idea
4 changes: 2 additions & 2 deletions src/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function onKernelRequest(RequestEvent $event): void
return;
}

if (method_exists($event, 'isMasterRequest')) { // Symfony < 5.3
if ($event->isMasterRequest()) {
if (method_exists($event, 'isMainRequest')) { // Symfony < 5.3
if ($event->isMainRequest()) {
$this->httpRequest = $event->getRequest();
$this->timestampStart = microtime(true);
}
Expand Down
47 changes: 41 additions & 6 deletions src/DependencyInjection/TreblleConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,87 @@

class TreblleConfiguration
{
/** @var string $apiKey */
private string $apiKey;

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

/** @var string $endpointUrl */
private string $endpointUrl;
/**
* @var list<string>
*/

/** @var list<string> $masked */
private array $masked;

/** @var list<string> $ignore */
private array $ignore;

/** @var bool $debug */
private bool $debug;

/**
* @param list<string> $masked
* @param string $apiKey
* @param string $projectId
* @param string $endpointUrl
* @param array<int,string> $masked
* @param bool $debug
* @param array<int,string> $ignore
*/
public function __construct(string $apiKey, string $projectId, string $endpointUrl, array $masked, bool $debug)
public function __construct(string $apiKey, string $projectId, string $endpointUrl, array $masked, bool $debug, array $ignore = [])
{
$this->apiKey = $apiKey;
$this->projectId = $projectId;
$this->endpointUrl = $endpointUrl;
$this->masked = $masked;
$this->ignore = $ignore;
$this->debug = $debug;
}

/**
* @return string
*/
public function getApiKey(): string
{
return $this->apiKey;
}

/**
* @return string
*/
public function getProjectId(): string
{
return $this->projectId;
}

/**
* @return string
*/
public function getEndpointUrl(): string
{
return $this->endpointUrl;
}

/**
* @return list<string>
* @return array<int,string>
*/
public function getMasked(): array
{
return $this->masked;
}

/**
* @return bool
*/
public function isDebug(): bool
{
return $this->debug;
}

/**
* @return array<int,string>
*/
public function getIgnored(): array
{
return $this->ignore;
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/TreblleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function load(array $configs, ContainerBuilder $container): void
'$endpointUrl' => $config['endpoint_url'],
'$masked' => $config['masked'],
'$debug' => $config['debug'],
'$ignore' => $config['ignore'],
]);
$container->setDefinition(TreblleConfiguration::class, $definition);

Expand Down
3 changes: 2 additions & 1 deletion src/DependencyInjection/TreblleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static function createTreblle(
$requestDataProvider,
$responseDataProvider,
$errorDataProvider,
$configuration->isDebug()
$configuration->isDebug(),
$configuration->getIgnored(),
);
}

Expand Down
4 changes: 4 additions & 0 deletions src/EventSubscriber/TreblleEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public static function getSubscribedEvents(): array

public function onKernelTerminate(KernelEvent $event): void
{
if (in_array($event->getRequest()->getRequestUri(), $this->treblle->ignoredUris(), true)) {
return;
}

try {
$this->treblle->onShutdown();
} catch (\Throwable $throwable) {
Expand Down
2 changes: 1 addition & 1 deletion tests/DataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function test_it_throws_exception_when_accesing_response_without_setting_
public function test_it_builds_request_correctly(): void
{
$event = $this->createMock(RequestEvent::class);
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
$event->expects($this->once())->method('isMainRequest')->willReturn(true);
$event->expects($this->once())->method('getRequest')->willReturn(new Request());

$this->subjectUnderTest->onKernelRequest($event);
Expand Down
2 changes: 1 addition & 1 deletion tests/TreblleIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function test_it_correctly_serializes_request_data_on_shutdown(
->willReturn($language);

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

Expand Down

0 comments on commit 520354d

Please sign in to comment.