最初にやったニジエに抜けがあった

This commit is contained in:
hina 2019-02-17 03:18:59 +09:00
parent 24dee801ad
commit 51f097fdf0
No known key found for this signature in database
GPG Key ID: 6136D5E22A0EE24B

View File

@ -6,12 +6,19 @@ use GuzzleHttp\Client;
class NijieResolver implements Resolver class NijieResolver implements Resolver
{ {
/** @var Client */ /**
* @var Client
*/
protected $client; protected $client;
/**
* @var OGPResolver
*/
private $ogpResolver;
public function __construct(Client $client) public function __construct(Client $client, OGPResolver $ogpResolver)
{ {
$this->client = $client; $this->client = $client;
$this->ogpResolver = $ogpResolver;
} }
public function resolve(string $url): Metadata public function resolve(string $url): Metadata
@ -26,8 +33,7 @@ class NijieResolver implements Resolver
$client = $this->client; $client = $this->client;
$res = $client->get($url); $res = $client->get($url);
if ($res->getStatusCode() === 200) { if ($res->getStatusCode() === 200) {
$ogpResolver = new OGPResolver(); $metadata = $this->ogpResolver->parse($res->getBody());
$metadata = $ogpResolver->parse($res->getBody());
$dom = new \DOMDocument(); $dom = new \DOMDocument();
@$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8')); @$dom->loadHTML(mb_convert_encoding($res->getBody(), 'HTML-ENTITIES', 'UTF-8'));