Skip to content

Commit 4b2a2e1

Browse files
Merge pull request #5 from ricardofiorani/secure-option-enhancement
Make it available to use both http and https schemes
2 parents 007be08 + 76df4c3 commit 4b2a2e1

23 files changed

+207
-117
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![Coding Standards](https://img.shields.io/badge/cs-PSR--4-yellow.svg)](https://github.com/php-fig-rectified/fig-rectified-standards)
77
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/ricardofiorani/php-video-url-parser/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/ricardofiorani/php-video-url-parser/?branch=master)
88
[![Code Coverage](https://scrutinizer-ci.com/g/ricardofiorani/php-video-url-parser/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/ricardofiorani/php-video-url-parser/?branch=master)
9+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ricardofiorani/php-video-url-parser/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
910

1011
PHP Video URL Parser is a parser that detects a given video url and returns an object containing information like the video's embed code, title, description, thumbnail and other information that the service may give.
1112

@@ -142,5 +143,3 @@ echo $video->getEmbedCode(500,500);
142143
* Create PHPUnit Tests
143144

144145

145-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ricardofiorani/php-video-url-parser/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
146-

example/RegisteringANewService.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ use MyVendor\ServiceAdapter\DailymotionServiceAdapter;
138138
use RicardoFiorani\Adapter\VideoAdapterInterface;
139139
use RicardoFiorani\Renderer\EmbedRendererInterface;
140140

141-
class DailymotionServiceAdapterFactory implements \RicardoFiorani\Adapter\Factory\CallableServiceAdapterFactoryInterface
141+
class DailymotionServiceAdapterFactory implements \RicardoFiorani\Adapter\CallableServiceAdapterFactoryInterface
142142
{
143143
/**
144144
* @param string $url

src/Adapter/AbstractServiceAdapter.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ abstract class AbstractServiceAdapter implements VideoAdapterInterface
3535
/**
3636
* AbstractVideoAdapter constructor.
3737
*
38-
* @param string $url
39-
* @param string $pattern
38+
* @param string $url
39+
* @param string $pattern
4040
* @param EmbedRendererInterface $renderer
4141
*/
4242
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
@@ -113,20 +113,31 @@ public function setRenderer($renderer)
113113
}
114114

115115
/**
116-
* @param int $width
117-
* @param int $height
116+
* @param int $width
117+
* @param int $height
118118
* @param bool $autoplay
119119
*
120120
* @return string
121121
*
122122
* @throws NotEmbeddableException
123123
*/
124-
public function getEmbedCode($width, $height, $autoplay = false)
124+
public function getEmbedCode($width, $height, $autoplay = false, $secure = false)
125125
{
126126
if (false == $this->isEmbeddable()) {
127127
throw new NotEmbeddableException();
128128
}
129129

130-
return $this->getRenderer()->render($this->getEmbedUrl($autoplay), $width, $height);
130+
return $this->getRenderer()->renderVideoEmbedCode($this->getEmbedUrl($autoplay, $secure), $width, $height);
131+
}
132+
133+
/**
134+
* Switches the protocol scheme between http and https
135+
*
136+
* @param bool|false $secure
137+
* @return string
138+
*/
139+
public function getScheme($secure = false)
140+
{
141+
return ($secure ? 'https' : 'http');
131142
}
132143
}

src/Adapter/Factory/CallableServiceAdapterFactoryInterface.php src/Adapter/CallableServiceAdapterFactoryInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 29/08/2015
66
* Time: 14:57.
77
*/
8-
namespace RicardoFiorani\Adapter\Factory;
8+
namespace RicardoFiorani\Adapter;
99

1010
use RicardoFiorani\Adapter\VideoAdapterInterface;
1111
use RicardoFiorani\Renderer\EmbedRendererInterface;

src/Adapter/Dailymotion/DailymotionServiceAdapter.php

+24-17
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class DailymotionServiceAdapter extends AbstractServiceAdapter
1818
/**
1919
* AbstractVideoAdapter constructor.
2020
*
21-
* @param string $url
22-
* @param string $pattern
21+
* @param string $url
22+
* @param string $pattern
2323
* @param EmbedRendererInterface $renderer
2424
*/
2525
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
@@ -64,72 +64,79 @@ public function getThumbNailSizes()
6464

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

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

8181
/**
8282
* Returns the small thumbnail's url.
8383
*
84+
* @param bool $secure
8485
* @return string
86+
* @throws InvalidThumbnailSizeException
8587
*/
86-
public function getSmallThumbnail()
88+
public function getSmallThumbnail($secure = false)
8789
{
8890
//Since this service does not provide other thumbnails sizes we just return the default size
89-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
91+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
9092
}
9193

9294
/**
9395
* Returns the medium thumbnail's url.
9496
*
97+
* @param bool $secure
9598
* @return string
99+
* @throws InvalidThumbnailSizeException
96100
*/
97-
public function getMediumThumbnail()
101+
public function getMediumThumbnail($secure = false)
98102
{
99103
//Since this service does not provide other thumbnails sizes we just return the default size
100-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
104+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
101105
}
102106

103107
/**
104108
* Returns the large thumbnail's url.
105109
*
110+
* @param bool $secure
106111
* @return string
112+
* @throws InvalidThumbnailSizeException
107113
*/
108-
public function getLargeThumbnail()
114+
public function getLargeThumbnail($secure = false)
109115
{
110116
//Since this service does not provide other thumbnails sizes we just return the default size
111-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
117+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
112118
}
113119

114120
/**
115121
* Returns the largest thumnbnaail's url.
116-
*
122+
* @param bool $secure
117123
* @return string
124+
* @throws InvalidThumbnailSizeException
118125
*/
119-
public function getLargestThumbnail()
126+
public function getLargestThumbnail($secure = false)
120127
{
121128
//Since this service does not provide other thumbnails sizes we just return the default size
122-
return $this->getThumbnail(self::THUMBNAIL_DEFAULT);
129+
return $this->getThumbnail(self::THUMBNAIL_DEFAULT, $secure);
123130
}
124131

125132
/**
126133
* @param bool $autoplay
127-
*
134+
* @param bool $secure
128135
* @return string
129136
*/
130-
public function getEmbedUrl($autoplay = false)
137+
public function getEmbedUrl($autoplay = false, $secure = false)
131138
{
132-
return '//www.dailymotion.com/embed/video/'.$this->videoId.($autoplay ? '?amp&autoplay=1' : '');
139+
return $this->getScheme($secure) . '://www.dailymotion.com/embed/video/' . $this->videoId . ($autoplay ? '?amp&autoplay=1' : '');
133140
}
134141

135142
/**

src/Adapter/Dailymotion/Factory/DailymotionServiceAdapterFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace RicardoFiorani\Adapter\Dailymotion\Factory;
99

1010
use RicardoFiorani\Adapter\Dailymotion\DailymotionServiceAdapter;
11-
use RicardoFiorani\Adapter\Factory\CallableServiceAdapterFactoryInterface;
11+
use RicardoFiorani\Adapter\CallableServiceAdapterFactoryInterface;
1212
use RicardoFiorani\Adapter\VideoAdapterInterface;
1313
use RicardoFiorani\Renderer\EmbedRendererInterface;
1414

src/Adapter/Facebook/FacebookServiceAdapter.php

+22-17
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class FacebookServiceAdapter extends AbstractServiceAdapter
1919
/**
2020
* AbstractVideoAdapter constructor.
2121
*
22-
* @param string $url
23-
* @param string $pattern
22+
* @param string $url
23+
* @param string $pattern
2424
* @param EmbedRendererInterface $renderer
2525
*/
2626
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
@@ -33,7 +33,7 @@ public function __construct($url, $pattern, EmbedRendererInterface $renderer)
3333
}
3434

3535
/**
36-
* Returns the service name (ie: "Youtube" or "Vimeo").
36+
* Returns the service name .
3737
*
3838
* @return string
3939
*/
@@ -65,71 +65,76 @@ public function getThumbNailSizes()
6565
/**
6666
* @param string $size
6767
*
68+
* @param bool $secure
6869
* @return string
69-
*
7070
* @throws InvalidThumbnailSizeException
7171
*/
72-
public function getThumbnail($size)
72+
public function getThumbnail($size, $secure = false)
7373
{
7474
if (false == in_array($size, $this->getThumbNailSizes())) {
7575
throw new InvalidThumbnailSizeException();
7676
}
7777

78-
return 'https://graph.facebook.com/'.$this->getVideoId().'/picture';
78+
return $this->getScheme($secure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture';
7979
}
8080

8181
/**
8282
* Returns the small thumbnail's url.
8383
*
84+
* @param bool $secure
8485
* @return string
85-
*
8686
* @throws ThumbnailSizeNotAvailable
8787
*/
88-
public function getSmallThumbnail()
88+
public function getSmallThumbnail($secure = false)
8989
{
9090
throw new ThumbnailSizeNotAvailable();
9191
}
9292

9393
/**
9494
* Returns the medium thumbnail's url.
9595
*
96+
* @param bool $secure
9697
* @return string
98+
* @throws InvalidThumbnailSizeException
9799
*/
98-
public function getMediumThumbnail()
100+
public function getMediumThumbnail($secure = false)
99101
{
100-
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT);
102+
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure);
101103
}
102104

103105
/**
104106
* Returns the large thumbnail's url.
105107
*
108+
* @param bool $secure
106109
* @return string
107-
*
108110
* @throws ThumbnailSizeNotAvailable
109111
*/
110-
public function getLargeThumbnail()
112+
public function getLargeThumbnail($secure = false)
111113
{
112114
throw new ThumbnailSizeNotAvailable();
113115
}
114116

115117
/**
116-
* Returns the largest thumnbnaail's url.
118+
* Returns the largest thumbnail's url.
117119
*
120+
* @param bool $secure
118121
* @return string
122+
* @throws InvalidThumbnailSizeException
119123
*/
120-
public function getLargestThumbnail()
124+
public function getLargestThumbnail($secure = false)
121125
{
122-
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT);
126+
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $secure);
123127
}
124128

125129
/**
126130
* @param bool $autoplay
127131
*
132+
* @param bool $secure
128133
* @return string
129134
*/
130-
public function getEmbedUrl($autoplay = false)
135+
public function getEmbedUrl($autoplay = false, $secure = false)
131136
{
132-
return 'https://www.facebook.com/video/embed?video_id='.$this->getVideoId();
137+
return $this->getScheme($secure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId();
133138
}
134139

135140
/**

src/Adapter/Facebook/Factory/FacebookServiceAdapterFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace RicardoFiorani\Adapter\Facebook\Factory;
99

1010
use RicardoFiorani\Adapter\Facebook\FacebookServiceAdapter;
11-
use RicardoFiorani\Adapter\Factory\CallableServiceAdapterFactoryInterface;
11+
use RicardoFiorani\Adapter\CallableServiceAdapterFactoryInterface;
1212
use RicardoFiorani\Adapter\VideoAdapterInterface;
1313
use RicardoFiorani\Renderer\EmbedRendererInterface;
1414

src/Adapter/VideoAdapterInterface.php

+14-8
Original file line numberDiff line numberDiff line change
@@ -47,46 +47,52 @@ public function getThumbnail($size);
4747
/**
4848
* Returns the small thumbnail's url.
4949
*
50+
* @param bool $secure
5051
* @return string
5152
*/
52-
public function getSmallThumbnail();
53+
public function getSmallThumbnail($secure = false);
5354

5455
/**
5556
* Returns the medium thumbnail's url.
5657
*
58+
* @param bool $secure
5759
* @return string
5860
*/
59-
public function getMediumThumbnail();
61+
public function getMediumThumbnail($secure = false);
6062

6163
/**
6264
* Returns the large thumbnail's url.
6365
*
66+
* @param bool $secure
6467
* @return string
6568
*/
66-
public function getLargeThumbnail();
69+
public function getLargeThumbnail($secure = false);
6770

6871
/**
6972
* Returns the largest thumnbnail's url.
7073
*
74+
* @param bool $secure
7175
* @return string
7276
*/
73-
public function getLargestThumbnail();
77+
public function getLargestThumbnail($secure = false);
7478

7579
/**
7680
* @param bool $autoplay
81+
* @param bool $secure
7782
*
7883
* @return string
7984
*/
80-
public function getEmbedUrl($autoplay = false);
85+
public function getEmbedUrl($autoplay = false, $secure = false);
8186

8287
/**
83-
* @param int $width
84-
* @param int $height
88+
* @param int $width
89+
* @param int $height
8590
* @param bool $autoplay
91+
* @param bool $secure
8692
*
8793
* @return string
8894
*/
89-
public function getEmbedCode($width, $height, $autoplay = false);
95+
public function getEmbedCode($width, $height, $autoplay = false, $secure = false);
9096

9197
/**
9298
* @return bool

src/Adapter/Vimeo/Factory/VimeoServiceAdapterFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88
namespace RicardoFiorani\Adapter\Vimeo\Factory;
99

10-
use RicardoFiorani\Adapter\Factory\CallableServiceAdapterFactoryInterface;
10+
use RicardoFiorani\Adapter\CallableServiceAdapterFactoryInterface;
1111
use RicardoFiorani\Adapter\Vimeo\VimeoServiceAdapter;
1212
use RicardoFiorani\Renderer\EmbedRendererInterface;
1313

0 commit comments

Comments
 (0)