Skip to content

Commit 14c2653

Browse files
Look Harry, we are almost there... I can see the version 1.0 coming Harry
1 parent c9da906 commit 14c2653

File tree

5 files changed

+79
-24
lines changed

5 files changed

+79
-24
lines changed

README.md

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,74 @@ echo $video->getLargestThumbnail();
5151
## Registering your own service video (it's easy !)
5252
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
5353

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

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

57-
# TODO List goals for release 1.0:
58+
## Using your own framework's template engine
59+
In this project I've used a simple renderer (wich just does an echo of an iframe) but you can use your own implementation. It must follow the RicardoFiorani\Renderer\EmbedRendererInterface and just like that.
60+
61+
Here's an example:
62+
### My Example Renderer Class
63+
```php
64+
namespace MyVendor\MyRenderer;
65+
66+
67+
class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface
68+
{
69+
70+
/**
71+
* @param string $embedUrl
72+
* @param integer $height
73+
* @param integer $width
74+
* @return string
75+
*/
76+
public function render($embedUrl, $height, $width)
77+
{
78+
//Just for example porpoises
79+
return "Hell yeah baby, you've rendered: ".addslashes($embedUrl);
80+
81+
//A functional example would be like
82+
//return '<iframe width="' . $width . '" height="' . $height . '" src="' . addslashes($embedUrl) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
83+
}
84+
}
85+
```
86+
### My Example Renderer Factory Class
87+
```php
88+
namespace MyVendor\MyRenderer\Factory;
89+
90+
class MyOwnRendererFactory implements RendererFactoryInterface
91+
{
92+
/**
93+
* @return EmbedRendererInterface
94+
*/
95+
public function __invoke()
96+
{
97+
$renderer = new MyOwnRenderer();
98+
}
99+
}
100+
```
101+
### Registering my renderer
102+
103+
```php
104+
<?php
105+
use RicardoFiorani\Detector\VideoServiceDetector;
58106

59-
Create examples showing how to use this:
60-
-Examples must show how to create and register a new ServiceAdapter
61-
-Examples must show how to set a Third Party Renderer such as Twig, Smarty, Mustache or Blade
62-
63-
Fix the Exceptions Messages
107+
require __DIR__ . '/vendor/autoload.php';
108+
109+
$vsd = new VideoServiceDetector();
110+
111+
//This is where the magic os done
112+
$vsd->setRenderer('MyOwnRenderer', 'MyVendor\\MyRenderer\\Factory\\MyOwnRendererFactory');
113+
114+
$video = $vsd->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');
115+
116+
//This will output "Hell yeah baby, you've rendered: http://www.youtube.com/embed/PkOcm_XaWrw"
117+
echo $video->getEmbedCode(500,500);
118+
119+
```
120+
121+
# TODO List goals for release 1.0:
64122

65-
Create PHPUnit Tests
123+
* Fix the Exceptions Messages
124+
* Create PHPUnit Tests

src/Adapter/AbstractServiceAdapter.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
namespace RicardoFiorani\Adapter;
1010

1111

12-
use RicardoFiorani\Exception\NotEmbedableException;
12+
use RicardoFiorani\Exception\NotEmbeddableException;
1313
use RicardoFiorani\Renderer\EmbedRendererInterface;
1414

1515
abstract class AbstractServiceAdapter implements VideoAdapterInterface
@@ -115,16 +115,17 @@ public function setRenderer($renderer)
115115
/**
116116
* @param int $width
117117
* @param int $height
118+
* @param bool $autoplay
118119
* @return string
119-
* @throws NotEmbedableException
120+
* @throws NotEmbeddableException
120121
*/
121-
public function getEmbedCode($width, $height)
122+
public function getEmbedCode($width, $height, $autoplay = false)
122123
{
123-
if (false == $this->isEmbedable()) {
124-
throw new NotEmbedableException();
124+
if (false == $this->isEmbeddable()) {
125+
throw new NotEmbeddableException();
125126
}
126127

127-
return $this->getRenderer()->render($this->getEmbedUrl(), $width, $height);
128+
return $this->getRenderer()->render($this->getEmbedUrl($autoplay), $width, $height);
128129
}
129130

130131

src/Adapter/VideoAdapterInterface.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313

1414
interface VideoAdapterInterface
1515
{
16-
/**
17-
* @param string $url
18-
* @param string $pattern
19-
* @param EmbedRendererInterface $renderer
20-
*/
21-
public function __construct($url, $pattern, EmbedRendererInterface $renderer);
2216

2317
/**
2418
* Returns the service name (ie: "Youtube" or "Vimeo")
@@ -83,13 +77,14 @@ public function getEmbedUrl($autoplay = false);
8377
/**
8478
* @param integer $width
8579
* @param integer $height
80+
* @param bool $autoplay
8681
* @return string
8782
*/
88-
public function getEmbedCode($width, $height);
83+
public function getEmbedCode($width, $height, $autoplay = false);
8984

9085
/**
9186
* @return bool
9287
*/
93-
public function isEmbedable();
88+
public function isEmbeddable();
9489

9590
}

src/Adapter/Vimeo/VimeoServiceAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function getLargestThumbnail()
216216
/**
217217
* @return bool
218218
*/
219-
public function isEmbedable()
219+
public function isEmbeddable()
220220
{
221221
return true;
222222
}

src/Adapter/Youtube/YoutubeServiceAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function getLargestThumbnail()
135135
/**
136136
* @return bool
137137
*/
138-
public function isEmbedable()
138+
public function isEmbeddable()
139139
{
140140
return true;
141141
}

0 commit comments

Comments
 (0)