🎨 Apply PSR2

This commit is contained in:
Clement Desmidt 2019-01-25 21:39:18 +01:00
parent ab7887ce84
commit db51375185
4 changed files with 103 additions and 100 deletions

View File

@ -125,7 +125,8 @@ class Email extends TransportAbstract
* *
* @return string * @return string
*/ */
public static function getMimeType($file) { public static function getMimeType($file)
{
if (function_exists('finfo_open')) { if (function_exists('finfo_open')) {
$finfo = finfo_open(FILEINFO_MIME_TYPE); $finfo = finfo_open(FILEINFO_MIME_TYPE);
$type = (string) finfo_file($finfo, $file); $type = (string) finfo_file($finfo, $file);
@ -135,17 +136,19 @@ class Email extends TransportAbstract
return mime_content_type($file); return mime_content_type($file);
} else { } else {
$ext = strtolower(array_pop(explode('.', $file))); $ext = strtolower(array_pop(explode('.', $file)));
if (array_key_exists($ext, self::$mimeTypes)) if (array_key_exists($ext, self::$mimeTypes)) {
return self::$mimeTypes[$ext]; return self::$mimeTypes[$ext];
else } else {
return 'application/octet-stream'; return 'application/octet-stream';
} }
} }
}
/** /**
* @param BackupAbstract $backup * @param BackupAbstract $backup
*/ */
public function __construct(BackupAbstract $backup, array $config) { public function __construct(BackupAbstract $backup, array $config)
{
parent::__construct($backup, $config); parent::__construct($backup, $config);
$this->setFiles($this->backup->getFilesTobackup()); $this->setFiles($this->backup->getFilesTobackup());
$this->setStreams($this->backup->getStreamsTobackup()); $this->setStreams($this->backup->getStreamsTobackup());
@ -198,10 +201,9 @@ class Email extends TransportAbstract
// Checking files are selected // Checking files are selected
$zip = new \ZipArchive(); // Load zip library $zip = new \ZipArchive(); // Load zip library
$zip_name = time().".zip"; // Zip name $zip_name = time().".zip"; // Zip name
if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==TRUE) { if ($zip->open(TEMP_DIR.$zip_name, \ZIPARCHIVE::CREATE)==true) {
if(!empty($this->files)) { if (!empty($this->files)) {
foreach($this->files as $file => $name) foreach ($this->files as $file => $name) {
{
$zip->addFile($file, $name); // Adding files into zip $zip->addFile($file, $name); // Adding files into zip
} }
} }
@ -223,8 +225,8 @@ Content-Transfer-Encoding: 8bit
" . $this->message . "\r\n"; " . $this->message . "\r\n";
if(!empty($this->files)) if (!empty($this->files)) {
foreach($this->files as $file => $name) { foreach ($this->files as $file => $name) {
$output .= " $output .= "
--$random_hash --$random_hash
Content-Type: " . self::getMimeType($file) . "; name=" . $name . " Content-Type: " . self::getMimeType($file) . "; name=" . $name . "
@ -233,10 +235,13 @@ Content-Disposition: attachment; filename=" . $name . "
" . chunk_split(base64_encode(file_get_contents($file))); " . chunk_split(base64_encode(file_get_contents($file)));
} }
}
if(!empty($this->streams)) if (!empty($this->streams)) {
foreach($this->streams as $name=>$stream) { foreach ($this->streams as $name => $stream) {
if(count(explode('.',$name))<2) $name = 'backup'.$name.'.txt'; if (count(explode('.', $name))<2) {
$name = 'backup'.$name.'.txt';
}
$output .= " $output .= "
--$random_hash --$random_hash
Content-Type: text/plain; name=" . $name . " Content-Type: text/plain; name=" . $name . "
@ -245,8 +250,8 @@ Content-Disposition: attachment; filename=" . $name . "
" . chunk_split(base64_encode($stream)); " . chunk_split(base64_encode($stream));
} }
}
$output.="--$random_hash--"; $output.="--$random_hash--";
return mail($this->email_to, $this->subject, $output, $headers); return mail($this->email_to, $this->subject, $output, $headers);
} }
} }

View File

@ -28,7 +28,7 @@ abstract class BackupAbstract
* *
* @param array $config array of options and parameters * @param array $config array of options and parameters
*/ */
function __construct($config = array()) public function __construct($config = array())
{ {
$this->options = !empty($config['options']) ? $config['options'] : []; $this->options = !empty($config['options']) ? $config['options'] : [];
@ -174,7 +174,7 @@ abstract class BackupAbstract
if (touch(TEMP_DIR . $zip_name) === false) { if (touch(TEMP_DIR . $zip_name) === false) {
throw new \Exception('Backup::Zip::Permission denied.'); throw new \Exception('Backup::Zip::Permission denied.');
} }
if ($zip->open(TEMP_DIR . $zip_name, \ZipArchive::OVERWRITE) == TRUE) { if ($zip->open(TEMP_DIR . $zip_name, \ZipArchive::OVERWRITE) == true) {
foreach ($this->files_to_backup as $file => $name) { foreach ($this->files_to_backup as $file => $name) {
$zip->addFile($file, $name); // Adding files into zip $zip->addFile($file, $name); // Adding files into zip
} }
@ -270,5 +270,4 @@ abstract class BackupAbstract
throw new \Exception('name option is for zip only.'); throw new \Exception('name option is for zip only.');
} }
} }
} }

View File

@ -14,9 +14,9 @@ class Files extends BackupAbstract
throw new \Exception('Files needs a "files" configuration.'); throw new \Exception('Files needs a "files" configuration.');
} }
$filesToBackup = $config['files']; $filesToBackup = $config['files'];
if(!empty($filesToBackup) && is_array($filesToBackup)){ if (!empty($filesToBackup) && is_array($filesToBackup)) {
$names = array_map("basename",$filesToBackup); $names = array_map("basename", $filesToBackup);
$this->files_to_backup = array_combine($filesToBackup,$names); $this->files_to_backup = array_combine($filesToBackup, $names);
} }
parent::__construct($config); parent::__construct($config);
} }
@ -64,4 +64,3 @@ class Files extends BackupAbstract
// TODO: Implement build() method. // TODO: Implement build() method.
} }
} }
?>