Skip to content

Commit e5d8415

Browse files
committed
Remove deprecated methods and Flash support for 1.0
- Remove deprecated addProvider(), getHost(), getHostOrFail() methods - Remove Flash/object embed support (iframe-only now) - Remove unused _matchUrl() and embedLocal() methods - Remove local file handling (dead code) - Update tests to use new API (addProviderConfig, getProvider) - Update documentation for 1.0 - Clean up ProviderConfig examples in docs
1 parent 65883e2 commit e5d8415

5 files changed

Lines changed: 139 additions & 377 deletions

File tree

‎docs/README.md‎

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ $customProviders = [
121121
'url-match' => [
122122
'https?://(?:www\.)?custom\.example\.com/video/([0-9]+)',
123123
],
124-
'embed-src' => '',
125124
'embed-width' => '640',
126125
'embed-height' => '360',
127126
'iframe-player' => '//custom.example.com/embed/$2',
@@ -134,26 +133,25 @@ $MediaEmbed = new MediaEmbed(['custom_providers' => $customProviders]);
134133
$MediaObject = $MediaEmbed->parseUrl('https://custom.example.com/video/12345');
135134
```
136135

137-
#### 2. Dynamically with addProvider()
136+
#### 2. Dynamically with addProviderConfig()
138137

139-
Add providers at runtime:
138+
Add providers at runtime using the type-safe ProviderConfig DTO:
140139

141140
```php
141+
use MediaEmbed\Provider\ProviderConfig;
142+
142143
$MediaEmbed = new MediaEmbed();
143144

144-
$customProvider = [
145-
'name' => 'AnotherService',
146-
'website' => 'https://another.example.com',
147-
'url-match' => [
148-
'https?://another\.example\.com/watch/([a-z0-9]+)',
149-
],
150-
'embed-src' => '',
151-
'embed-width' => '560',
152-
'embed-height' => '315',
153-
'iframe-player' => '//another.example.com/player/$2',
154-
];
145+
$customProvider = new ProviderConfig(
146+
name: 'AnotherService',
147+
website: 'https://another.example.com',
148+
urlMatch: ['https?://another\.example\.com/watch/([a-z0-9]+)'],
149+
embedWidth: 560,
150+
embedHeight: 315,
151+
iframePlayer: '//another.example.com/player/$2',
152+
);
155153

156-
$MediaEmbed->addProvider($customProvider);
154+
$MediaEmbed->addProviderConfig($customProvider);
157155
```
158156

159157
#### 3. From a Configuration File
@@ -170,7 +168,6 @@ return [
170168
'url-match' => [
171169
'https?://file\.example\.com/v/([0-9]+)',
172170
],
173-
'embed-src' => '',
174171
'embed-width' => '640',
175172
'embed-height' => '360',
176173
'iframe-player' => '//file.example.com/embed/$2',
@@ -187,7 +184,6 @@ return [
187184
"url-match": [
188185
"https?://json\\.example\\.com/video/([0-9]+)"
189186
],
190-
"embed-src": "",
191187
"embed-width": "640",
192188
"embed-height": "360",
193189
"iframe-player": "//json.example.com/embed/$2"
@@ -207,36 +203,49 @@ $MediaEmbed = new MediaEmbed(['providers_config' => '/path/to/custom-providers.j
207203
By default, custom providers won't override existing ones. To override:
208204

209205
```php
206+
use MediaEmbed\Provider\ProviderConfig;
207+
210208
$MediaEmbed = new MediaEmbed();
211209

212-
$customYouTube = [
213-
'name' => 'YouTube',
214-
'website' => 'https://www.youtube.com',
215-
'url-match' => [
216-
'https?://youtu\.be/([0-9a-z-_]{11})',
217-
],
218-
'embed-src' => '',
219-
'embed-width' => '800', // Custom width
220-
'embed-height' => '600', // Custom height
221-
'iframe-player' => '//www.youtube.com/embed/$2?custom=param',
222-
];
210+
$customYouTube = new ProviderConfig(
211+
name: 'YouTube',
212+
website: 'https://www.youtube.com',
213+
urlMatch: ['https?://youtu\.be/([0-9a-z-_]{11})'],
214+
embedWidth: 800, // Custom width
215+
embedHeight: 600, // Custom height
216+
iframePlayer: '//www.youtube.com/embed/$2?custom=param',
217+
);
223218

224-
$MediaEmbed->addProvider($customYouTube, true); // Pass true to override
219+
$MediaEmbed->addProviderConfig($customYouTube, override: true);
225220
```
226221

227222
#### Provider Configuration Format
228223

229-
Each provider is an array with these properties:
224+
Using `ProviderConfig` DTO (recommended):
225+
226+
```php
227+
$config = new ProviderConfig(
228+
name: 'MyProvider', // Required: Display name
229+
website: 'https://...', // Homepage URL
230+
urlMatch: ['regex...'], // Required: URL patterns (array or string)
231+
embedWidth: 640, // Required: Default width
232+
embedHeight: 360, // Required: Default height
233+
iframePlayer: '//.../$2', // Required: Iframe URL template
234+
slug: 'myprovider', // Optional: Custom slug (auto-generated if omitted)
235+
imageSrc: '//.../$2.jpg', // Optional: Thumbnail URL template
236+
supportsTimestamp: false, // Optional: Timestamp support (like YouTube)
237+
);
238+
```
239+
240+
For array-based configs (legacy format):
230241

231242
- **name** (required): Display name of the provider
232243
- **website**: Homepage URL of the service
233-
- **url-match** (required): Array of regex patterns to match URLs (use $2, $3, etc. for capture groups)
234-
- **embed-src**: Legacy embed source (for older Flash-based embeds)
235-
- **embed-width**: Default width in pixels or percentage
236-
- **embed-height**: Default height in pixels or percentage
237-
- **iframe-player** (recommended): URL template for iframe embedding (use $2, $3, etc. for matched groups)
244+
- **url-match** (required): Array of regex patterns to match URLs
245+
- **embed-width** (required): Default width in pixels
246+
- **embed-height** (required): Default height in pixels
247+
- **iframe-player** (required): URL template for iframe embedding
238248
- **slug**: Optional custom slug (auto-generated from name if not provided)
239-
- **id**: Optional ID extraction pattern (defaults to $2)
240249
- **image-src**: Optional thumbnail image URL template
241250

242251
**Note:** In regex patterns and templates, `$1` is the full matched URL, `$2` is the first capture group, `$3` is the second, etc.
@@ -558,7 +567,7 @@ protected function _finalizeVideo($params) {
558567
}
559568
```
560569

561-
So `[video]123[/video]` becomes `<iframe ...>...</iframe>` or `<object ...><embed src="..."</embed></object>`.
570+
So `[video]123[/video]` becomes `<iframe ...>...</iframe>`.
562571

563572
### More examples
564573
You can see live examples when you get this repo running locally and browse to `examples` dir.

0 commit comments

Comments
 (0)