Skip to content

Commit 1dc6ae0

Browse files
author
Ricardo Fiorani
committed
updated documentation
1 parent a4f18f4 commit 1dc6ae0

File tree

2 files changed

+90
-61
lines changed

2 files changed

+90
-61
lines changed

Diff for: README.md

+13-61
Original file line numberDiff line numberDiff line change
@@ -71,71 +71,23 @@ A Fully functional example can be found [Here](https://github.com/ricardofiorani
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

7373
## Using your own framework's template engine
74-
In this project I've used a simple renderer (which 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.
74+
A Fully functional example can be found [Here](https://github.com/ricardofiorani/php-video-url-parser/tree/master/documentation/IntegratingYourOwnRenderer.md).
7575

76-
Here's an example:
77-
### My Example Renderer Class
78-
```php
79-
<?php
80-
namespace MyVendor\MyRenderer;
81-
82-
class MyOwnRenderer implements \RicardoFiorani\Renderer\EmbedRendererInterface
83-
{
84-
85-
/**
86-
* @param string $embedUrl
87-
* @param integer $height
88-
* @param integer $width
89-
* @return string
90-
*/
91-
public function render($embedUrl, $height, $width)
92-
{
93-
//Just for example porpoises
94-
return sprintf("Hello, I'm embedding %s", addslashes($embedUrl));
95-
96-
//A functional example would be like
97-
//return '<iframe width="' . $width . '" height="' . $height . '" src="' . addslashes($embedUrl) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
98-
}
99-
}
100-
```
101-
### My Example Renderer Factory Class
102-
```php
103-
<?php
104-
namespace MyVendor\MyRenderer\Factory;
105-
106-
class MyOwnRendererFactory implements RendererFactoryInterface
107-
{
108-
/**
109-
* @return EmbedRendererInterface
110-
*/
111-
public function __invoke()
112-
{
113-
return new MyOwnRenderer();
114-
}
115-
}
116-
```
117-
### Registering my renderer
118-
119-
```php
120-
<?php
121-
use RicardoFiorani\Matcher\VideoServiceMatcher;
122-
123-
require __DIR__ . '/vendor/autoload.php';
124-
125-
$vsm = new VideoServiceMatcher();
126-
127-
//This is where the magic is done
128-
$vsm->getServiceContainer()->setRenderer('MyOwnRenderer', 'MyVendor\\MyRenderer\\Factory\\MyOwnRendererFactory');
129-
130-
$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');
131-
132-
//This will output "Hello, I'm embedding http://www.youtube.com/embed/PkOcm_XaWrw"
133-
echo $video->getEmbedCode(500,500);
134-
135-
```
13676

13777
### Currently Suported Services
13878
* Youtube
13979
* Vimeo
14080
* Dailymotion
14181
* Facebook Videos
82+
83+
### Currently Supported PHP Versions
84+
* PHP 5.3
85+
* PHP 5.4
86+
* PHP 5.5
87+
* PHP 5.6
88+
* PHP 7.0
89+
* PHP 7.1
90+
* PHP 7.2
91+
92+
> Please note that even this lib is not passing tests on HHVM, we can't guarantee. Please use it on your own risk.
93+

Diff for: documentation/IntegratingYourOwnRenderer.md

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Functional Example of Integrating your own renderer
2+
In this project I've used a simple renderer (which just does an echo of an iframe) but you can use your own implementation.
3+
First, It must follow the RicardoFiorani\Renderer\EmbedRendererInterface interface.
4+
5+
Basically you need two classes:
6+
7+
* The Renderer Implementation
8+
* The Renderer's Factory
9+
10+
The examples can be seem below:
11+
12+
### My Renderer Implementation Class
13+
This is the concrete implementation on how your renderer is going to handle the embed URL to give you an embed code.
14+
In here you can inject any dependency you might need by the constructor and add any logic you need.
15+
Please note that it should implement the interface "\RicardoFiorani\Renderer\EmbedRendererInterface".
16+
```php
17+
<?php
18+
namespace MyVendor\MyRenderer;
19+
use \RicardoFiorani\Renderer\EmbedRendererInterface;
20+
21+
class MyOwnRenderer implements EmbedRendererInterface
22+
{
23+
/**
24+
* @param string $embedUrl
25+
* @param integer $height
26+
* @param integer $width
27+
* @return string
28+
*/
29+
public function renderVideoEmbedCode($embedUrl, $height, $width)
30+
{
31+
//Just for example porpoises
32+
return sprintf("Hello, I'm embedding %s", addslashes($embedUrl));
33+
34+
//A functional example would be like
35+
//return '<iframe width="' . $width . '" height="' . $height . '" src="' . addslashes($embedUrl) . '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
36+
}
37+
}
38+
```
39+
### My Renderer Implementation Factory Class
40+
This is the Factory of your renderer, basically all it must do is to implement the interface RicardoFiorani\Renderer\Factory\RendererFactoryInterface
41+
```php
42+
<?php
43+
namespace MyVendor\MyRenderer\Factory;
44+
use RicardoFiorani\Renderer\EmbedRendererInterface;
45+
use RicardoFiorani\Renderer\Factory\RendererFactoryInterface;
46+
47+
class MyOwnRendererFactory implements RendererFactoryInterface
48+
{
49+
/**
50+
* @return EmbedRendererInterface
51+
*/
52+
public function __invoke()
53+
{
54+
return new MyOwnRenderer();
55+
}
56+
}
57+
```
58+
### Registering my renderer
59+
60+
The last part is attaching your own renderer service to the VideoServiceMatcher, which can be done as the example that follows:
61+
62+
```php
63+
<?php
64+
use RicardoFiorani\Matcher\VideoServiceMatcher;
65+
66+
require __DIR__ . '/vendor/autoload.php';
67+
68+
$vsm = new VideoServiceMatcher();
69+
70+
//This is where you attach your own renderer to be used instead of the default one
71+
$vsm->getServiceContainer()->setRenderer('MyOwnRenderer', MyVendor\MyRenderer\Factory\MyOwnRendererFactory::class);
72+
73+
$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');
74+
75+
//This will output "Hello, I'm embedding http://www.youtube.com/embed/PkOcm_XaWrw"
76+
echo $video->getEmbedCode(500,500);
77+
```

0 commit comments

Comments
 (0)