forked from ifsnop/mysqldump-php
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from druidfi/code-refactor
Code refactor
- Loading branch information
Showing
24 changed files
with
1,503 additions
and
1,537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
/.settings | ||
# Vim swap files | ||
.*.sw* | ||
|
||
**/*.checksum | ||
/composer.lock | ||
/composer.phar | ||
/vendor/ | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM php:8.1-alpine | ||
|
||
RUN apk --update add --no-cache \ | ||
bash mysql-client \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
RUN docker-php-ext-install mysqli pdo pdo_mysql | ||
|
||
WORKDIR /app | ||
|
||
CMD ["tail", "-f", "/dev/null"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: | ||
|
||
db: | ||
container_name: "mysqldump-php-db" | ||
image: druidfi/mysql:5.7-drupal | ||
|
||
db2: | ||
container_name: "mysqldump-php-db2" | ||
image: druidfi/mysql:8.0-drupal | ||
|
||
php: | ||
container_name: "mysqldump-php" | ||
image: tester:latest | ||
build: | ||
context: . | ||
volumes: | ||
- .:/app | ||
depends_on: | ||
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
class CompressBzip2 implements CompressInterface | ||
{ | ||
private $fileHandler; | ||
|
||
public function __construct() | ||
{ | ||
if (!function_exists("bzopen")) { | ||
throw new Exception("Compression is enabled, but bzip2 lib is not installed or configured properly"); | ||
} | ||
} | ||
|
||
/** | ||
* @param string $filename | ||
*/ | ||
public function open($filename) | ||
{ | ||
$this->fileHandler = bzopen($filename, "w"); | ||
|
||
if (false === $this->fileHandler) { | ||
throw new Exception("Output file is not writable"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function write(string $str): int | ||
{ | ||
$bytesWritten = bzwrite($this->fileHandler, $str); | ||
|
||
if (false === $bytesWritten) { | ||
throw new Exception("Writting to file failed! Probably, there is no more free space left?"); | ||
} | ||
|
||
return $bytesWritten; | ||
} | ||
|
||
public function close(): bool | ||
{ | ||
return bzclose($this->fileHandler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
use Exception; | ||
|
||
class CompressGzip implements CompressInterface | ||
{ | ||
private $fileHandler; | ||
|
||
public function __construct() | ||
{ | ||
if (!function_exists("gzopen")) { | ||
throw new Exception("Compression is enabled, but gzip lib is not installed or configured properly"); | ||
} | ||
} | ||
|
||
public function open(string $filename) | ||
{ | ||
$this->fileHandler = gzopen($filename, "wb"); | ||
|
||
if (false === $this->fileHandler) { | ||
throw new Exception("Output file is not writable"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function write(string $str): int | ||
{ | ||
$bytesWritten = gzwrite($this->fileHandler, $str); | ||
|
||
if (false === $bytesWritten) { | ||
throw new Exception("Writing to file failed! Probably, there is no more free space left?"); | ||
} | ||
|
||
return $bytesWritten; | ||
} | ||
|
||
public function close(): bool | ||
{ | ||
return gzclose($this->fileHandler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
use Exception; | ||
|
||
class CompressGzipstream implements CompressInterface | ||
{ | ||
private $fileHandler; | ||
private $compressContext; | ||
|
||
public function open($filename) | ||
{ | ||
$this->fileHandler = fopen($filename, "wb"); | ||
|
||
if (false === $this->fileHandler) { | ||
throw new Exception("Output file is not writable"); | ||
} | ||
|
||
$this->compressContext = deflate_init(ZLIB_ENCODING_GZIP, ['level' => 9]); | ||
|
||
return true; | ||
} | ||
|
||
public function write(string $str): int | ||
{ | ||
$bytesWritten = fwrite($this->fileHandler, deflate_add($this->compressContext, $str, ZLIB_NO_FLUSH)); | ||
|
||
if (false === $bytesWritten) { | ||
throw new Exception("Writing to file failed! Probably, there is no more free space left?"); | ||
} | ||
|
||
return $bytesWritten; | ||
} | ||
|
||
public function close(): bool | ||
{ | ||
fwrite($this->fileHandler, deflate_add($this->compressContext, '', ZLIB_FINISH)); | ||
|
||
return fclose($this->fileHandler); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
interface CompressInterface | ||
{ | ||
public function open(string $filename); | ||
|
||
public function write(string $str): int; | ||
|
||
public function close(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
use Exception; | ||
|
||
abstract class CompressManagerFactory | ||
{ | ||
public static function create(string $c): CompressInterface | ||
{ | ||
$c = ucfirst(strtolower($c)); | ||
|
||
if (!CompressMethod::isValid($c)) { | ||
throw new Exception("Compression method ($c) is not defined yet"); | ||
} | ||
|
||
$methodClass = __NAMESPACE__."\\"."Compress".$c; | ||
|
||
return new $methodClass; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
use Ifsnop\Mysqldump\Mysqldump; | ||
|
||
/** | ||
* Enum with all available compression methods. | ||
*/ | ||
abstract class CompressMethod | ||
{ | ||
public static array $enums = [ | ||
Mysqldump::NONE, | ||
Mysqldump::GZIP, | ||
Mysqldump::BZIP2, | ||
Mysqldump::GZIPSTREAM, | ||
]; | ||
|
||
/** | ||
* @param string $c | ||
* @return boolean | ||
*/ | ||
public static function isValid(string $c): bool | ||
{ | ||
return in_array($c, self::$enums); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Ifsnop\Mysqldump\Compress; | ||
|
||
use Exception; | ||
|
||
class CompressNone implements CompressInterface | ||
{ | ||
private $fileHandler; | ||
|
||
public function open(string $filename) | ||
{ | ||
$this->fileHandler = fopen($filename, "wb"); | ||
|
||
if (false === $this->fileHandler) { | ||
throw new Exception("Output file is not writable"); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
public function write(string $str): int | ||
{ | ||
$bytesWritten = fwrite($this->fileHandler, $str); | ||
|
||
if (false === $bytesWritten) { | ||
throw new Exception("Writing to file failed! Probably, there is no more free space left?"); | ||
} | ||
|
||
return $bytesWritten; | ||
} | ||
|
||
public function close(): bool | ||
{ | ||
return fclose($this->fileHandler); | ||
} | ||
} |
Oops, something went wrong.