class hackedProjectWebDownloader in Hacked! 8.2
Base class for downloading remote versions of projects.
Hierarchy
- class \Drupal\hacked\hackedProjectWebDownloader uses StringTranslationTrait
Expanded class hierarchy of hackedProjectWebDownloader
File
- src/
hackedProjectWebDownloader.php, line 11
Namespace
Drupal\hackedView source
class hackedProjectWebDownloader {
use StringTranslationTrait;
var $project;
/**
* Constructor, pass in the project this downloaded is expected to download.
*/
function __construct(&$project) {
$this->project = $project;
}
/**
* Returns a temp directory to work in.
*
* @param null $namespace
* The optional namespace of the temp directory, defaults to the classname.
* @return bool|string
*/
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;
}
/**
* Returns a directory to save the downloaded project into.
*/
function get_destination() {
$type = $this->project->project_type;
$name = $this->project->name;
$version = $this->project->existing_version;
$dir = $this
->get_temp_directory() . "/{$type}/{$name}";
// Build the destination folder tree if it doesn't already exists.
if (!\Drupal::service('file_system')
->prepareDirectory($dir, FileSystemInterface::CREATE_DIRECTORY) && !mkdir($dir, 0775, TRUE)) {
$message = $this
->t('Failed to create temp directory: %dir', [
'%dir' => $dir,
]);
\Drupal::logger('hacked')
->error($message);
return FALSE;
}
return "{$dir}/{$version}";
}
/**
* Returns the final destination of the unpacked project.
*/
function get_final_destination() {
$dir = $this
->get_destination();
$name = $this->project->name;
$version = $this->project->existing_version;
$type = $this->project->project_type;
// More special handling for core:
if ($type != 'core') {
$module_dir = $dir . "/{$name}";
}
else {
$module_dir = $dir . '/' . $name . '-' . $version;
}
return $module_dir;
}
/**
* Download the remote files to the local filesystem.
*/
function download() {
}
/**
* Recursively delete all files and folders in the specified filepath, then
* delete the containing folder.
*
* Note that this only deletes visible files with write permission.
*
* @param string $path
* A filepath relative to file_directory_path.
*/
function remove_dir($path) {
if (is_file($path) || is_link($path)) {
unlink($path);
}
elseif (is_dir($path)) {
$d = dir($path);
while (($entry = $d
->read()) !== FALSE) {
if ($entry == '.' || $entry == '..') {
continue;
}
$entry_path = $path . '/' . $entry;
$this
->remove_dir($entry_path);
}
$d
->close();
rmdir($path);
}
else {
$message = $this
->t('Unknown file type(%path) stat: %stat ', [
'%path' => $path,
'%stat' => print_r(stat($path), 1),
]);
\Drupal::logger('hacked')
->error($message);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
hackedProjectWebDownloader:: |
property | |||
hackedProjectWebDownloader:: |
function | Download the remote files to the local filesystem. | 2 | |
hackedProjectWebDownloader:: |
function | Returns a directory to save the downloaded project into. | ||
hackedProjectWebDownloader:: |
function | Returns the final destination of the unpacked project. | 1 | |
hackedProjectWebDownloader:: |
function | Returns a temp directory to work in. | ||
hackedProjectWebDownloader:: |
function | Recursively delete all files and folders in the specified filepath, then delete the containing folder. | ||
hackedProjectWebDownloader:: |
function | Constructor, pass in the project this downloaded is expected to download. | ||
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |