Added validators and new transport

This commit is contained in:
Shikiryu
2015-07-12 20:34:54 +02:00
parent 091dd4cf22
commit 8426972504
9 changed files with 165 additions and 138 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace Shikiryu\Backup\Transport;
use Shikiryu\Backup\Backup\BackupAbstract;
class Folder extends TransportAbstract
{
protected $folder;
public function __construct(BackupAbstract $backup, array $config = array())
{
parent::__construct($backup, $config);
if (!empty($this->folder)) {
$this->folder = sprintf('%s/', rtrim($this->folder, '/'));
}
}
/**
* @return bool
* @throws \Exception
*/
public function send()
{
foreach ($this->backup->getFilesToBackup() as $file => $name) {
if (copy($file, $this->folder . $name) === false) {
throw new \Exception(sprintf('Copy of %s in %s failed', $name, $this->folder));
};
}
foreach ($this->backup->getStreamsToBackup() as $name => $file) {
if (count(explode('.', $name)) < 2) {
$name = 'backup' . $name . '.txt';
}
if (file_put_contents($this->folder . $name, $file) === false) {
throw new \Exception(sprintf('Saving of %s in %s failed', $name, $this->folder));
}
}
return true;
}
}