mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-25 10:31:05 +00:00
Use DomCrawler in AuthenticatorProvider
This commit is contained in:
parent
4e7b5c66ad
commit
9f2fb0c6fa
1 changed files with 7 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
||||||
namespace Wallabag\ExpressionLanguage;
|
namespace Wallabag\ExpressionLanguage;
|
||||||
|
|
||||||
use GuzzleHttp\ClientInterface;
|
use GuzzleHttp\ClientInterface;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||||
|
|
||||||
|
@ -69,27 +70,19 @@ class AuthenticatorProvider implements ExpressionFunctionProviderInterface
|
||||||
throw new \Exception('Not supported');
|
throw new \Exception('Not supported');
|
||||||
},
|
},
|
||||||
function (array $arguments, $xpathQuery, $html) {
|
function (array $arguments, $xpathQuery, $html) {
|
||||||
$useInternalErrors = libxml_use_internal_errors(true);
|
try {
|
||||||
|
$crawler = new Crawler((string) $html);
|
||||||
|
|
||||||
$doc = new \DOMDocument();
|
$crawler = $crawler->filterXPath($xpathQuery);
|
||||||
$doc->loadHTML((string) $html, \LIBXML_NOCDATA | \LIBXML_NOWARNING | \LIBXML_NOERROR);
|
} catch (\Throwable $e) {
|
||||||
|
|
||||||
$xpath = new \DOMXPath($doc);
|
|
||||||
$domNodeList = $xpath->query($xpathQuery);
|
|
||||||
|
|
||||||
if (0 === $domNodeList->length) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
$domNode = $domNodeList->item(0);
|
if (0 === $crawler->count()) {
|
||||||
|
|
||||||
libxml_use_internal_errors($useInternalErrors);
|
|
||||||
|
|
||||||
if (null === $domNode || null === $domNode->attributes) {
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
return $domNode->attributes->getNamedItem('value')->nodeValue;
|
return (string) $crawler->first()->attr('value');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue