You are here

class FileCopierFactory in Automatic Updates 8.2

A file copier factory which returns file copiers according to configuration.

Hierarchy

  • class \Drupal\package_manager\FileCopierFactory implements \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierFactoryInterface

Expanded class hierarchy of FileCopierFactory

1 string reference to 'FileCopierFactory'
package_manager.services.yml in package_manager/package_manager.services.yml
package_manager/package_manager.services.yml
1 service uses FileCopierFactory
package_manager.file_copier.factory in package_manager/package_manager.services.yml
Drupal\package_manager\FileCopierFactory

File

package_manager/src/FileCopierFactory.php, line 16

Namespace

Drupal\package_manager
View source
class FileCopierFactory implements FileCopierFactoryInterface {

  /**
   * The decorated file copier factory.
   *
   * @var \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\FileCopierFactoryInterface
   */
  protected $decorated;

  /**
   * The PHP file copier service.
   *
   * @var \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\PhpFileCopierInterface
   */
  protected $phpFileCopier;

  /**
   * The rsync file copier service.
   *
   * @var \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\RsyncFileCopierInterface
   */
  protected $rsyncFileCopier;

  /**
   * The config factory service.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a FileCopierFactory object.
   *
   * @param \Symfony\Component\Process\ExecutableFinder $executable_finder
   *   The Symfony executable finder.
   * @param \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\PhpFileCopierInterface $php_file_copier
   *   The PHP file copier service.
   * @param \PhpTuf\ComposerStager\Infrastructure\Process\FileCopier\RsyncFileCopierInterface $rsync_file_copier
   *   The rsync file copier service.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory service.
   */
  public function __construct(ExecutableFinder $executable_finder, PhpFileCopierInterface $php_file_copier, RsyncFileCopierInterface $rsync_file_copier, ConfigFactoryInterface $config_factory) {
    $this->decorated = new StagerFileCopierFactory($executable_finder, $php_file_copier, $rsync_file_copier);
    $this->phpFileCopier = $php_file_copier;
    $this->rsyncFileCopier = $rsync_file_copier;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public function create() : FileCopierInterface {
    $copier = $this->configFactory
      ->get('package_manager.settings')
      ->get('file_copier');
    switch ($copier) {
      case 'rsync':
        return $this->rsyncFileCopier;
      case 'php':
        return $this->phpFileCopier;
      default:
        return $this->decorated
          ->create();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FileCopierFactory::$configFactory protected property The config factory service.
FileCopierFactory::$decorated protected property The decorated file copier factory.
FileCopierFactory::$phpFileCopier protected property The PHP file copier service.
FileCopierFactory::$rsyncFileCopier protected property The rsync file copier service.
FileCopierFactory::create public function
FileCopierFactory::__construct public function Constructs a FileCopierFactory object.