You are here

function hackedProjectWebDownloader::get_temp_directory in Hacked! 8.2

Returns a temp directory to work in.

Parameters

null $namespace: The optional namespace of the temp directory, defaults to the classname.

Return value

bool|string

1 call to hackedProjectWebDownloader::get_temp_directory()
hackedProjectWebDownloader::get_destination in src/hackedProjectWebDownloader.php
Returns a directory to save the downloaded project into.

File

src/hackedProjectWebDownloader.php, line 30

Class

hackedProjectWebDownloader
Base class for downloading remote versions of projects.

Namespace

Drupal\hacked

Code

function get_temp_directory($namespace = NULL) {
  if (is_null($namespace)) {
    $reflect = new \ReflectionClass($this);
    $namespace = $reflect
      ->getShortName();
  }
  $segments = [
    \Drupal::service('file_system')
      ->getTempDirectory(),
    'hacked-cache-' . get_current_user(),
    $namespace,
  ];
  $dir = implode('/', array_filter($segments));
  if (!\Drupal::service('file_system')
    ->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
    $message = $this
      ->t('Failed to create temp directory: %dir', array(
      '%dir' => $dir,
    ));
    \Drupal::logger('hacked')
      ->error($message);
    return FALSE;
  }
  return $dir;
}