Skip to content

Commit 9c9254b

Browse files
committed
make oembed configurable for additional oembed parameters
1 parent f255552 commit 9c9254b

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
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.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ $oembed->int('width'); //Return the value as integer
167167
$oembed->url('url'); //Return the value as full url (converts relative urls to absolutes)
168168
```
169169

170+
Additional oEmbed parameters (like instagrams `hidecaption`) can also be provided:
171+
```php
172+
$embed = new Embed();
173+
$result->setSettings([
174+
'oembed:query_parameters' => ['hidecaption' => true]
175+
]);
176+
```
177+
170178
## LinkedData
171179

172180
Another API available by default, used to extract info using the [JsonLD](https://www.w3.org/TR/json-ld/) schema.
@@ -247,7 +255,7 @@ The `Extractor` class has many `Detectors`. Each detector is responsible to dete
247255

248256
So, an adapter is basically an extractor created specifically for a site. It can contains also custom detectors or apis. If you see the `src/Adapters` folder you can see all adapters.
249257

250-
If you create an adapter, you need also register to Embed, so it knows in which website needs to use. To do that, there's the `ExtractorFactory` object, that is responsible for instantiate the right extractor for each site.
258+
If you create an adapter, you need also register to Embed, so it knows in which website needs to use. To do that, there's the `ExtractorFactory` object, that is responsible for instantiate the right extractor for each site.
251259

252260
```php
253261
use Embed\Embed;

src/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function getSettings(): array
129129
return $this->settings;
130130
}
131131

132-
public function getSetting(string $key): ?string
132+
public function getSetting(string $key)
133133
{
134134
return $this->settings[$key] ?? null;
135135
}

src/OEmbed.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ private static function getProviders(): array
2222
return self::$providers;
2323
}
2424

25+
public function getOembedQueryParameters(string $url): array
26+
{
27+
$queryParameters = ['url' => $url, 'format' => 'json'];
28+
29+
return array_merge($queryParameters, $this->extractor->getSetting('oembed:query_parameters'));
30+
}
31+
2532
protected function fetchData(): array
2633
{
2734
$this->endpoint = $this->detectEndpoint();
@@ -63,7 +70,7 @@ private function detectEndpointFromProviders(): ?UriInterface
6370

6471
return $this->extractor->getCrawler()
6572
->createUri($endpoint)
66-
->withQuery(http_build_query(['url' => $url, 'format' => 'json']));
73+
->withQuery(http_build_query($this->getOembedQueryParameters($url)));
6774
}
6875

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

0 commit comments

Comments
 (0)