Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.0.0-beta #8

Closed
wants to merge 13 commits into from
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@ sudo: false
# Setup build matrix
language: php
php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

matrix:
include:
- php: 5.3
dist: precise

# Dependencies
before_install:
- composer self-update
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ A Fully functional example can be found [Here](https://github.com/ricardofiorani
* Facebook Videos

## Currently Supported PHP Versions
* PHP 5.3
* PHP 5.4
* PHP 5.5
* PHP 5.6
* PHP 7.0
* PHP 7.1
* PHP 7.2

Expand Down
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
"name": "ricardofiorani/php-video-url-parser",
"description": "A Simple and efficient PHP Video URL Parser that gives you thumbnails and embed codes for various services as Youtube, Vimeo, DailyMotion and Facebook",
"require-dev": {
"phpunit/phpunit": "^4.8",
"fabpot/php-cs-fixer" : ">= 1.0"
"phpunit/phpunit": "^7.2",
"friendsofphp/php-cs-fixer": "^2.12",
"mockery/mockery": "^1.1",
"zendframework/zend-diactoros": "^1.8"
},
"license": "MIT",
"authors": [
Expand All @@ -13,11 +15,16 @@
}
],
"require": {
"php": ">=5.3"
"php": ">=7.1",
"psr/simple-cache": "^1.0",
"roave/doctrine-simplecache": "^2.1"
},
"autoload": {
"psr-4": {
"RicardoFiorani\\": "src/"
}
},
"scripts": {
"test": "php vendor/bin/phpunit"
}
}
17 changes: 5 additions & 12 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: Ricardo Fiorani
* Date: 29/08/2015
* Time: 14:34
*/

return array(
'services' => array(
Expand All @@ -13,20 +7,20 @@
'#(https?://vimeo.com)/([0-9]+)#i',
'#(https?://vimeo.com)/channels/staffpicks/([0-9]+)#i',
),
'factory' => '\\RicardoFiorani\\Adapter\\Vimeo\\Factory\\VimeoServiceAdapterFactory',
'factory' => \RicardoFiorani\Adapter\Vimeo\Factory\VimeoServiceAdapterFactory::class,
),
'Youtube' => array(
'patterns' => array(
'#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#',
'%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i',
),
'factory' => '\\RicardoFiorani\\Adapter\\Youtube\\Factory\\YoutubeServiceAdapterFactory',
'factory' => \RicardoFiorani\Adapter\Youtube\Factory\YoutubeServiceAdapterFactory::class,
),
'Dailymotion' => array(
'patterns' => array(
'#https?://www.dailymotion.com/video/([A-Za-z0-9]+)#s',
),
'factory' => '\\RicardoFiorani\\Adapter\\Dailymotion\\Factory\\DailymotionServiceAdapterFactory',
'factory' => \RicardoFiorani\Adapter\Dailymotion\Factory\DailymotionServiceAdapterFactory::class,
),
'Facebook' => array(
'patterns' => array(
Expand All @@ -35,11 +29,10 @@
'~^https?://www\.facebook\.com/.*?/videos/(\d+)/?$~m',

),
'factory' => '\\RicardoFiorani\\Adapter\\Facebook\\Factory\\FacebookServiceAdapterFactory',
'factory' => \RicardoFiorani\Adapter\Facebook\Factory\FacebookServiceAdapterFactory::class,
),
),
'renderer' => array(
'name' => 'DefaultRenderer',
'factory' => '\\RicardoFiorani\\Renderer\\Factory\\DefaultRendererFactory',
'factory' => \RicardoFiorani\Renderer\Factory\DefaultRendererFactory::class,
)
);
2 changes: 1 addition & 1 deletion documentation/IntegratingYourOwnRenderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require __DIR__ . '/vendor/autoload.php';
$vsm = new VideoServiceMatcher();

//This is where you attach your own renderer to be used instead of the default one
$vsm->getServiceContainer()->setRenderer('MyOwnRenderer', MyVendor\MyRenderer\Factory\MyOwnRendererFactory::class);
$vsm->getServiceContainer()->setRenderer(new MyVendor\MyRenderer\Factory\MyOwnRendererFactory());

$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');

Expand Down
2 changes: 1 addition & 1 deletion documentation/RegisteringANewService.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ $patterns = array(
);

//Register the new service
$vsd->getServiceContainer()->registerService($serviceName, $patterns, MyVendor\ServiceAdapter\Factory\DailymotionServiceAdapterFactory::class);
$vsd->getServiceContainer()->registerService($serviceName, $patterns, new MyVendor\ServiceAdapter\Factory\DailymotionServiceAdapterFactory());

//This will get you an DailymotionServiceAdapter
$video = $vsd->parse('http://www.dailymotion.com/video/x33ncwc_kittens-fight-in-tiny-boxing-ring_animals');
Expand Down
118 changes: 37 additions & 81 deletions src/Adapter/AbstractServiceAdapter.php
Original file line number Diff line number Diff line change
@@ -1,130 +1,78 @@
<?php
/**
* Created by PhpStorm.
* User: Ricardo Fiorani
* Date: 29/08/2015
* Time: 19:37.
*/
<?php declare(strict_types=1);

namespace RicardoFiorani\Adapter;

use RicardoFiorani\Exception\NotEmbeddableException;
use RicardoFiorani\Adapter\Exception\InvalidUrlException;
use RicardoFiorani\Adapter\Exception\NotEmbeddableException;
use RicardoFiorani\Renderer\EmbedRendererInterface;

abstract class AbstractServiceAdapter implements VideoAdapterInterface
{
/**
* @var string
*/
public $rawUrl;

/**
* @var string
*/
public $videoId;

/**
* @var string
*/
public $pattern;

/**
* @var EmbedRendererInterface
*/
public $renderer;

/**
* AbstractVideoAdapter constructor.
*
* @param string $url
* @param string $pattern
* @param EmbedRendererInterface $renderer
*/
public function __construct($url, $pattern, EmbedRendererInterface $renderer)
public function __construct(string $url, string $pattern, EmbedRendererInterface $renderer)
{
$this->rawUrl = $url;
$this->pattern = $pattern;
$this->renderer = $renderer;
}

/**
* Returns the input URL.
*
* @return string
*/
public function getRawUrl()
public function getRawUrl(): string
{
return $this->rawUrl;
}

/**
* @param string $rawUrl
*/
public function setRawUrl($rawUrl)
public function setRawUrl(string $rawUrl)
{
$this->rawUrl = $rawUrl;
}

/**
* @return string
*/
public function getVideoId()
public function getVideoId(): string
{
return $this->videoId;
}

/**
* @param string $videoId
*/
public function setVideoId($videoId)
public function setVideoId(string $videoId)
{
$this->videoId = $videoId;
}

/**
* @return string
*/
public function getPattern()
public function getPattern(): string
{
return $this->pattern;
}

/**
* @param string $pattern
*/
public function setPattern($pattern)
public function setPattern(string $pattern)
{
$this->pattern = $pattern;
}

/**
* @return EmbedRendererInterface
*/
public function getRenderer()
public function getRenderer(): EmbedRendererInterface
{
return $this->renderer;
}

/**
* @param EmbedRendererInterface $renderer
*/
public function setRenderer($renderer)
public function setRenderer(EmbedRendererInterface $renderer)
{
$this->renderer = $renderer;
}

/**
* @param int $width
* @param int $height
* @param bool $forceAutoplay
* @param bool $forceSecure
*
* @return string
* @throws NotEmbeddableException
*/
public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecure = false)
{
if (false == $this->isEmbeddable()) {
throw new NotEmbeddableException();
public function getEmbedCode(
int $width,
int $height,
bool $forceAutoplay = false,
bool $forceSecure = false
): string {
if (false === $this->isEmbeddable()) {
throw new NotEmbeddableException(
sprintf('The service "%s" does not provide embeddable videos', $this->getServiceName())
);
}

return $this->getRenderer()->renderVideoEmbedCode(
Expand All @@ -135,17 +83,25 @@ public function getEmbedCode($width, $height, $forceAutoplay = false, $forceSecu
}

/**
* Switches the protocol scheme between http and https in case you want to force https
*
* @param bool|false $forceSecure
* @return string
* @throws InvalidUrlException
*/
public function getScheme($forceSecure = false)
public function getScheme(bool $forceSecure = false): string
{
if ($forceSecure) {
return 'https';
}

return parse_url($this->rawUrl, PHP_URL_SCHEME);
$parsedUrlSchema = parse_url($this->rawUrl, PHP_URL_SCHEME);

if (false !== $parsedUrlSchema) {
return $parsedUrlSchema;
}

throw new InvalidUrlException(sprintf('The URL %s is not valid', $this->rawUrl));
}

public function isThumbnailSizeAvailable($intendedSize): bool
{
return in_array($intendedSize, $this->getThumbNailSizes());
}
}
18 changes: 3 additions & 15 deletions src/Adapter/CallableServiceAdapterFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
<?php
/**
* Created by PhpStorm.
* User: Ricardo Fiorani
* Date: 29/08/2015
* Time: 14:57.
*/
<?php declare(strict_types=1);

namespace RicardoFiorani\Adapter;

use RicardoFiorani\Adapter\VideoAdapterInterface;
use RicardoFiorani\Renderer\EmbedRendererInterface;

interface CallableServiceAdapterFactoryInterface
{
/**
* @param string $url
* @param string $pattern
* @param EmbedRendererInterface $renderer
*
* @return VideoAdapterInterface
*/
public function __invoke($url, $pattern, EmbedRendererInterface $renderer);
public function __invoke(string $url, string $pattern, EmbedRendererInterface $renderer): VideoAdapterInterface;
}
Loading