You are here

class DownloadController in Default Content Deploy 8

Returns responses for config module routes.

Hierarchy

Expanded class hierarchy of DownloadController

File

src/Controller/DownloadController.php, line 14

Namespace

Drupal\default_content_deploy\Controller
View source
class DownloadController implements ContainerInjectionInterface {

  /**
   * The DCD manager.
   *
   * @var \Drupal\default_content_deploy\DeployManager
   */
  protected $deployManager;

  /**
   * The File system.
   *
   * @var \Drupal\Core\File\FileSystemInterface
   */
  protected $fileSystem;

  /**
   * DownloadController constructor.
   *
   * @param \Drupal\default_content_deploy\DeployManager $deploy_manager
   *   The DCD manager.
   * @param \Drupal\Core\File\FileSystemInterface $file_system
   *   The File system.
   */
  public function __construct(DeployManager $deploy_manager, FileSystemInterface $file_system) {
    $this->deployManager = $deploy_manager;
    $this->fileSystem = $file_system;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('default_content_deploy.manager'), $container
      ->get('file_system'));
  }

  /**
   * Return binary archive file for download.
   *
   * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
   */
  public function downloadCompressedContent() {
    $this->deployManager
      ->compressContent();
    $path = $this->fileSystem
      ->getTempDirectory() . '/dcd/content.tar.gz';
    $headers = [
      'Content-Type' => 'application/tar+gzip',
      'Content-Description' => 'File Download',
      'Content-Disposition' => 'attachment; filename=content.tar.gz',
    ];
    return new BinaryFileResponse($path, 200, $headers);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DownloadController::$deployManager protected property The DCD manager.
DownloadController::$fileSystem protected property The File system.
DownloadController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
DownloadController::downloadCompressedContent public function Return binary archive file for download.
DownloadController::__construct public function DownloadController constructor.