Skip to content

Commit 450fa34

Browse files
author
Ricardo Fiorani
committed
small but needed refactorings about naming convention
1 parent d150b6e commit 450fa34

8 files changed

+137
-125
lines changed

README.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ echo $video->getLargestThumbnail();
6666
## Registering your own service video (it's easy !)
6767
If you want to register an implementation of some service your class just needs to implement the "RicardoFiorani\Adapter\VideoAdapterInterface" or extend the RicardoFiorani\Adapter\AbstractServiceAdapter
6868

69-
A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/example/RegisteringANewService.md).
69+
A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/documentation/RegisteringANewService.md).
7070

7171
PS: If you've made your awesome implementation of some well known service, feel free to send a Pull Request. All contributions are welcome :)
7272

@@ -76,9 +76,9 @@ In this project I've used a simple renderer (which just does an echo of an ifram
7676
Here's an example:
7777
### My Example Renderer Class
7878
```php
79+
<?php
7980
namespace MyVendor\MyRenderer;
8081

81-
8282
class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface
8383
{
8484

@@ -91,7 +91,7 @@ class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface
9191
public function render($embedUrl, $height, $width)
9292
{
9393
//Just for example porpoises
94-
return "Hell yeah baby, you've rendered: ".addslashes($embedUrl);
94+
return sprintf("Hello, I'm embedding %s", addslashes($embedUrl));
9595

9696
//A functional example would be like
9797
//return '<iframe width="' . $width . '" height="' . $height . '" src="' . addslashes($embedUrl) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
@@ -100,6 +100,7 @@ class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface
100100
```
101101
### My Example Renderer Factory Class
102102
```php
103+
<?php
103104
namespace MyVendor\MyRenderer\Factory;
104105

105106
class MyOwnRendererFactory implements RendererFactoryInterface
@@ -128,7 +129,7 @@ $vsm->getServiceContainer()->setRenderer('MyOwnRenderer', 'MyVendor\\MyRenderer\
128129

129130
$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');
130131

131-
//This will output "Hell yeah baby, you've rendered: http://www.youtube.com/embed/PkOcm_XaWrw"
132+
//This will output "Hello, I'm embedding http://www.youtube.com/embed/PkOcm_XaWrw"
132133
echo $video->getEmbedCode(500,500);
133134

134135
```
@@ -138,6 +139,3 @@ echo $video->getEmbedCode(500,500);
138139
* Vimeo
139140
* Dailymotion
140141
* Facebook Videos
141-
142-
143-

example/RegisteringANewService.md renamed to documentation/RegisteringANewService.md

+41-27
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
<?php
66
namespace MyVendor\ServiceAdapter;
77

8-
use RicardoFiorani\Adapter\AbstractServiceAdapter;
9-
use RicardoFiorani\Renderer\EmbedRendererInterface;
10-
118
//Your service Adapter must implement VideoAdapterInterface or Extend AbstractServiceAdapter
129
class DailymotionServiceAdapter extends AbstractServiceAdapter
1310
{
1411
const THUMBNAIL_DEFAULT = 'thumbnail';
1512

1613
/**
1714
* AbstractVideoAdapter constructor.
15+
*
1816
* @param string $url
1917
* @param string $pattern
2018
* @param EmbedRendererInterface $renderer
@@ -27,9 +25,9 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
2725
return parent::__construct($url, $pattern, $renderer);
2826
}
2927

30-
3128
/**
32-
* Returns the service name (ie: "Youtube" or "Vimeo")
29+
* Returns the service name (ie: "Youtube" or "Vimeo").
30+
*
3331
* @return string
3432
*/
3533
public function getServiceName()
@@ -38,7 +36,8 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
3836
}
3937

4038
/**
41-
* Returns if the service has a thumbnail image
39+
* Returns if the service has a thumbnail image.
40+
*
4241
* @return bool
4342
*/
4443
public function hasThumbnail()
@@ -47,7 +46,8 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
4746
}
4847

4948
/**
50-
* Returns all thumbnails available sizes
49+
* Returns all thumbnails available sizes.
50+
*
5151
* @return array
5252
*/
5353
public function getThumbNailSizes()
@@ -59,64 +59,79 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
5959

6060
/**
6161
* @param string $size
62+
* @param bool $forceSecure
63+
*
6264
* @return string
65+
* @throws InvalidThumbnailSizeException
6366
*/
64-
public function getThumbnail($size)
67+
public function getThumbnail($size, $forceSecure = false)
6568
{
6669
if (false == in_array($size, $this->getThumbNailSizes())) {
67-
throw new \RicardoFiorani\Exception\InvalidThumbnailSizeException;
70+
throw new InvalidThumbnailSizeException();
6871
}
6972

70-
return 'http://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
73+
return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
7174
}
7275

7376
/**
74-
* Returns the small thumbnail's url
77+
* Returns the small thumbnail's url.
78+
*
79+
* @param bool $forceSecure
7580
* @return string
81+
* @throws InvalidThumbnailSizeException
7682
*/
77-
public function getSmallThumbnail()
83+
public function getSmallThumbnail($forceSecure = false)
7884
{
7985
//Since this service does not provide other thumbnails sizes we just return the default size
80-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
86+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
8187
}
8288

8389
/**
84-
* Returns the medium thumbnail's url
90+
* Returns the medium thumbnail's url.
91+
*
92+
* @param bool $forceSecure
8593
* @return string
94+
* @throws InvalidThumbnailSizeException
8695
*/
87-
public function getMediumThumbnail()
96+
public function getMediumThumbnail($forceSecure = false)
8897
{
8998
//Since this service does not provide other thumbnails sizes we just return the default size
90-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
99+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
91100
}
92101

93102
/**
94-
* Returns the large thumbnail's url
103+
* Returns the large thumbnail's url.
104+
*
105+
* @param bool $forceSecure
95106
* @return string
107+
* @throws InvalidThumbnailSizeException
96108
*/
97-
public function getLargeThumbnail()
109+
public function getLargeThumbnail($forceSecure = false)
98110
{
99111
//Since this service does not provide other thumbnails sizes we just return the default size
100-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
112+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
101113
}
102114

103115
/**
104-
* Returns the largest thumnbnaail's url
116+
* Returns the largest thumnbnaail's url.
117+
* @param bool $forceSecure
105118
* @return string
119+
* @throws InvalidThumbnailSizeException
106120
*/
107-
public function getLargestThumbnail()
121+
public function getLargestThumbnail($forceSecure = false)
108122
{
109123
//Since this service does not provide other thumbnails sizes we just return the default size
110-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
124+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
111125
}
112126

113127
/**
114-
* @param bool $autoplay
128+
* @param bool $forceAutoplay
129+
* @param bool $forceSecure
115130
* @return string
116131
*/
117-
public function getEmbedUrl($autoplay = false)
132+
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
118133
{
119-
return '//www.dailymotion.com/embed/video/' . $this->videoId . ($autoplay ? '?amp&autoplay=1' : '');
134+
return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : '');
120135
}
121136

122137
/**
@@ -133,7 +148,6 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
133148
<?php
134149
namespace MyVendor\ServiceAdapter\Factory;
135150

136-
137151
use MyVendor\ServiceAdapter\DailymotionServiceAdapter;
138152
use RicardoFiorani\Adapter\VideoAdapterInterface;
139153
use RicardoFiorani\Renderer\EmbedRendererInterface;
@@ -174,7 +188,7 @@ $patterns = array(
174188
);
175189

176190
//Register the new service
177-
$vsd->getServiceContainer()->registerService($serviceName, $patterns, "\\MyVendor\\ServiceAdapter\\Factory\\DailymotionServiceAdapterFactory");
191+
$vsd->getServiceContainer()->registerService($serviceName, $patterns, MyVendor\ServiceAdapter\Factory\DailymotionServiceAdapterFactory::class);
178192

179193
//This will get you an DailymotionServiceAdapter
180194
$video = $vsd->parse('http://www.dailymotion.com/video/x33ncwc_kittens-fight-in-tiny-boxing-ring_animals');

src/Adapter/AbstractServiceAdapter.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,29 @@ public function setRenderer($renderer)
115115
/**
116116
* @param int $width
117117
* @param int $height
118-
* @param bool $autoplay
118+
* @param bool $forceAutoplay
119+
* @param bool $forceSecure
119120
*
120121
* @return string
121-
*
122122
* @throws NotEmbeddableException
123123
*/
124-
public function getEmbedCode($width, $height, $autoplay = false, $secure = false)
124+
public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false)
125125
{
126126
if (false == $this->isEmbeddable()) {
127127
throw new NotEmbeddableException();
128128
}
129129

130-
return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($autoplay, $secure), $width, $height);
130+
return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($forceAutoplay, $forceSecure), $width, $height);
131131
}
132132

133133
/**
134134
* Switches the protocol scheme between http and https
135135
*
136-
* @param bool|false $secure
136+
* @param bool|false $forceSecure
137137
* @return string
138138
*/
139-
public function getScheme($secure = false)
139+
public function getScheme($forceSecure = false)
140140
{
141-
return ($secure ? 'https' : 'http');
141+
return ($forceSecure ? 'https' : 'http');
142142
}
143143
}

src/Adapter/Dailymotion/DailymotionServiceAdapter.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -64,79 +64,79 @@ public function getThumbNailSizes()
6464

6565
/**
6666
* @param string $size
67-
* @param bool $secure
67+
* @param bool $forceSecure
6868
*
6969
* @return string
7070
* @throws InvalidThumbnailSizeException
7171
*/
72-
public function getThumbnail($size, $secure = false)
72+
public function getThumbnail($size, $forceSecure = false)
7373
{
7474
if (false == in_array($size, $this->getThumbNailSizes())) {
7575
throw new InvalidThumbnailSizeException();
7676
}
7777

78-
return $this->getScheme($secure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
78+
return $this->getScheme($forceSecure) . '://www.dailymotion.com/' . $size . '/video/' . $this->videoId;
7979
}
8080

8181
/**
8282
* Returns the small thumbnail's url.
8383
*
84-
* @param bool $secure
84+
* @param bool $forceSecure
8585
* @return string
8686
* @throws InvalidThumbnailSizeException
8787
*/
88-
public function getSmallThumbnail($secure = false)
88+
public function getSmallThumbnail($forceSecure = false)
8989
{
9090
//Since this service does not provide other thumbnails sizes we just return the default size
91-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
91+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
9292
}
9393

9494
/**
9595
* Returns the medium thumbnail's url.
9696
*
97-
* @param bool $secure
97+
* @param bool $forceSecure
9898
* @return string
9999
* @throws InvalidThumbnailSizeException
100100
*/
101-
public function getMediumThumbnail($secure = false)
101+
public function getMediumThumbnail($forceSecure = false)
102102
{
103103
//Since this service does not provide other thumbnails sizes we just return the default size
104-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
104+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
105105
}
106106

107107
/**
108108
* Returns the large thumbnail's url.
109109
*
110-
* @param bool $secure
110+
* @param bool $forceSecure
111111
* @return string
112112
* @throws InvalidThumbnailSizeException
113113
*/
114-
public function getLargeThumbnail($secure = false)
114+
public function getLargeThumbnail($forceSecure = false)
115115
{
116116
//Since this service does not provide other thumbnails sizes we just return the default size
117-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
117+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
118118
}
119119

120120
/**
121121
* Returns the largest thumnbnaail's url.
122-
* @param bool $secure
122+
* @param bool $forceSecure
123123
* @return string
124124
* @throws InvalidThumbnailSizeException
125125
*/
126-
public function getLargestThumbnail($secure = false)
126+
public function getLargestThumbnail($forceSecure = false)
127127
{
128128
//Since this service does not provide other thumbnails sizes we just return the default size
129-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
129+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $forceSecure);
130130
}
131131

132132
/**
133-
* @param bool $autoplay
134-
* @param bool $secure
133+
* @param bool $forceAutoplay
134+
* @param bool $forceSecure
135135
* @return string
136136
*/
137-
public function getEmbedUrl($autoplay = false, $secure = false)
137+
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
138138
{
139-
return $this->getScheme($secure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($autoplay ? '?amp&autoplay=1' : '');
139+
return $this->getScheme($forceSecure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($forceAutoplay ? '?amp&autoplay=1' : '');
140140
}
141141

142142
/**

0 commit comments

Comments
 (0)