Skip to content

Commit 5507f90

Browse files
committed
make oembed configurable for additional oembed parameters
1 parent f255552 commit 5507f90

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1010
- Ability to send settings to `CurlClient`. Added the `cookies_path` setting to customize the file used for cookies. #345
1111
- `Document::selectCss()` function to select elements using css selectors instead xpath (it requires symfony/css-selector)
1212
- `Document::removeCss()` function to remove elements using css selectors instead xpath (it requires symfony/css-selector)
13+
- Ability to configure OEmbed parameters from the outside
1314

1415
## 4.0.0 - 2020-03-13
1516
Full library refactoring.

src/OEmbed.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class OEmbed
1313

1414
private static $providers;
1515

16+
private array $queryParameters;
17+
1618
private static function getProviders(): array
1719
{
1820
if (!is_array(self::$providers)) {
@@ -22,6 +24,23 @@ private static function getProviders(): array
2224
return self::$providers;
2325
}
2426

27+
public function addQueryParameters(array $queryParameters): self
28+
{
29+
return $this->setQueryParameters(array_merge($this->getQueryParameters(), $queryParameters));
30+
}
31+
32+
public function setQueryParameters(array $queryParameters): self
33+
{
34+
$this->queryParameters = $queryParameters;
35+
36+
return $this;
37+
}
38+
39+
public function getQueryParameters(): array
40+
{
41+
return $this->queryParameters ?? [];
42+
}
43+
2544
protected function fetchData(): array
2645
{
2746
$this->endpoint = $this->detectEndpoint();
@@ -63,7 +82,7 @@ private function detectEndpointFromProviders(): ?UriInterface
6382

6483
return $this->extractor->getCrawler()
6584
->createUri($endpoint)
66-
->withQuery(http_build_query(['url' => $url, 'format' => 'json']));
85+
->withQuery(http_build_query(array_merge(['url' => $url, 'format' => 'json'], $this->getQueryParameters())));
6786
}
6887

6988
private static function searchEndpoint(array $providers, string $url): ?string

0 commit comments

Comments
 (0)