Skip to content

Commit bd7dca0

Browse files
committed
Better php doc in the code
1 parent f8ccc75 commit bd7dca0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1242
-2
lines changed

Embed/Adapters/Adapter.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,17 @@ abstract class Adapter
4141
'embedlyKey' => null
4242
);
4343

44+
/**
45+
* Initializes all providers used in this adapter (oembed, opengraph, etc)
46+
*
47+
* @param Request $request
48+
*/
4449
abstract protected function initProviders (Request $request);
4550

51+
52+
/**
53+
* {@inheritDoc}
54+
*/
4655
public function __construct(Request $request, array $options = null)
4756
{
4857
if ($options !== null) {
@@ -56,6 +65,15 @@ public function __construct(Request $request, array $options = null)
5665
}
5766
}
5867

68+
69+
/**
70+
* Magic method to execute and save the url data.
71+
* For example, on call $this->title, executes $this->getTitle()
72+
*
73+
* @param string $name
74+
*
75+
* @return mixed
76+
*/
5977
public function __get($name)
6078
{
6179
$method = 'get'.$name;
@@ -65,6 +83,15 @@ public function __get($name)
6583
}
6684
}
6785

86+
87+
/**
88+
* Search and returns data from the providers
89+
*
90+
* @param string $name The data name (title, description, image, etc)
91+
* @param boolean $returnFirst If it's true, returns the first value found, else returns the most popular value
92+
*
93+
* @return mixed
94+
*/
6895
public function getFromProviders($name, $returnFirst = true)
6996
{
7097
$method = 'get'.$name;
@@ -92,6 +119,15 @@ public function getFromProviders($name, $returnFirst = true)
92119
return $current;
93120
}
94121

122+
123+
/**
124+
* Search and returns url type data from the providers (image, providerIcon, providerUrl, etc)
125+
* If the url found is relative, transforms it to absolute
126+
*
127+
* @param string $name The data name
128+
*
129+
* @return null|string
130+
*/
95131
public function getUrlFromProviders($name)
96132
{
97133
$method = 'get'.$name;
@@ -103,36 +139,64 @@ public function getUrlFromProviders($name)
103139
}
104140
}
105141

142+
143+
/**
144+
* {@inheritDoc}
145+
*/
106146
public function getTitle()
107147
{
108148
return $this->getFromProviders('title') ?: $this->request->getUrl();
109149
}
110150

151+
152+
/**
153+
* {@inheritDoc}
154+
*/
111155
public function getDescription()
112156
{
113157
return $this->getFromProviders('description');
114158
}
115159

160+
161+
/**
162+
* {@inheritDoc}
163+
*/
116164
public function getUrl()
117165
{
118166
return $this->getUrlFromProviders('url') ?: $this->request->getUrl();
119167
}
120168

169+
170+
/**
171+
* {@inheritDoc}
172+
*/
121173
public function getSource()
122174
{
123175
return $this->getUrlFromProviders('source');
124176
}
125177

178+
179+
/**
180+
* {@inheritDoc}
181+
*/
126182
public function getAuthorName()
127183
{
128184
return $this->getFromProviders('authorName');
129185
}
130186

187+
188+
/**
189+
* {@inheritDoc}
190+
*/
131191
public function getAuthorUrl()
132192
{
133193
return $this->getUrlFromProviders('authorUrl');
134194
}
135195

196+
197+
/**
198+
* {@inheritDoc}
199+
*/
136200
public function getAspectRatio()
137201
{
138202
$width = $this->width;
@@ -143,6 +207,10 @@ public function getAspectRatio()
143207
}
144208
}
145209

210+
211+
/**
212+
* {@inheritDoc}
213+
*/
146214
public function getImage()
147215
{
148216
foreach ($this->images as $src) {
@@ -165,6 +233,10 @@ public function getImage()
165233
}
166234
}
167235

236+
237+
/**
238+
* {@inheritDoc}
239+
*/
168240
public function getProviderIcon()
169241
{
170242
if ($this->options['getBiggerIcon']) {
@@ -186,31 +258,55 @@ public function getProviderIcon()
186258
}
187259
}
188260

261+
262+
/**
263+
* {@inheritDoc}
264+
*/
189265
public function getProviderName()
190266
{
191267
return $this->getFromProviders('providerName') ?: $this->request->getDomain();
192268
}
193269

270+
271+
/**
272+
* {@inheritDoc}
273+
*/
194274
public function getProviderUrl()
195275
{
196276
return $this->getUrlFromProviders('providerUrl') ?: ($this->request->getScheme().'://'.$this->request->getDomain(true));
197277
}
198278

279+
280+
/**
281+
* {@inheritDoc}
282+
*/
199283
public function getImageWidth()
200284
{
201285
return null;
202286
}
203287

288+
289+
/**
290+
* {@inheritDoc}
291+
*/
204292
public function getImageHeight()
205293
{
206294
return null;
207295
}
208296

297+
298+
/**
299+
* {@inheritDoc}
300+
*/
209301
public function getWidth()
210302
{
211303
return $this->getFromProviders('width');
212304
}
213305

306+
307+
/**
308+
* {@inheritDoc}
309+
*/
214310
public function getHeight()
215311
{
216312
return $this->getFromProviders('height');

Embed/Adapters/AdapterInterface.php

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,179 @@
88

99
interface AdapterInterface
1010
{
11+
/**
12+
* Checks whether the request is valid to this Adapter
13+
*
14+
* @param Request $request
15+
*
16+
* @return boolean
17+
*/
1118
public static function check (Request $request);
1219

20+
21+
/**
22+
* Constructor.
23+
*
24+
* @param Request $request
25+
* @param null|array $options
26+
*/
1327
public function __construct (Request $request, array $options = null);
1428

29+
30+
/**
31+
* Gets the title
32+
*
33+
* @return string|null
34+
*/
1535
public function getTitle ();
1636

37+
38+
/**
39+
* Gets the description
40+
*
41+
* @return string|null
42+
*/
1743
public function getDescription ();
1844

45+
46+
/**
47+
* Gets the type of the url
48+
* The types are the same than the oEmbed types:
49+
* video, photo, link, rich
50+
*
51+
* @return string|null
52+
*/
1953
public function getType ();
2054

55+
56+
/**
57+
* Gets the source url (feed, api, etc)
58+
*
59+
* @return string|null
60+
*/
2161
public function getSource ();
2262

63+
64+
/**
65+
* Gets the embed code
66+
*
67+
* @return string|null
68+
*/
2369
public function getCode ();
2470

71+
72+
/**
73+
* Gets the canonical url
74+
*
75+
* @return string|null
76+
*/
2577
public function getUrl ();
2678

79+
80+
/**
81+
* Gets the author name
82+
*
83+
* @return string|null
84+
*/
2785
public function getAuthorName ();
2886

87+
88+
/**
89+
* Gets the author url
90+
*
91+
* @return string|null
92+
*/
2993
public function getAuthorUrl ();
3094

95+
96+
/**
97+
* Gets all icon provider urls found
98+
*
99+
* @return array
100+
*/
31101
public function getProviderIcons ();
32102

103+
104+
/**
105+
* Gets the best icon provider
106+
* if $options['getBiggerIcon'] is true, returns the bigger image found
107+
* else, returns the first found
108+
*
109+
* @return string|null
110+
*/
33111
public function getProviderIcon ();
34112

113+
114+
/**
115+
* Gets the provider name
116+
*
117+
* @return string|null
118+
*/
35119
public function getProviderName ();
36120

121+
122+
/**
123+
* Gets the provider url (usually the home url of the link)
124+
*
125+
* @return string|null
126+
*/
37127
public function getProviderUrl ();
38128

129+
130+
/**
131+
* Gets all images found in the webpage
132+
*
133+
* @return array
134+
*/
135+
public function getImages ();
136+
137+
138+
/**
139+
* Gets the best image
140+
* if $options['getBiggerImage'] is true, returns the biggest image
141+
*
142+
* @return string|null
143+
*/
39144
public function getImage ();
40145

146+
147+
/**
148+
* Gets the image width
149+
*
150+
* @return integer|null
151+
*/
41152
public function getImageWidth ();
42153

154+
155+
/**
156+
* Gets the image height
157+
*
158+
* @return integer|null
159+
*/
43160
public function getImageHeight ();
44161

162+
163+
/**
164+
* Gets the width of the embedded widget
165+
*
166+
* @return integer|null
167+
*/
45168
public function getWidth ();
46169

170+
171+
/**
172+
* Gets the height of the embedded widget
173+
*
174+
* @return integer|null
175+
*/
47176
public function getHeight ();
48177

178+
179+
/**
180+
* Gets the aspect ratio of the embedded widget
181+
* (useful to make it flexible)
182+
*
183+
* @return float|null
184+
*/
49185
public function getAspectRatio ();
50186
}

0 commit comments

Comments
 (0)