API/library/Account.php

66 lines
1.3 KiB
PHP
Raw Normal View History

2016-08-20 23:02:05 +02:00
<?php
namespace Shikiryu\LBCReposter;
use Goutte\Client;
class Account
{
/** @var Client */
protected $client;
/** @var Config */
protected $config;
2016-08-20 23:02:05 +02:00
/** @var bool */
protected $is_connected = false;
/**
* Account constructor.
* @param Client $client
* @param Config $config
2016-08-20 23:02:05 +02:00
*/
public function __construct(Client $client, Config $config)
2016-08-20 23:02:05 +02:00
{
$this->client = $client;
$this->config = $config;
2016-08-20 23:02:05 +02:00
}
/**
* @return Client
*/
public function getClient()
{
return $this->client;
}
/**
* @return Config
*/
public function getConfig()
2016-08-20 23:02:05 +02:00
{
return $this->config;
2016-08-20 23:02:05 +02:00
}
/**
* Check if it's connected
* (if there's a "logout" link)
*
* @return bool
*/
public function isConnected()
2016-08-20 23:02:05 +02:00
{
if (!$this->is_connected) {
$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;
}
/**
* @param bool $connected
*/
public function setConnected($connected = false)
{
$this->is_connected = $connected;
}
2016-09-12 16:41:57 +02:00
}