81 lines
1.9 KiB
PHP
81 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Shikiryu\LBCReposter;
|
|
|
|
use Goutte\Client;
|
|
|
|
class Account
|
|
{
|
|
/** @var Client */
|
|
protected $client;
|
|
/** @var Config */
|
|
protected $config;
|
|
/** @var bool */
|
|
protected $is_connected = false;
|
|
|
|
/**
|
|
* Account constructor.
|
|
* @param Client $client
|
|
* @param Config $config
|
|
*/
|
|
public function __construct(Config $config)
|
|
{
|
|
$this->client = new \Goutte\Client();
|
|
$this->client->setClient(
|
|
new \GuzzleHttp\Client([
|
|
'timeout' => 90,
|
|
'verify' => false,
|
|
'curl' => [
|
|
CURLOPT_TIMEOUT => 60,
|
|
CURLOPT_TIMEOUT_MS => 60,
|
|
CURLOPT_CONNECTTIMEOUT => 60,
|
|
],
|
|
'headers' => [
|
|
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0',
|
|
],
|
|
])
|
|
);
|
|
$this->client->setMaxRedirects(10);
|
|
$this->config = $config;
|
|
}
|
|
|
|
/**
|
|
* @return Client
|
|
*/
|
|
public function getClient()
|
|
{
|
|
return $this->client;
|
|
}
|
|
|
|
/**
|
|
* @return Config
|
|
*/
|
|
public function getConfig()
|
|
{
|
|
return $this->config;
|
|
}
|
|
|
|
/**
|
|
* Check if it's connected
|
|
* (if there's a "logout" link)
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isConnected()
|
|
{
|
|
if (!$this->is_connected) {
|
|
$crawler = $this->client->request('GET', Actions::HOME_URL);
|
|
$this->is_connected = $crawler->filter('#account_logout')->count() == 1;
|
|
}
|
|
return $this->is_connected;
|
|
}
|
|
|
|
/**
|
|
* @param bool $connected
|
|
*/
|
|
public function setConnected($connected = false)
|
|
{
|
|
$this->is_connected = $connected;
|
|
}
|
|
}
|