class Setup in DRD Agent 8.3
Same name in this branch
- 8.3 src/Setup.php \Drupal\drd_agent\Setup
- 8.3 src/Command/Setup.php \Drupal\drd_agent\Command\Setup
Same name and namespace in other branches
- 4.0.x src/Setup.php \Drupal\drd_agent\Setup
Class Setup.
@package Drupal\drd_agent
Hierarchy
- class \Drupal\drd_agent\Setup
Expanded class hierarchy of Setup
3 files declare their use of Setup
- Authorize.php in src/
Form/ Authorize.php - Drush.php in src/
Commands/ Drush.php - Setup.php in src/
Command/ Setup.php
1 string reference to 'Setup'
1 service uses Setup
File
- src/
Setup.php, line 14
Namespace
Drupal\drd_agentView source
class Setup {
protected $values;
/**
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
/**
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* Setup constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* @param \Drupal\Component\Datetime\TimeInterface $time
* @param \Symfony\Component\HttpFoundation\RequestStack $request_stack
*/
public function __construct(ConfigFactoryInterface $config_factory, TimeInterface $time, RequestStack $request_stack) {
$this->configFactory = $config_factory;
$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']);
}
}
/**
* Set the remote setup token which contains the configuration.
*
* @param string $remoteSetupToken
* The remote setup token.
*
* @return $this
*/
public function setRemoteSetupToken($remoteSetupToken) : self {
$values = strtr($remoteSetupToken, [
'-' => '+',
'_' => '/',
]);
$this->values = json_decode(base64_decode($values), TRUE);
return $this;
}
/**
* Perform the configuration with the data from the token.
*
* @return array
* The configuration data for this domain.
*/
public function execute() : array {
$this
->checkForRemoteSetupToken();
$config = $this->configFactory
->getEditable('drd_agent.settings');
$authorised = $config
->get('authorised') ?? [];
$this->values['timestamp'] = $this->time
->getRequestTime();
$this->values['ip'] = $this->request
->getClientIp();
$authorised[$this->values['uuid']] = $this->values;
$config
->set('authorised', $authorised)
->save(TRUE);
return $this->values;
}
/**
* Get the hostname to which we should redirect after confirmation.
*
* @return string
* The hostname.
*/
public function getDomain() : string {
$this
->checkForRemoteSetupToken();
return parse_url($this->values['redirect'], PHP_URL_HOST);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Setup:: |
protected | property | ||
Setup:: |
protected | property | ||
Setup:: |
protected | property | ||
Setup:: |
protected | property | ||
Setup:: |
private | function | ||
Setup:: |
public | function | Perform the configuration with the data from the token. | |
Setup:: |
public | function | Get the hostname to which we should redirect after confirmation. | |
Setup:: |
public | function | Set the remote setup token which contains the configuration. | |
Setup:: |
public | function | Setup constructor. |