1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace RicardoFiorani\Adapter\Facebook; |
4
|
|
|
|
5
|
|
|
use RicardoFiorani\Adapter\AbstractServiceAdapter; |
6
|
|
|
use RicardoFiorani\Adapter\Exception\InvalidThumbnailSizeException; |
7
|
|
|
use RicardoFiorani\Exception\ThumbnailSizeNotAvailable; |
8
|
|
|
use RicardoFiorani\Renderer\EmbedRendererInterface; |
9
|
|
|
|
10
|
|
|
class FacebookServiceAdapter extends AbstractServiceAdapter |
11
|
|
|
{ |
12
|
|
|
const THUMBNAIL_SIZE_DEFAULT = 'default'; |
13
|
|
|
|
14
|
|
|
public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer) |
15
|
|
|
{ |
16
|
|
|
$match = array(); |
17
|
|
|
preg_match($pattern, $url, $match); |
18
|
|
|
$this->setVideoId($match[1]); |
19
|
|
|
|
20
|
|
|
return parent::__construct($url, $pattern, $renderer); |
|
|
|
|
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function getServiceName(): string |
24
|
|
|
{ |
25
|
|
|
return 'Facebook'; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function hasThumbnail(): bool |
29
|
|
|
{ |
30
|
|
|
return true; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getThumbNailSizes(): array |
34
|
|
|
{ |
35
|
|
|
return array(self::THUMBNAIL_SIZE_DEFAULT); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
View Code Duplication |
public function getThumbnail(string $size, bool $forceSecure = false): string |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
if (false == in_array($size, $this->getThumbNailSizes())) { |
|
|
|
|
41
|
|
|
throw new InvalidThumbnailSizeException(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->getScheme($forceSecure) . '://graph.facebook.com/' . $this->getVideoId() . '/picture'; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @throws ThumbnailSizeNotAvailable |
49
|
|
|
*/ |
50
|
|
|
public function getSmallThumbnail(bool $forceSecure = false): string |
51
|
|
|
{ |
52
|
|
|
throw new ThumbnailSizeNotAvailable(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @throws InvalidThumbnailSizeException |
57
|
|
|
*/ |
58
|
|
|
public function getMediumThumbnail(bool $forceSecure = false): string |
59
|
|
|
{ |
60
|
|
|
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @throws ThumbnailSizeNotAvailable |
65
|
|
|
*/ |
66
|
|
|
public function getLargeThumbnail(bool $forceSecure = false): string |
67
|
|
|
{ |
68
|
|
|
throw new ThumbnailSizeNotAvailable(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @throws InvalidThumbnailSizeException |
73
|
|
|
*/ |
74
|
|
|
public function getLargestThumbnail(bool $forceSecure = false): string |
75
|
|
|
{ |
76
|
|
|
return $this->getThumbnail(self::THUMBNAIL_SIZE_DEFAULT, $forceSecure); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getEmbedUrl(bool $forceAutoplay = false, bool $forceSecure = false): string |
80
|
|
|
{ |
81
|
|
|
return $this->getScheme($forceSecure) . '://www.facebook.com/video/embed?video_id=' . $this->getVideoId(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function isEmbeddable(): bool |
85
|
|
|
{ |
86
|
|
|
return true; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|