diff --git a/include/class-FTP.php b/include/class-FTP.php index a87eadd..52402a7 100644 --- a/include/class-FTP.php +++ b/include/class-FTP.php @@ -1,92 +1,106 @@ . // load dependent traits class_exists( 'Domain' ); /** - * An FTP user + * Methods for an FTP class */ -class FTP extends Queried { +trait FTPTrait { - use DomainAPITrait; - - /** - * Table name - */ - const T = 'ftp'; - - /** - * Constructor - * - * Normalize the object obtained from the database - */ - public function __construct() { - $this->normalizeDomain(); - $this->booleans( 'ftp_active' ); - $this->integers( 'ftp_ulbandwidth', - 'ftp_dlbandwidth', - 'ftp_quotasize', - 'ftp_quotafiles' ); - } + use DomainTrait; /** * Get the FTP login username * * @return string E-mail */ public function getFTPLogin() { return $this->get( 'ftp_login' ); } /** * Check if this FTP account is active * * @return bool */ public function isFTPActive() { return $this->get( 'ftp_active' ); } /** * Get the mailbox permalink * * @return string */ public function getFTPPermalink( $absolute = false ) { return FTP::permalink( $this->getDomainName(), $this->getFTPLogin() ); } + protected function normalizeFTP() { + $this->normalizeDomain(); + $this->booleans( 'ftp_active' ); + $this->integers( 'ftp_ulbandwidth', + 'ftp_dlbandwidth', + 'ftp_quotasize', + 'ftp_quotafiles' + ); + } + +} + +/** + * An FTP user + */ +class FTP extends Queried { + + use FTPTrait; + + /** + * Table name + */ + const T = 'ftp'; + + /** + * Constructor + * + * Normalize the object obtained from the database + */ + public function __construct() { + $this->normalizeFTP(); + } + /** * Get the FTP permalink from domain name and FTP login * * @param string $domain Domain name * @param string $login FTP user login * @return string */ public static function permalink( $domain, $login = null ) { $url = sprintf( '%s/%s', ROOT . '/ftp.php', $domain ); if( $login ) { $url .= "/$login"; } return $url; } }