View source
<?php
namespace Drupal\drd_agent;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class Setup {
protected $values;
protected $state;
protected $time;
protected $request;
public function __construct(StateInterface $state, TimeInterface $time, RequestStack $request_stack) {
$this->state = $state;
$this->time = $time;
$this->request = $request_stack
->getCurrentRequest();
$this
->checkForRemoteSetupToken();
}
private function checkForRemoteSetupToken() {
if (isset($_SESSION['drd_agent_authorization_values'])) {
$this
->setRemoteSetupToken($_SESSION['drd_agent_authorization_values']);
}
}
public function setRemoteSetupToken($remoteSetupToken) : self {
$values = strtr($remoteSetupToken, [
'-' => '+',
'_' => '/',
]);
$this->values = json_decode(base64_decode($values), TRUE);
return $this;
}
public function execute() : array {
$this
->checkForRemoteSetupToken();
$authorised = $this->state
->get('drd_agent.authorised', []);
$this->values['timestamp'] = $this->time
->getRequestTime();
$this->values['ip'] = $this->request
->getClientIp();
$authorised[$this->values['uuid']] = $this->values;
$this->state
->set('drd_agent.authorised', $authorised);
return $this->values;
}
public function getDomain() {
$this
->checkForRemoteSetupToken();
if (isset($this->values['redirect'])) {
return parse_url($this->values['redirect'], PHP_URL_HOST);
}
return FALSE;
}
}