Skip to content

Commit

Permalink
Add PHP 8-only Support (v3) (#149)
Browse files Browse the repository at this point in the history
* drop PHP 7 support, require symfony/process 5+, phpunit 9.5+

* drop PHP 7 support, remove unneeded laravel config

* convert to PHP 8 syntax

* remove deprecated `enableCompression()` method

* remove deprecated `enableCompression()` method

* add bzip2 compressor

* update requirements with required compression utilities, update section on compression with `Bzip2Compressor` info

* update changelog

* add/update files to more closely match spatie/package-skeleton-php

* Fix styling
  • Loading branch information
patinthehat authored Mar 31, 2021
1 parent 05e5955 commit 9b00348
Show file tree
Hide file tree
Showing 20 changed files with 196 additions and 389 deletions.
49 changes: 36 additions & 13 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,54 @@

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/spatie/db-dumper).
Please read and understand the contribution guide before creating an issue or pull request.

## Etiquette

## Pull Requests
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
extremely unfair for them to suffer abuse or anger for their hard work.

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
world that developers are civilized and selfless people.

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
## Viability

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
When requesting or submitting new features, first consider whether it might be useful to others. Open
source projects are used by many developers, who may have entirely different needs to your own. Think about
whether or not your feature is likely to be used by other users of the project.

- **Create feature branches** - Don't ask us to pull from your master branch.
## Procedure

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
Before filing an issue:

- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
- Check to make sure your feature suggestion isn't already present within the project.
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
- Check the pull requests tab to ensure that the feature isn't already in progress.

Before submitting a pull request:

- Check the codebase to ensure that your feature doesn't already exist.
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
## Requirements

If the project maintainer has any additional requirements, you will find them listed here.

## Running Tests
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).

``` bash
$ composer test
```
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

**Happy coding**!
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
github: spatie
custom: https://spatie.be/open-source/support-us
3 changes: 3 additions & 0 deletions .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Security Policy

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
3 changes: 1 addition & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.0, 7.4, 7.3, 7.2]
laravel: [8.*, 7.*, 6.*]
php: [8.0]
dependency-version: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `db-dumper` will be documented in this file

## 3.0.0 - unreleased

- require PHP 8+
- drop all PHP 7.x support
- use PHP 8 syntax
- add `Bzip2Compressor` to allow use of the bzip2 compression utility

## 2.21.1 - 2021-02-24

- fix attempt to generate dump over http connection when using socket (#145)
Expand Down
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ We invest a lot of resources into creating [best in class open source packages](
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

## Requirements

For dumping MySQL-db's `mysqldump` should be installed.

For dumping PostgreSQL-db's `pg_dump` should be installed.
Expand All @@ -65,6 +66,8 @@ For dumping SQLite-db's `sqlite3` should be installed.

For dumping MongoDB-db's `mongodump` should be installed.

For compressing dump files, `gzip` and/or `bzip2` should be installed.

## Installation

You can install the package via composer:
Expand Down Expand Up @@ -224,16 +227,20 @@ $dumpCommand = MySql::create()
Please note that using the `->addExtraOption('--databases dbname')` or `->addExtraOption('--all-databases')` will override the database name set on a previous `->setDbName()` call.

### Using compression
If you want to compress the outputted file, you can use one of the compressors and the resulted dump file will be compressed.

There is one compressor that comes out of the box: `GzipCompressor`. It will compress your db dump with `gzip`. Make sure `gzip` is installed on your system before using this.
If you want the output file to be compressed, you can use a compressor class.

There are two compressors that come out of the box:

- `GzipCompressor` - This will compress your db dump with `gzip`. Make sure `gzip` is installed on your system before using this.
- `Bzip2Compressor` - This will compress your db dump with `bzip2`. Make sure `bzip2` is installed on your system before using this.

```php
$dumpCommand = MySql::create()
->setDbName('dbname')
->setUserName('username')
->setPassword('password')
->useCompressor(new GzipCompressor())
->useCompressor(new GzipCompressor()) // or `new Bzip2Compressor()`
->dumpToFile('dump.sql.gz');
```

Expand Down Expand Up @@ -271,23 +278,23 @@ class GzipCompressor implements Compressor
}
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Testing

``` bash
composer test
$ composer test
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Contributing

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

## Security
## Security Vulnerabilities

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

## Credits

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
}
],
"require": {
"php" : "^7.2|^8.0",
"symfony/process": "^4.2|^5.0"
"php" : "^8.0",
"symfony/process": "^5.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0|^8.0|^9.0"
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 16 additions & 0 deletions src/Compressors/Bzip2Compressor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Spatie\DbDumper\Compressors;

class Bzip2Compressor implements Compressor
{
public function useCommand(): string
{
return 'bzip2';
}

public function useExtension(): string
{
return 'bz2';
}
}
46 changes: 8 additions & 38 deletions src/Databases/MongoDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@

class MongoDb extends DbDumper
{
protected $port = 27017;
protected int $port = 27017;

/** @var null|string */
protected $collection = null;
protected ?string $collection = null;

/** @var null|string */
protected $authenticationDatabase = null;
protected ?string $authenticationDatabase = null;

/**
* Dump the contents of the database to the given file.
*
* @param string $dumpFile
*
* @throws \Spatie\DbDumper\Exceptions\CannotStartDump
* @throws \Spatie\DbDumper\Exceptions\DumpFailed
*/
public function dumpToFile(string $dumpFile)
public function dumpToFile(string $dumpFile): void
{
$this->guardAgainstIncompleteCredentials();

Expand All @@ -39,9 +29,10 @@ public function dumpToFile(string $dumpFile)
* Verifies if the dbname and host options are set.
*
* @throws \Spatie\DbDumper\Exceptions\CannotStartDump
*
* @return void
*/
public function guardAgainstIncompleteCredentials()
public function guardAgainstIncompleteCredentials(): void
{
foreach (['dbName', 'host'] as $requiredProperty) {
if (strlen($this->$requiredProperty) === 0) {
Expand All @@ -50,37 +41,20 @@ public function guardAgainstIncompleteCredentials()
}
}

/**
* @param string $collection
*
* @return \Spatie\DbDumper\Databases\MongoDb
*/
public function setCollection(string $collection)
public function setCollection(string $collection): self
{
$this->collection = $collection;

return $this;
}

/**
* @param string $authenticationDatabase
*
* @return \Spatie\DbDumper\Databases\MongoDb
*/
public function setAuthenticationDatabase(string $authenticationDatabase)
public function setAuthenticationDatabase(string $authenticationDatabase): self
{
$this->authenticationDatabase = $authenticationDatabase;

return $this;
}

/**
* Generate the dump command for MongoDb.
*
* @param string $filename
*
* @return string
*/
public function getDumpCommand(string $filename): string
{
$quote = $this->determineQuote();
Expand Down Expand Up @@ -118,10 +92,6 @@ public function getDumpCommand(string $filename): string
return $this->echoToFile(implode(' ', $command), $filename);
}

/**
* @param string $dumpFile
* @return Process
*/
public function getProcess(string $dumpFile): Process
{
$command = $this->getDumpCommand($dumpFile);
Expand Down
Loading

0 comments on commit 9b00348

Please sign in to comment.