class Local
Same name and namespace in other branches
- 11.x core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local
- 10 core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local
- 8.9.x core/lib/Drupal/Core/FileTransfer/Local.php \Drupal\Core\FileTransfer\Local
Defines the local connection class for copying files as the httpd user.
Hierarchy
- class \Drupal\Core\FileTransfer\FileTransfer
- class \Drupal\Core\FileTransfer\Local implements \Drupal\Core\FileTransfer\ChmodInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait extends \Drupal\Core\FileTransfer\FileTransfer
Expanded class hierarchy of Local
3 files declare their use of Local
- TestFileTransferWithSettingsForm.php in core/
modules/ update/ tests/ modules/ update_test/ src/ TestFileTransferWithSettingsForm.php - UpdateManagerInstall.php in core/
modules/ update/ src/ Form/ UpdateManagerInstall.php - UpdateReady.php in core/
modules/ update/ src/ Form/ UpdateReady.php
5 string references to 'Local'
- InstallerExistingConfigSyncDirectoryMultilingualTest::prepareEnvironment in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerExistingConfigSyncDirectoryMultilingualTest.php - InstallerExistingConfigSyncDirectoryMultilingualTest::testConfigSync in core/
tests/ Drupal/ FunctionalTests/ Installer/ InstallerExistingConfigSyncDirectoryMultilingualTest.php - Confirms that the installation installed the configuration correctly.
- locale.settings.yml in core/
profiles/ testing_multilingual/ config/ install/ locale.settings.yml - core/profiles/testing_multilingual/config/install/locale.settings.yml
- LocaleUpdateBase::setTranslationFiles in core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateBase.php - Setup the environment containing local and remote translation files.
- LocaleUpdateInterfaceTest::testInterface in core/
modules/ locale/ tests/ src/ Functional/ LocaleUpdateInterfaceTest.php - Tests the user interfaces of the interface translation update system.
File
-
core/
lib/ Drupal/ Core/ FileTransfer/ Local.php, line 11
Namespace
Drupal\Core\FileTransferView source
class Local extends FileTransfer implements ChmodInterface {
use DependencySerializationTrait;
/**
* The file system service.
*
* @var \Drupal\Core\File\FileSystemInterface
*/
protected $fileSystem;
/**
* {@inheritdoc}
*/
public function __construct($jail, FileSystemInterface $file_system) {
parent::__construct($jail);
$this->fileSystem = $file_system;
}
/**
* {@inheritdoc}
*/
public function connect() {
// No-op
}
/**
* {@inheritdoc}
*/
public static function factory($jail, $settings) {
return new Local($jail, \Drupal::service('file_system'));
}
/**
* {@inheritdoc}
*/
protected function copyFileJailed($source, $destination) {
if (@!copy($source, $destination)) {
throw new FileTransferException('Cannot copy %source to %destination.', 0, [
'%source' => $source,
'%destination' => $destination,
]);
}
}
/**
* {@inheritdoc}
*/
protected function createDirectoryJailed($directory) {
if (!is_dir($directory) && @!mkdir($directory, 0777, TRUE)) {
throw new FileTransferException('Cannot create directory %directory.', 0, [
'%directory' => $directory,
]);
}
}
/**
* {@inheritdoc}
*/
protected function removeDirectoryJailed($directory) {
if (!is_dir($directory)) {
// Programmer error assertion, not something we expect users to see.
throw new FileTransferException('removeDirectoryJailed() called with a path (%directory) that is not a directory.', 0, [
'%directory' => $directory,
]);
}
/** @var \Drupal\Core\File\FileSystemInterface $file_system */
$file_system = \Drupal::service('file_system');
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::CHILD_FIRST) as $filename => $file) {
if ($file->isDir()) {
if (@!$file_system->rmdir($filename)) {
throw new FileTransferException('Cannot remove directory %directory.', 0, [
'%directory' => $filename,
]);
}
}
elseif ($file->isFile()) {
if (@!$this->fileSystem
->unlink($filename)) {
throw new FileTransferException('Cannot remove file %file.', 0, [
'%file' => $filename,
]);
}
}
}
if (@!$file_system->rmdir($directory)) {
throw new FileTransferException('Cannot remove directory %directory.', 0, [
'%directory' => $directory,
]);
}
}
/**
* {@inheritdoc}
*/
protected function removeFileJailed($file) {
if (@!$this->fileSystem
->unlink($file)) {
throw new FileTransferException('Cannot remove file %file.', 0, [
'%file' => $file,
]);
}
}
/**
* {@inheritdoc}
*/
public function isDirectory($path) {
return is_dir($path);
}
/**
* {@inheritdoc}
*/
public function isFile($path) {
return is_file($path);
}
/**
* {@inheritdoc}
*/
public function chmodJailed($path, $mode, $recursive) {
if ($recursive && is_dir($path)) {
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $filename => $file) {
if (@!chmod($filename, $mode)) {
throw new FileTransferException('Cannot chmod %path.', 0, [
'%path' => $filename,
]);
}
}
}
elseif (@!chmod($path, $mode)) {
throw new FileTransferException('Cannot chmod %path.', 0, [
'%path' => $path,
]);
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.