Skip to content

Commit 0d58921

Browse files
committed
improved docs
1 parent 2a79cc9 commit 0d58921

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

README.md

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -73,51 +73,61 @@ $info->linkedData; //The linked-data info (http://json-ld.org/)
7373
$info->feeds; //The RSS/Atom feeds
7474
```
7575

76-
### The adapter
76+
## The adapter
7777

7878
The adapter is the class that get all information of the page from the providers and choose the best result for each value. For example, a page can provide multiple titles from opengraph, twitter cards, oembed, the `<title>` html element, etc, so the adapter get all this titles and choose the best one.
7979

8080
Embed has an generic adapter called "Webpage" to use with any web but has also some specific adapters for sites like archive.org, facebook, google, github, spotify, etc, that provides information using their own apis, or need to fix any specific issue.
8181

8282
The available options for the adapters are:
8383

84-
* min_image_width (int): Minimal image width used to choose the main image
85-
* min_image_height (int): Minimal image height used to choose the main image
86-
* images_blacklist (array): Images that you don't want to be used. Could be plain text or [Url](https://github.com/oscarotero/Embed/blob/master/src/Url.php) match pattern.
87-
* choose_bigger_image (bool): Choose the bigger image as the main image (instead the first found, that usually is the most relevant).
84+
Name | Type | Description
85+
-----|------|------------
86+
`min_image_width` | `int` | Minimal image width used to choose the main image
87+
`min_image_height` | `int` | Minimal image height used to choose the main image
88+
`images_blacklist` | `string|array` | Images that you don't want to be used. Could be plain text or [Uri](https://github.com/oscarotero/Embed/blob/master/src/Uri.php) match pattern.
89+
`choose_bigger_image` | `bool` | Choose the bigger image as the main image (instead the first found, that usually is the most relevant).
8890

89-
### The providers
91+
## The providers
9092

9193
The providers get the data from different sources. Each source has it's own provider. For example, there is a provider for opengraph, other for twitter cards, for oembed, html, etc. Some providers can be configured and are the following:
9294

93-
#### oembed
95+
### oembed
9496

9597
Used to get data from oembed api if it's available:
9698

97-
* parameters (array): Extra query parameters to send with the oembed request
98-
* embedly_key (string): If it's defined, use embed.ly api as fallback oembed provider.
99-
* iframely_key (string): If it's defined, use iframe.ly api as fallback oembed provider.
99+
Name | Type | Description
100+
-----|------|------------
101+
`parameters` | `array` | Extra query parameters to send with the oembed request
102+
`embedly_key` | `string` | If it's defined, use embed.ly api as fallback oembed provider.
103+
`iframely_key` | `string` | If it's defined, use iframe.ly api as fallback oembed provider.
100104

101-
#### html
105+
### html
102106

103107
Used to get data directly from the html code of the page:
104108

105-
* max_images (int): Max number of images fetched from the html code (searching for the `<img>` elements). By default is -1 (no limit). Use 0 to no get images.
106-
* external_images (bool|array): By default is false, this means that images located in other domains are not allowed. You can set true (allow all) or provide an array of url patterns.
109+
Name | Type | Description
110+
-----|------|------------
111+
`max_images` | `int` | Max number of images fetched from the html code (searching for the `<img>` elements). By default is -1 (no limit). Use 0 to no get images.
112+
`external_images` | `bool|array` | By default is false, this means that images located in other domains are not allowed. You can set true (allow all) or provide an array of url patterns.
107113

108-
#### google
114+
### google
109115

110-
Used only for google maps to generate the embed code [using the embed api](https://developers.google.com/maps/documentation/embed/)
116+
Used only for google maps to generate the embed code.
111117

112-
* key (string): the key used
118+
Name | Type | Description
119+
-----|------|------------
120+
`key` | `string` | The key used [for the embed api](https://developers.google.com/maps/documentation/embed/)
113121

114-
#### soundcloud
122+
### soundcloud
115123

116124
Used only for soundcloud pages, to get information using its api.
117125

118-
* key (string): to get info from soundcloud API.
126+
Name | Type | Description
127+
-----|------|------------
128+
`key` | `string` | The key used to get info from soundcloud API.
119129

120-
### Example with all options:
130+
## Example with all options:
121131

122132
The options are passed as the second argument as you can see in the following example:
123133

@@ -149,13 +159,12 @@ $info = Embed::create($url, [
149159
]);
150160
```
151161

152-
### Dispatcher
162+
## The dispatcher
153163

154164
To dispatch the http request, Embed has the interface `Embed\Http\DispatcherInterface`. By default the curl library is used but you can create your own dispatcher to use any other library like [guzzle](https://github.com/guzzle/guzzle):
155165

156-
Create the dispatcher class:
157-
158166
```php
167+
use Embed\Embed;
159168
use Embed\Http\DispatcherInteface;
160169
use Embed\Http\Uri;
161170
use Embed\Http\Response;
@@ -185,24 +194,15 @@ class MyDispatcher implements DispatcherInterface
185194
return $responses;
186195
}
187196
}
188-
```
189197

190-
And to use it:
191-
192-
```php
193-
use Embed\Embed;
194-
use Embed\Http\Request;
195-
196-
$request = new Request('http://example.com', new MyDispatcher());
197-
198-
$info = Embed::create($request);
198+
//Use the dispatcher passing as third argument
199+
$info = Embed::create('http://example.com', [], new MyDispatcher());
199200
```
200201

201202
The default curl dispatcher accepts the same options that the [curl_setopt PHP function](http://php.net/manual/en/function.curl-setopt.php). You can edit the default values:
202203

203204
```php
204205
use Embed\Embed;
205-
use Embed\Http\Request;
206206
use Embed\Http\CurlDispatcher;
207207

208208
$dispatcher = new CurlDispatcher([
@@ -217,14 +217,12 @@ $dispatcher = new CurlDispatcher([
217217
CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4,
218218
]);
219219

220-
$request = new Request('http://example.com', $dispatcher);
221-
222-
$info = Embed::create($request);
220+
$info = Embed::create('http://example.com', [], $dispatcher);
223221
```
224222

225-
### Accessing to more data
223+
## Accessing to advanced data
226224

227-
The adapter get the data from all providers and choose the best values. But you can get all available values accessing directly to each provider. There's also the possibility to inspect all http request executed for debug purposes:
225+
The adapter get the data from all providers and choose the best values. But you can get all available values accessing directly to each provider. There's also the possibility to inspect all http requests executed for debug purposes:
228226

229227
```php
230228
use Embed\Embed;

0 commit comments

Comments
 (0)