2016-08-20 23:02:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Shikiryu\LBCReposter;
|
|
|
|
|
2018-06-29 00:04:32 +02:00
|
|
|
use GuzzleHttp\Client;
|
2016-08-20 23:02:05 +02:00
|
|
|
|
|
|
|
class Account
|
|
|
|
{
|
|
|
|
/** @var Client */
|
|
|
|
protected $client;
|
2016-09-11 22:53:40 +02:00
|
|
|
/** @var Config */
|
|
|
|
protected $config;
|
2016-08-20 23:02:05 +02:00
|
|
|
/** @var bool */
|
|
|
|
protected $is_connected = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Account constructor.
|
|
|
|
* @param Client $client
|
2016-09-11 22:53:40 +02:00
|
|
|
* @param Config $config
|
2016-08-20 23:02:05 +02:00
|
|
|
*/
|
2017-09-28 22:33:47 +02:00
|
|
|
public function __construct(Config $config)
|
2016-08-20 23:02:05 +02:00
|
|
|
{
|
2018-06-29 00:04:32 +02:00
|
|
|
$this->client = new Client([
|
|
|
|
'timeout' => 90,
|
|
|
|
'verify' => false,
|
|
|
|
'curl' => [
|
|
|
|
CURLOPT_TIMEOUT => 60,
|
|
|
|
CURLOPT_TIMEOUT_MS => 60,
|
|
|
|
CURLOPT_CONNECTTIMEOUT => 60,
|
|
|
|
CURLOPT_COOKIEJAR => tmpfile(),
|
|
|
|
],
|
|
|
|
'headers' => [
|
|
|
|
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/39.0',
|
|
|
|
],
|
|
|
|
]);
|
2016-09-11 22:53:40 +02:00
|
|
|
$this->config = $config;
|
2016-08-20 23:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Client
|
|
|
|
*/
|
|
|
|
public function getClient()
|
|
|
|
{
|
|
|
|
return $this->client;
|
|
|
|
}
|
|
|
|
|
2016-08-24 23:37:29 +02:00
|
|
|
/**
|
2017-09-27 21:42:22 +02:00
|
|
|
* @return Config
|
2016-08-24 23:37:29 +02:00
|
|
|
*/
|
2017-09-27 21:42:22 +02:00
|
|
|
public function getConfig()
|
2016-08-20 23:02:05 +02:00
|
|
|
{
|
2017-09-27 21:42:22 +02:00
|
|
|
return $this->config;
|
2016-08-20 23:02:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-24 23:37:29 +02:00
|
|
|
/**
|
2017-09-27 21:42:22 +02:00
|
|
|
* Check if it's connected
|
|
|
|
* (if there's a "logout" link)
|
2016-08-24 23:37:29 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-09-27 21:42:22 +02:00
|
|
|
public function isConnected()
|
2016-08-20 23:02:05 +02:00
|
|
|
{
|
2017-09-27 21:42:22 +02:00
|
|
|
if (!$this->is_connected) {
|
2018-06-29 00:04:32 +02:00
|
|
|
// $crawler = $this->client->request('GET', Actions::HOME_URL);
|
|
|
|
// $this->is_connected = $crawler->filter('#account_logout')->count() == 1;
|
2016-08-20 23:02:05 +02:00
|
|
|
}
|
|
|
|
return $this->is_connected;
|
|
|
|
}
|
|
|
|
|
2016-08-24 23:37:29 +02:00
|
|
|
/**
|
2017-09-27 21:42:22 +02:00
|
|
|
* @param bool $connected
|
2016-08-24 23:37:29 +02:00
|
|
|
*/
|
2017-09-27 21:42:22 +02:00
|
|
|
public function setConnected($connected = false)
|
2017-09-06 22:28:00 +02:00
|
|
|
{
|
2017-09-27 21:42:22 +02:00
|
|
|
$this->is_connected = $connected;
|
2017-09-06 22:28:00 +02:00
|
|
|
}
|
2016-09-12 16:41:57 +02:00
|
|
|
}
|