Skip to content

Commit 7d35f75

Browse files
a lot of fixes and aditions such as additions of Renderers, Refactorations and better naming conventions, and better interfaces implementations
1 parent 795677c commit 7d35f75

19 files changed

+536
-102
lines changed

.travis.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use Docker environment
2+
sudo: false
3+
4+
# Setup build matrix
5+
language: php
6+
php:
7+
- 5.3
8+
- 5.4
9+
- 5.5
10+
- 5.6
11+
- 7.0
12+
- hhvm
13+
14+
# Dependencies
15+
before_install:
16+
- composer self-update
17+
18+
install:
19+
- travis_retry composer update --no-interaction --prefer-source
20+
21+
script: phpunit
22+
23+
# Cache dependencies
24+
cache:
25+
directories:
26+
- vendor
27+
- $HOME/.composer/cache

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# PHP Video URL Parser
22
Simple Video Parser in PHP
3+
4+
# TODO List goals for release 1.0:
5+
6+
Create examples showing how to use this:
7+
-Examples must show how to create and register a new ServiceAdapter
8+
-Examples must show how to set a Third Party Renderer such as Twig, Smarty, Mustache or Blade
9+
10+
Fix the Exceptions Messages
11+
12+
Create PHPUnit Tests

config/config.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66
* Time: 14:34
77
*/
88

9-
/**
10-
* Array with Available Services
11-
*/
129
return array(
13-
'Vimeo' => array(
14-
'patterns' => array(
15-
'#(https?://vimeo.com)/([0-9]+)#i'
10+
'services' => array(
11+
'Vimeo' => array(
12+
'patterns' => array(
13+
'#(https?://vimeo.com)/([0-9]+)#i'
14+
),
15+
'factory' => '\\RicardoFiorani\\Adapter\\Vimeo\\Factory\\VimeoServiceAdapterFactory',
1616
),
17-
'factory' => 'RicardoFiorani\\Adapter\\Vimeo\\Factory\\VimeoServiceAdapterFactory',
18-
),
19-
'Youtube' => array(
20-
'patterns' => array(
21-
'#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#',
22-
'%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i',
17+
'Youtube' => array(
18+
'patterns' => array(
19+
'#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#',
20+
'%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i',
21+
),
22+
'factory' => '\\RicardoFiorani\\Adapter\\Youtube\\Factory\\YoutubeServiceAdapterFactory',
2323
),
24-
'factory' => 'RicardoFiorani\\Container\\Youtube\\Factory\\YoutubeVideoContainerFactory',
2524
),
25+
'renderer' => array(
26+
'name' => 'DefaultRenderer',
27+
'factory' => '\\RicardoFiorani\\Renderer\\Factory\\DefaultRendererFactory',
28+
)
2629
);

phpunit.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php" colors="true">
3+
4+
<filter>
5+
<whitelist>
6+
<directory suffix=".php">./src</directory>
7+
</whitelist>
8+
</filter>
9+
10+
<testsuites>
11+
<testsuite name="PHP Video URL Parser Test Suite">
12+
<directory>./test</directory>
13+
</testsuite>
14+
</testsuites>
15+
</phpunit>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: Ricardo Fiorani
5+
* Date: 29/08/2015
6+
* Time: 19:37
7+
*/
8+
9+
namespace RicardoFiorani\Adapter;
10+
11+
12+
use RicardoFiorani\Exception\NotEmbedableException;
13+
use RicardoFiorani\Renderer\EmbedRendererInterface;
14+
15+
abstract class AbstractServiceAdapter implements VideoAdapterInterface
16+
{
17+
/**
18+
* @var string
19+
*/
20+
public $rawUrl;
21+
22+
/**
23+
* @var string
24+
*/
25+
public $videoId;
26+
27+
/**
28+
* @var string
29+
*/
30+
public $pattern;
31+
32+
/**
33+
* @var EmbedRendererInterface
34+
*/
35+
public $renderer;
36+
37+
/**
38+
* AbstractVideoAdapter constructor.
39+
* @param string $url
40+
* @param string $pattern
41+
* @param EmbedRendererInterface $renderer
42+
*/
43+
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
44+
{
45+
$this->rawUrl = $url;
46+
$this->pattern = $pattern;
47+
$this->renderer = $renderer;
48+
}
49+
50+
/**
51+
* Returns the input URL
52+
* @return string
53+
*/
54+
public function getRawUrl()
55+
{
56+
return $this->rawUrl;
57+
}
58+
59+
/**
60+
* @param string $rawUrl
61+
*/
62+
public function setRawUrl($rawUrl)
63+
{
64+
$this->rawUrl = $rawUrl;
65+
}
66+
67+
/**
68+
* @return string
69+
*/
70+
public function getVideoId()
71+
{
72+
return $this->videoId;
73+
}
74+
75+
/**
76+
* @param string $videoId
77+
*/
78+
public function setVideoId($videoId)
79+
{
80+
$this->videoId = $videoId;
81+
}
82+
83+
/**
84+
* @return string
85+
*/
86+
public function getPattern()
87+
{
88+
return $this->pattern;
89+
}
90+
91+
/**
92+
* @param string $pattern
93+
*/
94+
public function setPattern($pattern)
95+
{
96+
$this->pattern = $pattern;
97+
}
98+
99+
/**
100+
* @return EmbedRendererInterface
101+
*/
102+
public function getRenderer()
103+
{
104+
return $this->renderer;
105+
}
106+
107+
/**
108+
* @param EmbedRendererInterface $renderer
109+
*/
110+
public function setRenderer($renderer)
111+
{
112+
$this->renderer = $renderer;
113+
}
114+
115+
/**
116+
* @param int $width
117+
* @param int $height
118+
* @return string
119+
* @throws NotEmbedableException
120+
*/
121+
public function getEmbedCode($width, $height)
122+
{
123+
if (false == $this->isEmbedable()) {
124+
throw new NotEmbedableException();
125+
}
126+
127+
return $this->getRenderer()->render($this->getEmbedUrl(), $width, $height);
128+
}
129+
130+
131+
}

src/Adapter/AbstractServiceContainer.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/Adapter/Factory/CallableFactoryInterface.php renamed to src/Adapter/Factory/CallableServiceAdapterFactoryInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111

1212
use RicardoFiorani\Adapter\VideoAdapterInterface;
13+
use RicardoFiorani\Renderer\EmbedRendererInterface;
1314

14-
interface CallableFactoryInterface
15+
interface CallableServiceAdapterFactoryInterface
1516
{
1617
/**
1718
* @param string $url
1819
* @param string $pattern
20+
* @param EmbedRendererInterface $renderer
1921
* @return VideoAdapterInterface
2022
*/
21-
public function __invoke($url, $pattern);
23+
public function __invoke($url, $pattern, EmbedRendererInterface $renderer);
2224
}

src/Adapter/VideoAdapterInterface.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
namespace RicardoFiorani\Adapter;
1010

1111

12+
use RicardoFiorani\Renderer\EmbedRendererInterface;
13+
1214
interface VideoAdapterInterface
1315
{
1416
/**
1517
* @param string $url
1618
* @param string $pattern
19+
* @param EmbedRendererInterface $renderer
1720
*/
18-
public function __construct($url, $pattern);
21+
public function __construct($url, $pattern, EmbedRendererInterface $renderer);
1922

2023
/**
2124
* Returns the service name (ie: "Youtube" or "Vimeo")
@@ -47,9 +50,46 @@ public function getThumbNailSizes();
4750
*/
4851
public function getThumbnail($size);
4952

53+
/**
54+
* Returns the small thumbnail's url
55+
* @return string
56+
*/
57+
public function getSmallThumbnail();
58+
59+
/**
60+
* Returns the medium thumbnail's url
61+
* @return string
62+
*/
63+
public function getMediumThumbnail();
64+
65+
/**
66+
* Returns the large thumbnail's url
67+
* @return string
68+
*/
69+
public function getLargeThumbnail();
70+
71+
/**
72+
* Returns the largest thumnbnaail's url
73+
* @return string
74+
*/
75+
public function getLargestThumbnail();
76+
5077
/**
5178
* @param bool $autoplay
5279
* @return string
5380
*/
5481
public function getEmbedUrl($autoplay = false);
82+
83+
/**
84+
* @param integer $width
85+
* @param integer $height
86+
* @return string
87+
*/
88+
public function getEmbedCode($width, $height);
89+
90+
/**
91+
* @return bool
92+
*/
93+
public function isEmbedable();
94+
5595
}

0 commit comments

Comments
 (0)