You are here

class Setup in DRD Agent 8.3

Same name in this branch
  1. 8.3 src/Setup.php \Drupal\drd_agent\Setup
  2. 8.3 src/Command/Setup.php \Drupal\drd_agent\Command\Setup
Same name and namespace in other branches
  1. 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'
drd_agent.services.yml in ./drd_agent.services.yml
drd_agent.services.yml
1 service uses Setup
drd_agent.setup in ./drd_agent.services.yml
Drupal\drd_agent\Setup

File

src/Setup.php, line 14

Namespace

Drupal\drd_agent
View 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

Namesort descending Modifiers Type Description Overrides
Setup::$configFactory protected property
Setup::$request protected property
Setup::$time protected property
Setup::$values protected property
Setup::checkForRemoteSetupToken private function
Setup::execute public function Perform the configuration with the data from the token.
Setup::getDomain public function Get the hostname to which we should redirect after confirmation.
Setup::setRemoteSetupToken public function Set the remote setup token which contains the configuration.
Setup::__construct public function Setup constructor.