mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-11 17:51:02 +00:00
Move source files directly under src/ directory
This commit is contained in:
parent
804261bc26
commit
a37b385c23
190 changed files with 19 additions and 21 deletions
96
src/ExpressionLanguage/AuthenticatorProvider.php
Normal file
96
src/ExpressionLanguage/AuthenticatorProvider.php
Normal file
|
@ -0,0 +1,96 @@
|
|||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\ExpressionLanguage;
|
||||
|
||||
use GuzzleHttp\ClientInterface;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
|
||||
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
|
||||
|
||||
class AuthenticatorProvider implements ExpressionFunctionProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var ClientInterface
|
||||
*/
|
||||
private $guzzle;
|
||||
|
||||
public function __construct(ClientInterface $guzzle)
|
||||
{
|
||||
$this->guzzle = $guzzle;
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
$result = [
|
||||
$this->getRequestHtmlFunction(),
|
||||
$this->getXpathFunction(),
|
||||
$this->getPregMatchFunction(),
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getRequestHtmlFunction()
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'request_html',
|
||||
function () {
|
||||
throw new \Exception('Not supported');
|
||||
},
|
||||
function (array $arguments, $uri, array $options = []) {
|
||||
return $this->guzzle->get($uri, $options)->getBody();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function getPregMatchFunction()
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'preg_match',
|
||||
function () {
|
||||
throw new \Exception('Not supported');
|
||||
},
|
||||
function (array $arguments, $pattern, $html) {
|
||||
preg_match($pattern, $html, $matches);
|
||||
|
||||
if (2 !== \count($matches)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function getXpathFunction()
|
||||
{
|
||||
return new ExpressionFunction(
|
||||
'xpath',
|
||||
function () {
|
||||
throw new \Exception('Not supported');
|
||||
},
|
||||
function (array $arguments, $xpathQuery, $html) {
|
||||
$useInternalErrors = libxml_use_internal_errors(true);
|
||||
|
||||
$doc = new \DOMDocument();
|
||||
$doc->loadHTML((string) $html, \LIBXML_NOCDATA | \LIBXML_NOWARNING | \LIBXML_NOERROR);
|
||||
|
||||
$xpath = new \DOMXPath($doc);
|
||||
$domNodeList = $xpath->query($xpathQuery);
|
||||
|
||||
if (0 === $domNodeList->length) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$domNode = $domNodeList->item(0);
|
||||
|
||||
libxml_use_internal_errors($useInternalErrors);
|
||||
|
||||
if (null === $domNode || null === $domNode->attributes) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $domNode->attributes->getNamedItem('value')->nodeValue;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue