Update embed service and data class names
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Embed;
|
||||
|
||||
class EmbedData
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $videoUrl,
|
||||
public readonly string $thumbnailUrl,
|
||||
) {}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class EmbedService
|
||||
*
|
||||
* @throws \Exception When the URL does not contain any embedable data
|
||||
*/
|
||||
public function getData(string $url): EmbedData
|
||||
public function getVideo(string $url): EmbedVideo
|
||||
{
|
||||
$url = $this->parseUrl($url);
|
||||
$data = $this->embera->getUrlData($url);
|
||||
@@ -44,7 +44,7 @@ class EmbedService
|
||||
|
||||
$data = $data[$url];
|
||||
|
||||
return new EmbedData(
|
||||
return new EmbedVideo(
|
||||
$this->getIframeSrc($data['html']),
|
||||
\trim($data['thumbnail_url']),
|
||||
);
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Embed;
|
||||
|
||||
class EmbedVideo
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* A URL path to the embedded video element source.
|
||||
*/
|
||||
public readonly string $src,
|
||||
|
||||
/**
|
||||
* A URL path to the embedded video element thumbnail.
|
||||
*/
|
||||
public readonly string $thumbnail,
|
||||
) {}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Tests\Service\Embed;
|
||||
|
||||
use App\Service\Embed\EmbedData;
|
||||
use App\Service\Embed\EmbedVideo;
|
||||
use App\Service\Embed\EmbedService;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
@@ -22,13 +22,13 @@ class EmbedServiceTest extends KernelTestCase
|
||||
*/
|
||||
public function testGetsEmbedData(string $url)
|
||||
{
|
||||
$data = $this->embedService->getData($url);
|
||||
$embed = $this->embedService->getVideo($url);
|
||||
|
||||
$this->assertInstanceOf(EmbedData::class, $data);
|
||||
$this->assertNotEmpty($data->videoUrl);
|
||||
$this->assertStringStartsWith('http', $data->videoUrl);
|
||||
$this->assertNotEmpty($data->thumbnailUrl);
|
||||
$this->assertStringStartsWith('http', $data->thumbnailUrl);
|
||||
$this->assertInstanceOf(EmbedVideo::class, $embed);
|
||||
$this->assertNotEmpty($embed->src);
|
||||
$this->assertStringStartsWith('http', $embed->src);
|
||||
$this->assertNotEmpty($embed->thumbnail);
|
||||
$this->assertStringStartsWith('http', $embed->thumbnail);
|
||||
}
|
||||
|
||||
public function provideUrls(): array
|
||||
@@ -56,7 +56,7 @@ class EmbedServiceTest extends KernelTestCase
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$this->embedService->getData($string);
|
||||
$this->embedService->getVideo($string);
|
||||
}
|
||||
|
||||
public function provideNotUrls()
|
||||
|
||||
Reference in New Issue
Block a user