From edee2f248b53fd6585e652c60d152b605e14d5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean=20Jar=20Pereira=20de=20Ara=C3=BAjo?= Date: Tue, 16 Aug 2016 22:06:52 -0300 Subject: [PATCH] first commit --- .gitignore | 4 ++++ composer.json | 22 ++++++++++++++++++ src/Providers/Vimeo.php | 36 ++++++++++++++++++++++++++++++ src/Providers/Youtube.php | 47 +++++++++++++++++++++++++++++++++++++++ src/VideoEmbed.php | 39 ++++++++++++++++++++++++++++++++ tests/Equals.php | 29 ++++++++++++++++++++++++ 6 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 src/Providers/Vimeo.php create mode 100644 src/Providers/Youtube.php create mode 100644 src/VideoEmbed.php create mode 100644 tests/Equals.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..709d33b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +vendor/ +composer.lock +composer.phar +.idea/ \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..1aa0a42 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "jeanjar/video_embed", + "description": "A simple video embed for YouTube and Vimeo", + "license": "MIT", + "authors": [ + { + "name": "Jean Jar Pereira de Araújo", + "email": "jeanjpa@gmail.com" + } + ], + "require": { + "php" : ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "5.5.*" + }, + "autoload": { + "psr-4": { + "VideoEmbed\\": "src/" + } + } +} diff --git a/src/Providers/Vimeo.php b/src/Providers/Vimeo.php new file mode 100644 index 0000000..105d6d5 --- /dev/null +++ b/src/Providers/Vimeo.php @@ -0,0 +1,36 @@ + $value) + { + if (is_int($param)) + { + $realParams .= $value . ' '; + } + else + { + $realParams .= $param . '="' . $value . '" '; + } + } + } + return ''; + } +} \ No newline at end of file diff --git a/src/Providers/Youtube.php b/src/Providers/Youtube.php new file mode 100644 index 0000000..b26ed86 --- /dev/null +++ b/src/Providers/Youtube.php @@ -0,0 +1,47 @@ +'; + } + +} \ No newline at end of file diff --git a/src/VideoEmbed.php b/src/VideoEmbed.php new file mode 100644 index 0000000..1440e3b --- /dev/null +++ b/src/VideoEmbed.php @@ -0,0 +1,39 @@ + Youtube::class, + 'youtu' => Youtube::class, + 'vimeo' => Vimeo::class, + ]; + + public static function render($url, $params = []) + { + foreach (self::$list as $host => $class) + { + if (preg_match('/' . $host . '/i', $url)) + { + return call_user_func_array([$class, 'render'], [$url, $params]); + } + } + } +} \ No newline at end of file diff --git a/tests/Equals.php b/tests/Equals.php new file mode 100644 index 0000000..047103b --- /dev/null +++ b/tests/Equals.php @@ -0,0 +1,29 @@ + true]); + $this->assertEquals('bLLxXZoqq_Y', $id); + + $id = VideoEmbed::render('https://vimeo.com/18758609', ['return_id' => true]); + $this->assertEquals('18758609', $id); + } + + public function testeEmbedEquals() + { + $video = VideoEmbed::render('https://www.youtube.com/watch?v=bLLxXZoqq_Y', ['width' => 300, 'height' => 250]); + $this->assertEquals('', $video); + + $video = VideoEmbed::render('https://vimeo.com/18758609'); + $this->assertEquals('', $video); + } +} \ No newline at end of file