Skip to content

Commit

Permalink
fix(#34): Dropped dependency to deprecated fusonic/linq library (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburtscher committed Dec 5, 2023
1 parent d3a41c7 commit 09dca70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"ext-dom": "*",
"symfony/dom-crawler": "^3.0|^4.0|^5.0|^6.0",
"symfony/css-selector": "^3.0|^4.0|^5.0|^6.0",
"fusonic/linq": "^1.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0"
},
Expand Down
34 changes: 10 additions & 24 deletions src/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Fusonic\OpenGraph;

use DOMElement;
use Fusonic\Linq\Linq;
use Fusonic\OpenGraph\Objects\ObjectBase;
use Fusonic\OpenGraph\Objects\Website;
use LogicException;
Expand Down Expand Up @@ -97,32 +95,20 @@ private function extractOpenGraphData(string $content): ObjectBase
{
// Get all meta-tags starting with "og:"
$ogMetaTags = $crawler->filter("meta[{$t}^='og:']");

// Create clean property array
$props = Linq::from($ogMetaTags)
->select(
function (DOMElement $tag) use ($t) {
$name = strtolower(trim($tag->getAttribute($t)));
$value = trim($tag->getAttribute("content"));
return new Property($name, $value);
}
)
->toArray();
$props = [];
foreach ($ogMetaTags as $tag) {
$name = strtolower(trim($tag->getAttribute($t)));
$value = trim($tag->getAttribute("content"));
$props[] = new Property($name, $value);
}

$properties = array_merge($properties, $props);

}

// Create new object of the correct type
$typeProperty = Linq::from($properties)
->firstOrNull(
function (Property $property) {
return $property->key === Property::TYPE;
}
);
switch ($typeProperty !== null ? $typeProperty->value : null) {
default:
$object = new Website();
break;
}
// Create new object
$object = new Website();

// Assign all properties to the object
$object->assignProperties($properties, $this->debug);
Expand Down

0 comments on commit 09dca70

Please sign in to comment.