Skip to content

Commit 7904e78

Browse files
author
Ricardo Fiorani
committed
General refactoring for v1.0.0
1 parent c870031 commit 7904e78

20 files changed

+94
-45
lines changed

src/Adapter/AbstractServiceAdapter.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
* Date: 29/08/2015
66
* Time: 19:37.
77
*/
8+
89
namespace RicardoFiorani\Adapter;
910

10-
use RicardoFiorani\Exception\NotEmbeddableException;
11+
use RicardoFiorani\Adapter\Exception\InvalidUrlException;
12+
use RicardoFiorani\Adapter\Exception\NotEmbeddableException;
1113
use RicardoFiorani\Renderer\EmbedRendererInterface;
1214

1315
abstract class AbstractServiceAdapter implements VideoAdapterInterface
@@ -123,8 +125,10 @@ public function setRenderer($renderer)
123125
*/
124126
public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false)
125127
{
126-
if (false == $this->isEmbeddable()) {
127-
throw new NotEmbeddableException();
128+
if (false === $this->isEmbeddable()) {
129+
throw new NotEmbeddableException(
130+
sprintf('The service "%s" does not provide embeddable videos', $this->getServiceName())
131+
);
128132
}
129133

130134
return $this->getRenderer()->renderVideoEmbedCode(
@@ -139,13 +143,25 @@ public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecu
139143
*
140144
* @param bool|false $forceSecure
141145
* @return string
146+
* @throws InvalidUrlException
142147
*/
143148
public function getScheme($forceSecure = false)
144149
{
145150
if ($forceSecure) {
146151
return 'https';
147152
}
148153

149-
return parse_url($this->rawUrl, PHP_URL_SCHEME);
154+
$parsedUrlSchema = parse_url($this->rawUrl, PHP_URL_SCHEME);
155+
156+
if (false !== $parsedUrlSchema) {
157+
return $parsedUrlSchema;
158+
}
159+
160+
throw new InvalidUrlException(sprintf('The URL %s is not valid', $this->rawUrl));
161+
}
162+
163+
public function isThumbnailSizeAvailable($intendedSize)
164+
{
165+
return in_array($intendedSize, $this->getThumbNailSizes());
150166
}
151167
}

src/Adapter/Dailymotion/DailymotionServiceAdapter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace RicardoFiorani\Adapter\Dailymotion;
99

1010
use RicardoFiorani\Adapter\AbstractServiceAdapter;
11-
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
11+
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
1212
use RicardoFiorani\Renderer\EmbedRendererInterface;
1313

1414
class DailymotionServiceAdapter extends AbstractServiceAdapter
@@ -68,6 +68,7 @@ public function getThumbNailSizes()
6868
*
6969
* @return string
7070
* @throws InvalidThumbnailSizeException
71+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
7172
*/
7273
public function getThumbnail($size, $forceSecure = false)
7374
{
@@ -84,6 +85,7 @@ public function getThumbnail($size, $forceSecure = false)
8485
* @param bool $forceSecure
8586
* @return string
8687
* @throws InvalidThumbnailSizeException
88+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
8789
*/
8890
public function getSmallThumbnail($forceSecure = false)
8991
{
@@ -97,6 +99,7 @@ public function getSmallThumbnail($forceSecure = false)
9799
* @param bool $forceSecure
98100
* @return string
99101
* @throws InvalidThumbnailSizeException
102+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
100103
*/
101104
public function getMediumThumbnail($forceSecure = false)
102105
{
@@ -110,6 +113,7 @@ public function getMediumThumbnail($forceSecure = false)
110113
* @param bool $forceSecure
111114
* @return string
112115
* @throws InvalidThumbnailSizeException
116+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
113117
*/
114118
public function getLargeThumbnail($forceSecure = false)
115119
{
@@ -122,6 +126,7 @@ public function getLargeThumbnail($forceSecure = false)
122126
* @param bool $forceSecure
123127
* @return string
124128
* @throws InvalidThumbnailSizeException
129+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
125130
*/
126131
public function getLargestThumbnail($forceSecure = false)
127132
{
@@ -133,6 +138,7 @@ public function getLargestThumbnail($forceSecure = false)
133138
* @param bool $forceAutoplay
134139
* @param bool $forceSecure
135140
* @return string
141+
* @throws \RicardoFiorani\Adapter\Exception\InvalidUrlException
136142
*/
137143
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
138144
{

src/Exception/InvalidThumbnailSizeException.php renamed to src/Adapter/Exception/InvalidThumbnailSizeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 29/08/2015
66
* Time: 20:17.
77
*/
8-
namespace RicardoFiorani\Exception;
8+
namespace RicardoFiorani\Adapter\Exception;
99

1010
use Exception;
1111

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* @author Ricardo Fiorani
4+
*/
5+
6+
namespace RicardoFiorani\Adapter\Exception;
7+
8+
use Exception;
9+
10+
class InvalidUrlException extends Exception
11+
{
12+
}

src/Exception/NotEmbeddableException.php renamed to src/Adapter/Exception/NotEmbeddableException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 30/08/2015
66
* Time: 01:25.
77
*/
8-
namespace RicardoFiorani\Exception;
8+
namespace RicardoFiorani\Adapter\Exception;
99

1010
use Exception;
1111

src/Exception/ServiceApiNotAvailable.php renamed to src/Adapter/Exception/ServiceApiNotAvailable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 10/02/2016
66
* Time: 18:13.
77
*/
8-
namespace RicardoFiorani\Exception;
8+
namespace RicardoFiorani\Adapter\Exception;
99

1010
use Exception;
1111

src/Adapter/Facebook/FacebookServiceAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace RicardoFiorani\Adapter\Facebook;
99

1010
use RicardoFiorani\Adapter\AbstractServiceAdapter;
11-
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
11+
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
1212
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable;
1313
use RicardoFiorani\Renderer\EmbedRendererInterface;
1414

src/Adapter/Vimeo/VimeoServiceAdapter.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
namespace RicardoFiorani\Adapter\Vimeo;
99

1010
use RicardoFiorani\Adapter\AbstractServiceAdapter;
11-
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
12-
use RicardoFiorani\Exception\ServiceApiNotAvailable;
11+
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
12+
use RicardoFiorani\Adapter\Exception\InvalidUrlException;
13+
use RicardoFiorani\Adapter\Exception\ServiceApiNotAvailable;
1314
use RicardoFiorani\Renderer\EmbedRendererInterface;
1415

1516
class VimeoServiceAdapter extends AbstractServiceAdapter
@@ -37,6 +38,7 @@ class VimeoServiceAdapter extends AbstractServiceAdapter
3738
* @param string $url
3839
* @param string $pattern
3940
* @param EmbedRendererInterface $renderer
41+
* @throws ServiceApiNotAvailable
4042
*/
4143
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
4244
{
@@ -120,10 +122,11 @@ private function setThumbnails(array $thumbnails)
120122

121123
/**
122124
* @param string $size
123-
*
125+
* @param bool $forceSecure
124126
* @return string
125127
*
126128
* @throws InvalidThumbnailSizeException
129+
* @throws InvalidUrlException
127130
*/
128131
public function getThumbnail($size, $forceSecure = false)
129132
{
@@ -143,6 +146,7 @@ public function getThumbnail($size, $forceSecure = false)
143146
* @param bool $forceAutoplay
144147
*
145148
* @return string
149+
* @throws InvalidUrlException
146150
*/
147151
public function getEmbedUrl($forceAutoplay = false, $forceSecure = false)
148152
{
@@ -169,6 +173,7 @@ public function getThumbNailSizes()
169173
* @param bool $forceSecure
170174
* @return string
171175
* @throws InvalidThumbnailSizeException
176+
* @throws InvalidUrlException
172177
*/
173178
public function getSmallThumbnail($forceSecure = false)
174179
{
@@ -181,6 +186,7 @@ public function getSmallThumbnail($forceSecure = false)
181186
* @param bool $forceSecure
182187
* @return string
183188
* @throws InvalidThumbnailSizeException
189+
* @throws InvalidUrlException
184190
*/
185191
public function getMediumThumbnail($forceSecure = false)
186192
{
@@ -191,9 +197,9 @@ public function getMediumThumbnail($forceSecure = false)
191197
* Returns the large thumbnail's url.
192198
*
193199
* @param bool $forceSecure
194-
* @param $forceSecure
195200
* @return string
196201
* @throws InvalidThumbnailSizeException
202+
* @throws InvalidUrlException
197203
*/
198204
public function getLargeThumbnail($forceSecure = false)
199205
{
@@ -204,9 +210,9 @@ public function getLargeThumbnail($forceSecure = false)
204210
* Returns the largest thumnbnaail's url.
205211
*
206212
* @param bool $forceSecure
207-
* @param $forceSecure
208213
* @return string
209214
* @throws InvalidThumbnailSizeException
215+
* @throws InvalidUrlException
210216
*/
211217
public function getLargestThumbnail($forceSecure = false)
212218
{
@@ -249,7 +255,10 @@ private function getVideoDataFromServiceApi()
249255
{
250256
$contents = file_get_contents('http://vimeo.com/api/v2/video/' . $this->getVideoId() . '.php');
251257
if (false === $contents) {
252-
throw new ServiceApiNotAvailable('Vimeo Service Adapter could not reach Vimeo API Service. Check if your server has file_get_contents() function available.');
258+
throw new ServiceApiNotAvailable(
259+
'Service "%s" could not reach it\'s API. Check if file_get_contents() function is available.',
260+
$this->getServiceName()
261+
);
253262
}
254263
$hash = unserialize($contents);
255264

src/Adapter/Youtube/YoutubeServiceAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace RicardoFiorani\Adapter\Youtube;
1010

1111
use RicardoFiorani\Adapter\AbstractServiceAdapter;
12-
use RicardoFiorani\Exception\InvalidThumbnailSizeException;
12+
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException;
1313
use RicardoFiorani\Renderer\EmbedRendererInterface;
1414

1515
class YoutubeServiceAdapter extends AbstractServiceAdapter

src/Exception/DuplicatedServiceNameException.php renamed to src/Container/Exception/DuplicatedServiceNameException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Date: 29/08/2015
66
* Time: 23:28.
77
*/
8-
namespace RicardoFiorani\Exception;
8+
namespace RicardoFiorani\Container\Exception;
99

1010
use Exception;
1111

0 commit comments

Comments
 (0)