diff --git a/src/Embed/Embed.php b/src/Embed/Embed.php
index 0396ac8..d4dd125 100644
--- a/src/Embed/Embed.php
+++ b/src/Embed/Embed.php
@@ -2,39 +2,42 @@
namespace Hyvor\Unfold\Embed;
-use Hyvor\Unfold\Embed\Exception\ParserException;
-use Hyvor\Unfold\Embed\Exception\UnableToResolveEmbedException;
-use Hyvor\Unfold\Embed\Platforms\Reddit;
-use Hyvor\Unfold\Embed\Platforms\Tiktok;
-use Hyvor\Unfold\Embed\Platforms\Twitter;
-use Hyvor\Unfold\Embed\Platforms\Youtube;
-use Hyvor\Unfold\UnfoldConfigObject;
+//use Hyvor\Unfold\Embed\Platforms\GithubGist;
+//use Hyvor\Unfold\Embed\Platforms\Reddit;
+//use Hyvor\Unfold\Embed\Platforms\Tiktok;
+//use Hyvor\Unfold\Embed\Platforms\Twitter;
+//use Hyvor\Unfold\Embed\Platforms\Youtube;
+use Hyvor\Unfold\Exception\EmbedUnableToResolveException;
+use Hyvor\Unfold\Exception\EmbedParserException;
+use Hyvor\Unfold\Exception\UnfoldException;
+use Hyvor\Unfold\UnfoldCallContext;
+use Hyvor\Unfold\UnfoldConfig;
use Hyvor\Unfold\Unfolded\Unfolded;
-use Hyvor\Unfold\UnfoldException;
use Hyvor\Unfold\UnfoldMethod;
-use Hyvor\Unfold\UnfoldCallContext;
class Embed
{
+
/**
- * @var EmbedParserAbstract[]
+ * @return string[]
*/
- public const PARSERS = [
- Youtube::class,
- Reddit::class,
- Tiktok::class,
- Twitter::class,
- Reddit::class,
- ];
+ public static function getParsers(): array
+ {
+ $namespace = __NAMESPACE__ . '\\Platforms\\';
+ return array_map(
+ fn($file) => $namespace . pathinfo($file, PATHINFO_FILENAME),
+ glob(__DIR__ . '/Platforms/*.php')
+ );
+ }
/**
- * @throws ParserException
+ * @throws EmbedParserException
*/
public static function parse(
string $url,
- ?UnfoldConfigObject $config = null,
+ ?UnfoldConfig $config = null,
): ?EmbedResponseObject {
- foreach (self::PARSERS as $parserClass) {
+ foreach (self::getParsers() as $parserClass) {
$parser = new $parserClass($url, $config);
if ($parser->match()) {
return $parser->parse();
@@ -55,7 +58,7 @@ public static function getUnfoldedObject(
if ($oembed === null) {
if ($context->method === UnfoldMethod::EMBED) {
- throw new UnableToResolveEmbedException();
+ throw new EmbedUnableToResolveException();
} else {
return null;
}
diff --git a/src/Embed/EmbedParserAbstract.php b/src/Embed/EmbedParserAbstract.php
index b1a65b8..994b86e 100644
--- a/src/Embed/EmbedParserAbstract.php
+++ b/src/Embed/EmbedParserAbstract.php
@@ -4,8 +4,9 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Uri;
-use Hyvor\Unfold\Embed\Exception\ParserException;
-use Hyvor\Unfold\UnfoldConfigObject;
+use Hyvor\Unfold\Exception\EmbedParserException;
+use Hyvor\Unfold\Exception\UnfoldException;
+use Hyvor\Unfold\UnfoldConfig;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;
@@ -15,13 +16,13 @@
*/
abstract class EmbedParserAbstract
{
- protected UnfoldConfigObject $config;
+ protected UnfoldConfig $config;
public function __construct(
protected string $url,
- ?UnfoldConfigObject $config = null,
+ ?UnfoldConfig $config = null,
) {
- $this->config = $config ?? new UnfoldConfigObject();
+ $this->config = $config ?? new UnfoldConfig();
}
@@ -65,14 +66,25 @@ public function match(): bool
return false;
}
- public function parse(): ?EmbedResponseObject
+ /**
+ * @throws UnfoldException
+ */
+ public function parse(): EmbedResponseObject
{
- $oEmbedUrl = $this->oEmbedUrl();
-
- if (!$oEmbedUrl) {
- // TODO: Check config option for fallback
- return null;
+ if ($this instanceof EmbedParserOEmbedInterface) {
+ return $this->parseOEmbed();
+ } elseif ($this instanceof EmbedParserCustomInterface) {
+ return $this->parseCustom();
+ } else {
+ throw new \Exception(
+ 'EmbedParserAbstract should be implemented with either EmbedParserOEmbedInterface or EmbedParserCustomInterface'
+ ); // @codeCoverageIgnore
}
+ }
+
+ public function parseOEmbed(): ?EmbedResponseObject
+ {
+ $oEmbedUrl = $this->oEmbedUrl();
$uri = Uri::withQueryValues(
new Uri($oEmbedUrl),
@@ -97,7 +109,7 @@ public function parse(): ?EmbedResponseObject
try {
$response = $client->sendRequest($request);
} catch (ClientExceptionInterface $e) {
- throw new ParserException(
+ throw new EmbedParserException(
"Failed to fetch oEmbed data from the endpoint",
previous: $e
);
@@ -107,7 +119,7 @@ public function parse(): ?EmbedResponseObject
$content = $response->getBody()->getContents();
if ($status !== 200) {
- throw new ParserException(
+ throw new EmbedParserException(
"Failed to fetch oEmbed data from the endpoint. Status: $status. Response: $content"
);
}
@@ -115,10 +127,20 @@ public function parse(): ?EmbedResponseObject
$parsed = json_decode($content, true);
if (!is_array($parsed)) {
- throw new ParserException("Failed to parse JSON response from oEmbed endpoint");
+ throw new EmbedParserException("Failed to parse JSON response from oEmbed endpoint");
}
return EmbedResponseObject::fromArray($parsed);
}
+ private function parseCustom()
+ {
+ $html = $this->getEmbedHtml();
+
+ return EmbedResponseObject::fromArray([
+ 'type' => 'embed',
+ 'html' => $html
+ ]);
+ }
+
}
diff --git a/src/Embed/EmbedParserOEmbedInterface.php b/src/Embed/EmbedParserOEmbedInterface.php
index 874f7fb..e67c4d0 100644
--- a/src/Embed/EmbedParserOEmbedInterface.php
+++ b/src/Embed/EmbedParserOEmbedInterface.php
@@ -4,6 +4,6 @@
interface EmbedParserOEmbedInterface
{
- public function oEmbedUrl(): ?string;
+ public function oEmbedUrl(): string;
}
diff --git a/src/Embed/Exception/ParserException.php b/src/Embed/Exception/ParserException.php
deleted file mode 100644
index 4e49b12..0000000
--- a/src/Embed/Exception/ParserException.php
+++ /dev/null
@@ -1,9 +0,0 @@
-config->facebookAccessToken;
if (!$facebookAccessToken) {
- throw new ParserException('Facebook Access Token is required for Instagram embeds');
+ throw new EmbedParserException('Facebook Access Token is required for Instagram embeds');
}
$uri = Uri::withQueryValue($uri, 'access_token', $facebookAccessToken);
@@ -57,7 +57,7 @@ public function regex()
];
}
- public function oEmbedUrl(): ?string
+ public function oEmbedUrl(): string
{
return 'https://graph.facebook.com/v16.0/instagram_oembed';
}
diff --git a/src/Embed/Platforms/Reddit.php b/src/Embed/Platforms/Reddit.php
index e681e68..c1bb944 100644
--- a/src/Embed/Platforms/Reddit.php
+++ b/src/Embed/Platforms/Reddit.php
@@ -19,7 +19,7 @@ public function regex()
];
}
- public function oEmbedUrl(): ?string
+ public function oEmbedUrl(): string
{
return 'https://www.reddit.com/oembed';
}
diff --git a/src/Embed/Platforms/Tiktok.php b/src/Embed/Platforms/Tiktok.php
index 80ead39..5511548 100644
--- a/src/Embed/Platforms/Tiktok.php
+++ b/src/Embed/Platforms/Tiktok.php
@@ -3,8 +3,9 @@
namespace Hyvor\Unfold\Embed\Platforms;
use Hyvor\Unfold\Embed\EmbedParserAbstract;
+use Hyvor\Unfold\Embed\EmbedParserOEmbedInterface;
-class Tiktok extends EmbedParserAbstract
+class Tiktok extends EmbedParserAbstract implements EmbedParserOEmbedInterface
{
public function regex()
{
@@ -14,7 +15,7 @@ public function regex()
];
}
- public function oEmbedUrl(): ?string
+ public function oEmbedUrl(): string
{
return 'https://www.tiktok.com/oembed';
}
diff --git a/src/Embed/Platforms/Twitter.php b/src/Embed/Platforms/Twitter.php
index e92ce2f..08048e8 100644
--- a/src/Embed/Platforms/Twitter.php
+++ b/src/Embed/Platforms/Twitter.php
@@ -19,7 +19,7 @@ public function regex()
];
}
- public function oEmbedUrl(): ?string
+ public function oEmbedUrl(): string
{
return 'https://publish.twitter.com/oembed';
}
diff --git a/src/Embed/Platforms/Youtube.php b/src/Embed/Platforms/Youtube.php
index 2236510..b65af59 100644
--- a/src/Embed/Platforms/Youtube.php
+++ b/src/Embed/Platforms/Youtube.php
@@ -23,7 +23,7 @@ public function regex()
];
}
- public function oEmbedUrl(): ?string
+ public function oEmbedUrl(): string
{
return 'https://www.youtube.com/oembed';
}
diff --git a/src/Exception/EmbedParserException.php b/src/Exception/EmbedParserException.php
new file mode 100644
index 0000000..5098a97
--- /dev/null
+++ b/src/Exception/EmbedParserException.php
@@ -0,0 +1,7 @@
+config->httpClient->sendRequest($request);
} catch (ClientExceptionInterface $e) {
- //
+ throw new LinkScrapeException($e->getMessage());
}
$status = $response->getStatusCode();
- $content = $response->getBody()->getContents();
- // TODO:
- return $response->getBody();
+ if ($status < 200 || $status >= 300) {
+ throw new LinkScrapeException("Unable to scrape link. HTTP status code: $status");
+ }
+
+ return $response->getBody()->getContents();
}
diff --git a/src/Link/Metadata/MetadataKeyType.php b/src/Link/Metadata/MetadataKeyType.php
index 2341301..7016877 100644
--- a/src/Link/Metadata/MetadataKeyType.php
+++ b/src/Link/Metadata/MetadataKeyType.php
@@ -2,6 +2,9 @@
namespace Hyvor\Unfold\Link\Metadata;
+use Hyvor\Unfold\Unfolded\UnfoldedAuthor;
+use Hyvor\Unfold\Unfolded\UnfoldedTag;
+
enum MetadataKeyType
{
case TITLE;
@@ -48,4 +51,40 @@ enum MetadataKeyType
case TWITTER_DESCRIPTION;
case TWITTER_TITLE;
case TWITTER_IMAGE;
+
+ /**
+ * Gets the value of the metadata from a given content string
+ * ex: article:published_time is converted to DateTimeInterface
+ */
+ public function getValue(string $content)
+ {
+ if (
+ $this === MetadataKeyType::OG_ARTICLE_PUBLISHED_TIME ||
+ $this === MetadataKeyType::OG_ARTICLE_MODIFIED_TIME
+ ) {
+ return MetadataParser::getDateTimeFromString($content);
+ }
+
+ if (
+ $this === MetadataKeyType::OG_ARTICLE_AUTHOR ||
+ $this === MetadataKeyType::TWITTER_CREATOR
+ ) {
+ return $this->getAuthorFromString($content);
+ }
+
+ if ($this === MetadataKeyType::OG_ARTICLE_TAG) {
+ return new UnfoldedTag($content);
+ }
+
+ return $content;
+ }
+
+ private function getAuthorFromString(string $value): UnfoldedAuthor
+ {
+ if (str_contains($value, 'http://') || str_contains($value, 'https://')) {
+ return new UnfoldedAuthor(null, $value);
+ } else {
+ return new UnfoldedAuthor($value, null);
+ }
+ }
}
diff --git a/src/Link/Metadata/MetadataParser.php b/src/Link/Metadata/MetadataParser.php
index e94c893..96a847d 100644
--- a/src/Link/Metadata/MetadataParser.php
+++ b/src/Link/Metadata/MetadataParser.php
@@ -90,28 +90,7 @@ public function addMetadataFromMetaTags(array $keys): void
return;
}
- if (
- $keyType === MetadataKeyType::OG_ARTICLE_PUBLISHED_TIME ||
- $keyType === MetadataKeyType::OG_ARTICLE_MODIFIED_TIME
- ) {
- $content = self::getDateTimeFromString($content);
- }
-
- if (
- $keyType === MetadataKeyType::OG_ARTICLE_AUTHOR ||
- $keyType === MetadataKeyType::TWITTER_CREATOR
- ) {
- if (str_contains($content, 'http://') || str_contains($content, 'https://')) {
- $content = new UnfoldedAuthor(null, $content);
- } else {
- $content = new UnfoldedAuthor($content, null);
- }
- }
-
- if ($keyType === MetadataKeyType::OG_ARTICLE_TAG) {
- $content = new UnfoldedTag($content);
- }
-
+ $content = $keyType->getValue($content);
$metadata[] = new MetadataObject($keyType, $content);
});
diff --git a/src/Link/Metadata/MetadataPriority.php b/src/Link/Metadata/MetadataPriority.php
index 853b702..9edbeca 100644
--- a/src/Link/Metadata/MetadataPriority.php
+++ b/src/Link/Metadata/MetadataPriority.php
@@ -11,7 +11,6 @@
*/
class MetadataPriority
{
-
/**
* @param MetadataObject[] $metadata
*/
@@ -57,7 +56,7 @@ private function prioritizedAll(array $keys)
* 'OG_TITLE' => [MetadataObject],
* ]
*/
- $keysNames = array_map(fn($key) => $key->name, $keys);
+ $keysNames = array_map(fn ($key) => $key->name, $keys);
uksort($keyedMetadata, function ($a, $b) use ($keysNames) {
return array_search($a, $keysNames) - array_search($b, $keysNames);
});
@@ -65,7 +64,7 @@ private function prioritizedAll(array $keys)
// index by 0,1,2
$keyedMetadata = array_values($keyedMetadata);
// return the values
- return array_map(fn($metadata) => $metadata->value, $keyedMetadata[0] ?? []);
+ return array_map(fn ($metadata) => $metadata->value, $keyedMetadata[0] ?? []);
}
/**
@@ -129,18 +128,31 @@ public function siteName(): ?string
}
- public function siteUrl(): ?string
+ public function siteUrl(string $url): ?string
{
- return $this->prioritized([
+ $currentUrl = $this->prioritized([
+ MetadataKeyType::CANONICAL_URL,
MetadataKeyType::OG_URL
]);
+ $currentUrl = $currentUrl ?? $url;
+
+ // get origin from url
+ $parsedUrl = parse_url($currentUrl);
+ if ($parsedUrl !== false) {
+ $scheme = $parsedUrl['scheme'] ?? 'http';
+ $host = $parsedUrl['host'] ?? '';
+ return $host ? $scheme . '://' . $host : null;
+ }
+
+ return null;
}
public function canonicalUrl(): ?string
{
return $this->prioritized([
- MetadataKeyType::CANONICAL_URL
+ MetadataKeyType::CANONICAL_URL,
+ MetadataKeyType::OG_URL
]);
}
@@ -190,4 +202,4 @@ public function locale(): ?string
]);
}
-}
\ No newline at end of file
+}
diff --git a/src/Link/Metadata/Parsers/HtmlLangParser.php b/src/Link/Metadata/Parsers/HtmlLangParser.php
index b9301f6..5d11a0d 100644
--- a/src/Link/Metadata/Parsers/HtmlLangParser.php
+++ b/src/Link/Metadata/Parsers/HtmlLangParser.php
@@ -12,7 +12,7 @@ public function add(): void
$htmlNode = $this->parser->crawler->filterXPath('//html');
if ($htmlNode->count() === 0) {
- return;
+ return; // @codeCoverageIgnore
}
$lang = $htmlNode->attr('lang');
diff --git a/src/Link/Metadata/Parsers/JsonLdParser.php b/src/Link/Metadata/Parsers/JsonLdParser.php
index 757767c..0dc9c4a 100644
--- a/src/Link/Metadata/Parsers/JsonLdParser.php
+++ b/src/Link/Metadata/Parsers/JsonLdParser.php
@@ -20,17 +20,15 @@ public function add(): void
if (isset($json['datePublished'])) {
$date = MetadataParser::getDateTimeFromString($json['datePublished']);
- if (!$date) {
- return;
+ if ($date) {
+ $this->parser->addMetadata(new MetadataObject(MetadataKeyType::RICH_SCHEMA_PUBLISHED_TIME, $date));
}
- $this->parser->addMetadata(new MetadataObject(MetadataKeyType::RICH_SCHEMA_PUBLISHED_TIME, $date));
}
if (isset($json['dateModified'])) {
$date = MetadataParser::getDateTimeFromString($json['dateModified']);
- if (!$date) {
- return;
+ if ($date) {
+ $this->parser->addMetadata(new MetadataObject(MetadataKeyType::RICH_SCHEMA_MODIFIED_TIME, $date));
}
- $this->parser->addMetadata(new MetadataObject(MetadataKeyType::RICH_SCHEMA_MODIFIED_TIME, $date));
}
if (isset($json['author'])) {
foreach ($json['author'] as $author) {
diff --git a/src/Unfold.php b/src/Unfold.php
index 0029d7c..7e6efda 100644
--- a/src/Unfold.php
+++ b/src/Unfold.php
@@ -3,6 +3,7 @@
namespace Hyvor\Unfold;
use Hyvor\Unfold\Embed\Embed;
+use Hyvor\Unfold\Exception\UnfoldException;
use Hyvor\Unfold\Link\Link;
use Hyvor\Unfold\Unfolded\Unfolded;
@@ -14,9 +15,9 @@ class Unfold
public static function unfold(
string $url,
UnfoldMethod $method = UnfoldMethod::LINK,
- UnfoldConfigObject $config = null,
+ UnfoldConfig $config = null,
): Unfolded {
- $config ??= new UnfoldConfigObject();
+ $config ??= new UnfoldConfig();
$context = new UnfoldCallContext(
$method,
$config,
diff --git a/src/UnfoldCallContext.php b/src/UnfoldCallContext.php
index dcda22b..88ac4d0 100644
--- a/src/UnfoldCallContext.php
+++ b/src/UnfoldCallContext.php
@@ -8,7 +8,7 @@ class UnfoldCallContext
public function __construct(
public UnfoldMethod $method,
- public UnfoldConfigObject $config,
+ public UnfoldConfig $config,
) {
$this->startTime = microtime(true);
}
diff --git a/src/UnfoldConfigObject.php b/src/UnfoldConfig.php
similarity index 99%
rename from src/UnfoldConfigObject.php
rename to src/UnfoldConfig.php
index 144a43c..0b92ad6 100644
--- a/src/UnfoldConfigObject.php
+++ b/src/UnfoldConfig.php
@@ -7,7 +7,7 @@
use Http\Discovery\Psr18ClientDiscovery;
use Psr\Http\Client\ClientInterface;
-class UnfoldConfigObject
+class UnfoldConfig
{
/**
* A PSR-18 HTTP Client for sending oembed and other requests
@@ -81,7 +81,8 @@ public function __construct(
public ?string $facebookAccessToken = null,
// CACHE
- ) {
+ )
+ {
$this->setHttpClient($httpClient);
}
diff --git a/src/Unfolded/Unfolded.php b/src/Unfolded/Unfolded.php
index 1e7f263..36ff3fd 100644
--- a/src/Unfolded/Unfolded.php
+++ b/src/Unfolded/Unfolded.php
@@ -39,190 +39,6 @@ public function __construct(
$this->version = '1.0';
}
- /**
- * @param MetadataObject[] $metadata
- */
- public static function title(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::TITLE,
- MetadataKeyType::OG_TITLE,
- MetadataKeyType::TWITTER_TITLE
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function description(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::DESCRIPTION,
- MetadataKeyType::OG_DESCRIPTION,
- MetadataKeyType::TWITTER_DESCRIPTION
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- * @return UnfoldedAuthor[]
- */
- public static function authors(array $metadata): array
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::RICH_SCHEMA_AUTHOR,
- MetadataKeyType::OG_ARTICLE_AUTHOR,
- MetadataKeyType::TWITTER_CREATOR
- ], true);
- }
-
- /**
- * @param MetadataObject[] $metadata
- * @return UnfoldedTag[]
- */
- public static function tags(array $metadata): array
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::OG_ARTICLE_TAG
- ], true);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function siteName(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::OG_SITE_NAME,
- MetadataKeyType::TWITTER_SITE
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function siteUrl(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::OG_URL
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function canonicalUrl(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::CANONICAL_URL
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function publishedTime(array $metadata): ?DateTimeInterface
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::RICH_SCHEMA_PUBLISHED_TIME,
- MetadataKeyType::OG_ARTICLE_PUBLISHED_TIME
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function modifiedTime(array $metadata): ?DateTimeInterface
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::RICH_SCHEMA_MODIFIED_TIME,
- MetadataKeyType::OG_ARTICLE_MODIFIED_TIME
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function thumbnailUrl(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::OG_IMAGE,
- MetadataKeyType::OG_IMAGE_URL,
- MetadataKeyType::OG_IMAGE_SECURE_URL,
- MetadataKeyType::TWITTER_IMAGE
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function iconUrl(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::FAVICON_URL
- ]);
- }
-
- /**
- * @param MetadataObject[] $metadata
- */
- public static function locale(array $metadata): ?string
- {
- return self::getMetadataFromKeys($metadata, [
- MetadataKeyType::LOCALE,
- MetadataKeyType::OG_LOCALE
- ]);
- }
-
-
- // Helpers
-
- /**
- * @param MetadataObject[] $metadata
- * @param MetadataKeyType[] $keys
- * @return string|DateTimeInterface|UnfoldedAuthor[]|UnfoldedTag[]|null
- */
- public static function getMetadataFromKeys(
- array $metadata,
- array $keys,
- bool $isMultiple = false
- ): string|DateTimeInterface|array|null {
- $value = [];
- /**
- * keyIndex is used track the most priority key found in the metadata
- */
- $keyIndex = count($keys) + 1;
-
- foreach ($metadata as $meta) {
- if (in_array($meta->key, $keys)) {
- $isNewPriority = $keyIndex > array_search($meta->key, $keys); // new key with higher priority found
- if (count($value) === 0) { // if value array is empty add the value
- $value[] = $meta->value;
- $keyIndex = array_search($meta->key, $keys); // set the new key index
- } elseif ($isNewPriority) { // if a new key with higher priority found add the value to an empty value array
- $value = [];
- $value[] = $meta->value;
- $keyIndex = array_search($meta->key, $keys); // set the new key index
- } elseif ($isMultiple && ($keyIndex === array_search(
- $meta->key,
- $keys
- ))) { // if multiple values are allowed and same priority key found
- $value[] = $meta->value;
- }
- }
- if (!$isMultiple && $keyIndex === 0) {
- break;
- }
- }
- return $isMultiple ?
- $value : // return the array of values
- (
- count($value) !== 0 ?
- $value[0] : // return the first value
- null // return null if no value found
- );
- }
-
/**
* @param MetadataObject[] $metadata
*/
@@ -242,7 +58,7 @@ public static function fromMetadata(
$metadataPriority->authors(),
$metadataPriority->tags(),
$metadataPriority->siteName(),
- $metadataPriority->siteUrl(),
+ $metadataPriority->siteUrl($url),
$metadataPriority->canonicalUrl(),
$metadataPriority->publishedTime(),
$metadataPriority->modifiedTime(),
diff --git a/tests/Feature/UnfoldEmbedTest.php b/tests/Feature/UnfoldEmbedTest.php
new file mode 100644
index 0000000..06bc3e4
--- /dev/null
+++ b/tests/Feature/UnfoldEmbedTest.php
@@ -0,0 +1,64 @@
+ '1.0',
+ 'type' => 'video',
+ 'provider_name' => 'YouTube',
+ 'provider_url' => 'https://youtube.com/',
+ 'width' => 425,
+ 'height' => 344,
+ 'title' => 'Amazing Nintendo Facts',
+ 'author_name' => 'ZackScott',
+ 'author_url' => 'https://www.youtube.com/user/ZackScott',
+ 'html' => '