Skip to content

Commit e43e741

Browse files
author
Dominik Jansen
committed
refactor: add method to set settings on embed
1 parent 0499371 commit e43e741

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,17 +328,14 @@ If you need to pass settings to your detectors, you can add settings to the `Ext
328328

329329
```php
330330
use Embed\Embed;
331-
use Embed\ExtractorFactory;
332331

333332
$embed = new Embed();
334-
$extractorFactory = new ExtractorFactory([
333+
$embed->setSettings([
335334
'oembed:query_parameters' => [], //Extra parameters send to oembed
336335
'twitch:parent' => 'example.com', //Required to embed twitch videos as iframe
337336
'facebook:token' => '1234|5678', //Required to embed content from Facebook
338337
'instagram:token' => '1234|5678', //Required to embed content from Instagram
339338
]);
340-
$embed->setExtractorFactory($extractorFactory);
341-
342339
$info = $embed->get($url);
343340
```
344341

demo/index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,13 @@ function printCode(?string $code, bool $asHtml = true): void
207207
'Cache-Control' => 'max-age=0,no-cache',
208208
]);
209209

210-
$extractorFactory = new \Embed\ExtractorFactory(
210+
$embed->setSettings(
211211
[
212212
'twitch:parent' => $_SERVER['SERVER_NAME'] === 'localhost' ? null : $_SERVER['SERVER_NAME'],
213213
'instagram:token' => getParam('instagram_token'),
214214
'facebook:token' => getParam('facebook_token'),
215215
]
216216
);
217-
$embed->setExtractorFactory($extractorFactory);
218217
$info = $embed->get(getUrl());
219218
} catch (Exception $exception) {
220219
echo '<pre>';

src/Embed.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public function getExtractorFactory(): ExtractorFactory
5757
return $this->extractorFactory;
5858
}
5959

60+
public function setSettings(array $settings): void
61+
{
62+
$this->extractorFactory->setSettings($settings);
63+
}
64+
6065
private function extract(RequestInterface $request, ResponseInterface $response, bool $redirect = true): Extractor
6166
{
6267
$uri = $this->crawler->getResponseUri($response) ?: $request->getUri();
@@ -81,9 +86,4 @@ private function mustRedirect(Extractor $extractor): bool
8186

8287
return $extractor->redirect !== null;
8388
}
84-
85-
public function setExtractorFactory(ExtractorFactory $extractorFactory): void
86-
{
87-
$this->extractorFactory = $extractorFactory;
88-
}
8989
}

src/ExtractorFactory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ public function setDefault(string $class): void
7777
{
7878
$this->default = $class;
7979
}
80+
81+
public function setSettings(array $settings): void
82+
{
83+
$this->settings = $settings;
84+
}
8085
}

0 commit comments

Comments
 (0)