mirror of
https://github.com/wallabag/wallabag.git
synced 2025-02-02 12:02:23 +00:00
Remove FileCookieJar
This commit is contained in:
parent
6e20dc985b
commit
0081d6afb7
2 changed files with 1 additions and 70 deletions
|
@ -22,7 +22,6 @@ services:
|
||||||
$fetchingErrorMessage: '%wallabag.fetching_error_message%'
|
$fetchingErrorMessage: '%wallabag.fetching_error_message%'
|
||||||
$languages: '%wallabag.languages%'
|
$languages: '%wallabag.languages%'
|
||||||
$lifeTime: '%wallabag.cache_lifetime%'
|
$lifeTime: '%wallabag.cache_lifetime%'
|
||||||
$cookieFile: "%kernel.cache_dir%/cookiejar.json"
|
|
||||||
$logoPath: 'web/img/appicon/apple-touch-icon-152.png'
|
$logoPath: 'web/img/appicon/apple-touch-icon-152.png'
|
||||||
$registrationEnabled: '%fosuser_registration%'
|
$registrationEnabled: '%fosuser_registration%'
|
||||||
$restrictedAccess: '@=service(''craue_config'').get(''restricted_access'')'
|
$restrictedAccess: '@=service(''craue_config'').get(''restricted_access'')'
|
||||||
|
@ -213,8 +212,7 @@ services:
|
||||||
Wallabag\SiteConfig\SiteConfigBuilder:
|
Wallabag\SiteConfig\SiteConfigBuilder:
|
||||||
alias: Wallabag\SiteConfig\GrabySiteConfigBuilder
|
alias: Wallabag\SiteConfig\GrabySiteConfigBuilder
|
||||||
|
|
||||||
GuzzleHttp\Cookie\CookieJar:
|
GuzzleHttp\Cookie\CookieJar: ~
|
||||||
alias: 'Wallabag\Helper\FileCookieJar'
|
|
||||||
|
|
||||||
Wallabag\Helper\HttpClientFactory:
|
Wallabag\Helper\HttpClientFactory:
|
||||||
calls:
|
calls:
|
||||||
|
|
|
@ -1,67 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Wallabag\Helper;
|
|
||||||
|
|
||||||
use GuzzleHttp\Cookie\FileCookieJar as BaseFileCookieJar;
|
|
||||||
use GuzzleHttp\Cookie\SetCookie;
|
|
||||||
use GuzzleHttp\Utils;
|
|
||||||
use Psr\Log\LoggerInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Overidden Cookie behavior to:
|
|
||||||
* - ignore error when the cookie file is malformatted (resulting in clearing it).
|
|
||||||
*/
|
|
||||||
class FileCookieJar extends BaseFileCookieJar
|
|
||||||
{
|
|
||||||
private $logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param LoggerInterface $logger Only used to log info when something goes wrong
|
|
||||||
* @param string $cookieFile File to store the cookie data
|
|
||||||
*/
|
|
||||||
public function __construct(LoggerInterface $logger, $cookieFile)
|
|
||||||
{
|
|
||||||
parent::__construct($cookieFile);
|
|
||||||
|
|
||||||
$this->logger = $logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load cookies from a JSON formatted file.
|
|
||||||
*
|
|
||||||
* Old cookies are kept unless overwritten by newly loaded ones.
|
|
||||||
*
|
|
||||||
* @param string $filename cookie file to load
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException if the file cannot be loaded
|
|
||||||
*/
|
|
||||||
public function load($filename)
|
|
||||||
{
|
|
||||||
$json = file_get_contents($filename);
|
|
||||||
if (false === $json) {
|
|
||||||
// @codeCoverageIgnoreStart
|
|
||||||
throw new \RuntimeException("Unable to load file {$filename}");
|
|
||||||
// @codeCoverageIgnoreEnd
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$data = Utils::jsonDecode($json, true);
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
$this->logger->error('JSON inside the cookie is broken', [
|
|
||||||
'json' => $json,
|
|
||||||
'error_msg' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
// cookie file is invalid, just ignore the exception and it'll reset the whole cookie file
|
|
||||||
$data = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (\is_array($data)) {
|
|
||||||
foreach (Utils::jsonDecode($json, true) as $cookie) {
|
|
||||||
$this->setCookie(new SetCookie($cookie));
|
|
||||||
}
|
|
||||||
} elseif (\strlen($data)) {
|
|
||||||
throw new \RuntimeException("Invalid cookie file: {$filename}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue