Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / FileTransfer / FTP.php
1 <?php
2
3 namespace Drupal\Core\FileTransfer;
4
5 /**
6  * Defines the base class for FTP implementations.
7  */
8 abstract class FTP extends FileTransfer {
9
10   /**
11    * {@inheritdoc}
12    */
13   public function __construct($jail, $username, $password, $hostname, $port) {
14     $this->username = $username;
15     $this->password = $password;
16     $this->hostname = $hostname;
17     $this->port = $port;
18     parent::__construct($jail);
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public static function factory($jail, $settings) {
25     $username = empty($settings['username']) ? '' : $settings['username'];
26     $password = empty($settings['password']) ? '' : $settings['password'];
27     $hostname = empty($settings['advanced']['hostname']) ? 'localhost' : $settings['advanced']['hostname'];
28     $port = empty($settings['advanced']['port']) ? 21 : $settings['advanced']['port'];
29
30     if (function_exists('ftp_connect')) {
31       $class = 'Drupal\Core\FileTransfer\FTPExtension';
32     }
33     else {
34       throw new FileTransferException('No FTP backend available.');
35     }
36
37     return new $class($jail, $username, $password, $hostname, $port);
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function getSettingsForm() {
44     $form = parent::getSettingsForm();
45     $form['advanced']['port']['#default_value'] = 21;
46     return $form;
47   }
48
49 }