You are here

class BackupDatabaseRemoteAdapter in Backup Database 8

BackupDatabaseRemoteAdapter class.

Hierarchy

Expanded class hierarchy of BackupDatabaseRemoteAdapter

2 files declare their use of BackupDatabaseRemoteAdapter
BackupDatabaseAdapterTest.php in tests/src/Unit/BackupDatabaseAdapterTest.php
Contains \Drupal\Tests\backup_db\Unit\BackupDatabaseAdapterTest
BackupDatabaseForm.php in src/Form/BackupDatabaseForm.php
Contains \Drupal\backup_db\Form\BackupDatabaseForm.

File

src/Adapter/BackupDatabaseRemoteAdapter.php, line 19
Contains \Drupal\backup_db\Adapter\BackupDatabaseRemoteAdapter

Namespace

Drupal\backup_db\Adapter
View source
class BackupDatabaseRemoteAdapter implements BackupDatabaseAdapterInterface {

  /**
   * @var \Drupal\backup_db\BackupDatabaseClientInterface
   */
  private $client;

  /**
   * @param $client \Drupal\backup_db\BackupDatabaseClientInterface
   */
  public function __construct(BackupDatabaseClientInterface $client) {
    $this->client = $client;
  }

  /**
   * Export method.
   */
  public function export() {
    $handler = $this->client
      ->getFileHandler();
    $handler
      ->setupFile($this->client
      ->getSettings());

    // @todo, run file validation here.
    $file = $handler
      ->getFile();
    $export = $this->client
      ->dump();
    $export
      ->start($file
      ->getFileUri());
    $this
      ->download($file
      ->getFileUri(), [
      'name' => $file
        ->getFileName(),
      'type' => $file
        ->getFileType(),
    ]);
    return TRUE;
  }

  /**
   * Expose the export for download.
   */
  private function download($path, $config) {
    $response = new BinaryFileResponse($path);
    $response
      ->trustXSendfileTypeHeader();
    $response->headers
      ->set('Content-Type', $config['type']);
    $response
      ->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $config['name']);
    $response
      ->prepare(\Symfony\Component\HttpFoundation\Request::createFromGlobals());
    $response
      ->send();
  }

}

Members