Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,7 @@ private function configureOptions(OptionsResolver $resolver): void
return array_map([$this, 'normalizeAbsolutePath'], $value);
});

$resolver->setNormalizer('spotlight_url', \Closure::fromCallable([$this, 'normalizeSpotlightUrl']));
$resolver->setNormalizer('spotlight', \Closure::fromCallable([$this, 'normalizeBooleanOrUrl']));

$resolver->setNormalizer('in_app_exclude', function (SymfonyOptions $options, array $value) {
Expand Down Expand Up @@ -1445,12 +1446,24 @@ private function normalizeBooleanOrUrl(SymfonyOptions $options, ?string $boolean
}

if (filter_var($booleanOrUrl, \FILTER_VALIDATE_URL)) {
return $booleanOrUrl;
return $this->normalizeSpotlightUrl($options, $booleanOrUrl);
}

return filter_var($booleanOrUrl, \FILTER_VALIDATE_BOOLEAN);
}

/**
* Normalizes the spotlight URL by removing the `/stream` at the end if present.
*/
private function normalizeSpotlightUrl(SymfonyOptions $options, string $url): string
{
if (substr_compare($url, '/stream', -7, 7) === 0) {
return substr($url, 0, -7);
}

return $url;
}

/**
* Normalizes the DSN option by parsing the host, public and secret keys and
* an optional path.
Expand Down
52 changes: 52 additions & 0 deletions tests/OptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -751,4 +751,56 @@ public static function enableTracingDataProvider(): array
[true, null, true],
];
}

/**
* @dataProvider spotlightUrlNormalizationDataProvider
*/
public function testSpotlightUrlNormalization(array $data, string $expected): void
{
$options = new Options($data);
$this->assertSame($expected, $options->getSpotlightUrl());
}

public static function spotlightUrlNormalizationDataProvider(): \Generator
{
yield [['spotlight_url' => 'http://localhost:8969'], 'http://localhost:8969'];
yield [['spotlight_url' => 'http://localhost:8969/stream'], 'http://localhost:8969'];
yield [['spotlight_url' => 'http://localhost:8969/foo'], 'http://localhost:8969/foo'];
yield [['spotlight_url' => 'http://localhost:8969/foo/stream'], 'http://localhost:8969/foo'];
yield [['spotlight_url' => 'http://localhost:8969/stream/foo'], 'http://localhost:8969/stream/foo'];
yield [['spotlight' => 'http://localhost:8969'], 'http://localhost:8969'];
yield [['spotlight' => 'http://localhost:8969/stream'], 'http://localhost:8969'];
yield [['spotlight' => 'http://localhost:8969/foo'], 'http://localhost:8969/foo'];
yield [['spotlight' => 'http://localhost:8969/foo/stream'], 'http://localhost:8969/foo'];
yield [['spotlight' => 'http://localhost:8969/stream/foo'], 'http://localhost:8969/stream/foo'];
}

/**
* @dataProvider setSpotlightUrlNormalizationDataProvider
*/
public function testSetSpotlightUrlNormalization(string $url, string $expected): void
{
$options = new Options();
$options->setSpotlightUrl($url);
$this->assertSame($expected, $options->getSpotlightUrl());
}

/**
* @dataProvider setSpotlightUrlNormalizationDataProvider
*/
public function testEnableSpotlightNormalization(string $url, string $expected): void
{
$options = new Options();
$options->enableSpotlight($url);
$this->assertSame($expected, $options->getSpotlightUrl());
}

public static function setSpotlightUrlNormalizationDataProvider(): \Generator
{
yield ['http://localhost:8969', 'http://localhost:8969'];
yield ['http://localhost:8969/stream', 'http://localhost:8969'];
yield ['http://localhost:8969/foo', 'http://localhost:8969/foo'];
yield ['http://localhost:8969/foo/stream', 'http://localhost:8969/foo'];
yield ['http://localhost:8969/stream/foo', 'http://localhost:8969/stream/foo'];
}
}