From dd2a6bd7d7ce07e94f976cae4f860695444a862a Mon Sep 17 00:00:00 2001 From: Shikiryu Date: Fri, 1 Jul 2016 21:59:39 +0200 Subject: [PATCH] Add a lot of docs --- app/code/Transport/Email.php | 12 +++++++++-- app/code/Transport/FTP.php | 5 +++++ app/code/Transport/Folder.php | 3 ++- app/code/Transport/SFTP.php | 9 ++++++-- app/code/Transport/TransportAbstract.php | 2 ++ app/code/backup/BackupAbstract.php | 26 ++++++++++++++++++++---- app/code/backup/Files.php | 18 +++++++++++++++- app/code/backup/Folder.php | 9 ++++++++ app/code/backup/Mysql.php | 9 ++++++++ 9 files changed, 83 insertions(+), 10 deletions(-) diff --git a/app/code/Transport/Email.php b/app/code/Transport/Email.php index 1ce2b4b..9691bf4 100644 --- a/app/code/Transport/Email.php +++ b/app/code/Transport/Email.php @@ -157,6 +157,11 @@ class Email extends TransportAbstract $this->encoding = $this->config['encoding']; } + /** + * @param array $files + * + * @return $this + */ private function setFiles($files = array()) { if (is_array($files) && !empty($files)) { @@ -165,6 +170,11 @@ class Email extends TransportAbstract return $this; } + /** + * @param array $streams + * + * @return $this + */ private function setStreams($streams = array()) { if (is_array($streams) && !empty($streams)) { @@ -240,5 +250,3 @@ Content-Disposition: attachment; filename=" . $name . " } } - -?> diff --git a/app/code/Transport/FTP.php b/app/code/Transport/FTP.php index 9957bd9..6a909db 100644 --- a/app/code/Transport/FTP.php +++ b/app/code/Transport/FTP.php @@ -51,6 +51,9 @@ class Ftp extends TransportAbstract return $this; } + /** + * @return bool + */ public function send() { $sent = true; @@ -82,6 +85,8 @@ class Ftp extends TransportAbstract if (!$sent) { throw new \Exception('At least an upload didnt work.'); } + + return $sent; } public function __destruct() diff --git a/app/code/Transport/Folder.php b/app/code/Transport/Folder.php index bc761c6..d167727 100644 --- a/app/code/Transport/Folder.php +++ b/app/code/Transport/Folder.php @@ -7,7 +7,7 @@ use Shikiryu\Backup\Backup\BackupAbstract; class Folder extends TransportAbstract { - + /** @var string */ protected $folder; public function __construct(BackupAbstract $backup, array $config = array()) @@ -21,6 +21,7 @@ class Folder extends TransportAbstract /** * @return bool + * * @throws \Exception */ public function send() diff --git a/app/code/Transport/SFTP.php b/app/code/Transport/SFTP.php index 0a444a0..2adb348 100644 --- a/app/code/Transport/SFTP.php +++ b/app/code/Transport/SFTP.php @@ -6,13 +6,17 @@ use phpseclib\Net\SFTP as LibSFTP; class Sftp extends TransportAbstract { - + /** @var string */ protected $host; + /** @var int */ protected $port = 22; + /** @var string */ protected $login; + /** @var string */ protected $password; + /** @var string */ protected $folder; - + /** @var LibSFTP */ private $connection; /** @@ -32,6 +36,7 @@ class Sftp extends TransportAbstract /** * @return bool + * * @throws \Exception */ public function send() diff --git a/app/code/Transport/TransportAbstract.php b/app/code/Transport/TransportAbstract.php index ebefe7f..00cedf3 100644 --- a/app/code/Transport/TransportAbstract.php +++ b/app/code/Transport/TransportAbstract.php @@ -7,7 +7,9 @@ use Shikiryu\Backup\Backup\BackupAbstract; abstract class TransportAbstract { + /** @var BackupAbstract */ protected $backup; + /** @var array */ protected $config; public function __construct(BackupAbstract $backup, array $config) diff --git a/app/code/backup/BackupAbstract.php b/app/code/backup/BackupAbstract.php index d00d7cf..69b623f 100644 --- a/app/code/backup/BackupAbstract.php +++ b/app/code/backup/BackupAbstract.php @@ -4,7 +4,7 @@ namespace Shikiryu\Backup\Backup; abstract class BackupAbstract { - + /** @var array */ protected $options; /** @var string[] */ protected $_filesToBackup = []; @@ -75,6 +75,9 @@ abstract class BackupAbstract return true; } + /** + * Initialize everything + */ protected function init() { $this->preBuild(); @@ -82,10 +85,24 @@ abstract class BackupAbstract $this->postBuild(); $this->applyOptions(); } - + + /** + * Function that can be used to initialize the backup + */ abstract protected function preBuild(); + /** + * Function that can be used after the backup + */ abstract protected function postBuild(); + /** + * Mandatory function doing the backup + */ abstract protected function build(); + /** + * Check if the backup is valid + * + * @return bool + */ abstract public function isValid(); /** @@ -204,7 +221,10 @@ abstract class BackupAbstract /** * @param $name + * * @throws \Exception + * + * @SuppressWarnings("unused") */ protected function setOptionName($name) { @@ -214,5 +234,3 @@ abstract class BackupAbstract } } - -?> diff --git a/app/code/backup/Files.php b/app/code/backup/Files.php index ff01b2d..a2b3b70 100644 --- a/app/code/backup/Files.php +++ b/app/code/backup/Files.php @@ -21,6 +21,13 @@ class Files extends BackupAbstract parent::__construct($config); } + /** + * Check if the backup is valid + * + * @return bool + * + * @SuppressWarnings("unused") + */ public function isValid() { $result = true; @@ -32,17 +39,26 @@ class Files extends BackupAbstract } return $result; } - + + /** + * Function that can be used to initialize the backup + */ protected function preBuild() { // TODO: Implement preBuild() method. } + /** + * Function that can be used after the backup + */ protected function postBuild() { // TODO: Implement postBuild() method. } + /** + * Mandatory function doing the backup + */ protected function build() { // TODO: Implement build() method. diff --git a/app/code/backup/Folder.php b/app/code/backup/Folder.php index f68e8e0..a36a4b5 100644 --- a/app/code/backup/Folder.php +++ b/app/code/backup/Folder.php @@ -18,16 +18,25 @@ class Folder extends BackupAbstract // TODO: Implement isValid() method. } + /** + * Function that can be used to initialize the backup + */ protected function preBuild() { // TODO: Implement preBuild() method. } + /** + * Function that can be used after the backup + */ protected function postBuild() { // TODO: Implement postBuild() method. } + /** + * Mandatory function doing the backup + */ protected function build() { // TODO: Implement build() method. diff --git a/app/code/backup/Mysql.php b/app/code/backup/Mysql.php index 897dafb..b0cd461 100644 --- a/app/code/backup/Mysql.php +++ b/app/code/backup/Mysql.php @@ -100,16 +100,25 @@ class Mysql extends BackupAbstract return !empty($this->_streamsToBackup); } + /** + * Function that can be used to initialize the backup + */ protected function preBuild() { $this->pdo = new \PDO('mysql:host='.$this->host.';dbname='.$this->database, $this->login, $this->pwd); } + /** + * Function that can be used after the backup + */ protected function postBuild() { // TODO: Implement postBuild() method. } + /** + * Mandatory function doing the backup + */ protected function build() { empty($this->tables) || $this->tables == '*' ? $this->everything() : $this->fromTables($this->tables);