Skip to content

Commit

Permalink
Refactor Library
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Nov 25, 2022
1 parent b79f14b commit 7b80980
Show file tree
Hide file tree
Showing 63 changed files with 2,739 additions and 2,398 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/part_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["7.4", "8.0", "8.1"]
php: ["8.2"]
os: [ubuntu-latest]
experimental: [false]
include:
- php: nightly
os: ubuntu-latest
experimental: true
- php: "8.1"
- php: "8.2"
os: windows-latest
experimental: false
# Not running on MacOS since it currently doesn't stop
# - php: 8.1
# os: macos-latest
# experimental: false
- php: 8.2
os: macos-latest
experimental: false

steps:
- name: Checkout Code
Expand Down Expand Up @@ -99,7 +98,7 @@ jobs:
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.2"
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -131,7 +130,7 @@ jobs:
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.2"
- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
Expand Down
109 changes: 59 additions & 50 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

/**
* PHP-CS-Fixer config for ZipStream-PHP
* @author Nicolas CARPi <nico-git@deltablot.email>
Expand All @@ -8,55 +11,61 @@
* @package maennchen/ZipStream-PHP
*/

$finder = PhpCsFixer\Finder::create()
->name('/\.php|\.php.dist$/')
->in(['src', 'test'])
;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$config = new PhpCsFixer\Config();
$finder = Finder::create()
->exclude('.github')
->exclude('.phpdoc')
->exclude('docs')
->exclude('tools')
->exclude('vendor')
->in(__DIR__);

return $config->setRules(array(
'@PSR2' => true,
'@PHP71Migration' => true,
'array_syntax' => ['syntax' => 'short'],
'class_attributes_separation' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'is_null' => true,
'no_homoglyph_names' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'non_printable_character' => true,
'ordered_imports' => true,
'ordered_class_elements' => true,
'php_unit_construct' => true,
'pow_to_exponentiation' => true,
'psr_autoloading' => true,
'random_api_migration' => true,
'return_assignment' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => true,
'import_constants' => true,
],
))
$config = new Config();
return $config->setRules([
'@PER' => true,
'@PER:risky' => true,
'@PHP82Migration' => true,
'@PHPUnit84Migration:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'class_attributes_separation' => true,
'declare_strict_types' => true,
'dir_constant' => true,
'is_null' => true,
'no_homoglyph_names' => true,
'no_null_property_initialization' => true,
'no_php4_constructor' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'non_printable_character' => true,
'ordered_imports' => true,
'ordered_class_elements' => true,
'php_unit_construct' => true,
'pow_to_exponentiation' => true,
'psr_autoloading' => true,
'random_api_migration' => true,
'return_assignment' => true,
'self_accessor' => true,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => true,
'single_blank_line_before_namespace' => true,
'single_class_element_per_statement' => true,
'single_line_comment_style' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_functions' => true,
'import_constants' => true,
],
])
->setFinder($finder)
->setRiskyAllowed(true)
;
->setRiskyAllowed(true);
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
php 8.1.13
php 8.2.0beta3
82 changes: 61 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ version.

## Overview

A fast and simple streaming zip file downloader for PHP. Using this library will save you from having to write the Zip to disk. You can directly send it to the user, which is much faster. It can work with S3 buckets or any PSR7 Stream.
A fast and simple streaming zip file downloader for PHP. Using this library will
save you from having to write the Zip to disk. You can directly send it to the
user, which is much faster. It can work with S3 buckets or any PSR7 Stream.

Please see the [LICENSE](LICENSE) file for licensing and warranty information.

## Installation

Simply add a dependency on maennchen/zipstream-php to your project's composer.json file if you use Composer to manage the dependencies of your project. Use following command to add the package to your project's dependencies:
Simply add a dependency on maennchen/zipstream-php to your project's
`composer.json` file if you use Composer to manage the dependencies of your
project. Use following command to add the package to your project's dependencies:

```bash
composer require maennchen/zipstream-php
Expand All @@ -29,45 +33,81 @@ composer require maennchen/zipstream-php
## Usage

For detailed instructions, please check the
[Documentation](https://maennchen.dev/ZipStream-PHP/).

Here's a simple example:
[Documentation](https://maennchen.github.io/ZipStream-PHP/).

```php
// Autoload the dependencies
require 'vendor/autoload.php';

// enable output of HTTP headers
$options = new ZipStream\Option\Archive();
$options->setSendHttpHeaders(true);

// create a new zipstream object
$zip = new ZipStream\ZipStream('example.zip', $options);
$zip = new ZipStream\ZipStream(
fileName: 'example.zip',

// enable output of HTTP headers
sendHttpHeaders: true,
);

// create a file named 'hello.txt'
$zip->addFile('hello.txt', 'This is the contents of hello.txt');
$zip->addFile(
fileName: 'hello.txt',
data: 'This is the contents of hello.txt',
);

// add a file named 'some_image.jpg' from a local file 'path/to/image.jpg'
$zip->addFileFromPath('some_image.jpg', 'path/to/image.jpg');
$zip->addFileFromPath(
fileName: 'some_image.jpg',
path: 'path/to/image.jpg',
);

// finish the zip stream
$zip->finish();
```

## Upgrade to version 3.0.0

### General

- Minimum PHP Version: `8.2`
- Only 64bit Architecture is supported.
- The class `ZipStream\Option\Method` has been replaced with the enum `ZipStream\CompressionMethod`.
- Most clases have been flagged as `@internal` and should not be used from the outside.
If you're using internal resources to extend this library, please open an issue so that a clean
interface can be added & published.
The externally available classes & enums are:
- `ZipStream\CompressionMethod`
- `ZipStream\Exception*`
- `ZipStream\ZipStream`

### Archive Options

- The class `ZipStream\Option\Archive` has been replaced in favor of named arguments in the
`ZipStream\ZipStream` constuctor.
- The archive options `largeFileSize` & `largeFileMethod` has been removed. If you want different
`compressionMethods` based on the file size, you'll have to implement this yourself.
- The archive option `httpHeaderCallback` changed the type from `callable` to `Closure`.
- The archive option `zeroHeader` has been replaced with the option `defaultEnableZeroHeader`
and can be overridden for every file.
- The archive option `statFiles` was removed since the library no longer checks filesizes this way.
- The archive option `deflateLevel` has been replaced with the option `defaultDeflateLevel`
and can be overridden for every file.
- The first argument (`name`) of the `ZipStream\ZipStream` constuctor has been replaced with
the named argument `outputName`.

### File Options

- The class `ZipStream\Option\File` has been replaced in favor of named arguments in the
`ZipStream\ZipStream->addFile*` functions.
- The file option `method` has been renamed to `compressionMethod`.
- The file option `time` has been renamed to `lastModificationDateTime`.
- The file option `size` has been renamed to `maxSize`.

## Upgrade to version 2.0.0

- Only the self opened streams will be closed (#139)
If you were relying on ZipStream to close streams that the library didn't open,
you'll need to close them yourself now.
https://github.com/maennchen/ZipStream-PHP/tree/2.0.0#upgrade-to-version-200

## Upgrade to version 1.0.0

- All options parameters to all function have been moved from an `array` to structured option objects. See [the wiki](https://github.com/maennchen/ZipStream-PHP/wiki/Available-options) for examples.
- The whole library has been refactored. The minimal PHP requirement has been raised to PHP 7.1.

## Usage with Symfony and S3

You can find example code on [the wiki](https://github.com/maennchen/ZipStream-PHP/wiki/Symfony-example).
https://github.com/maennchen/ZipStream-PHP/tree/2.0.0#upgrade-to-version-100

## Contributing

Expand Down
32 changes: 18 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,39 @@
}
],
"require": {
"php": "^7.4 || ^8.0",
"php-64bit": "^8.2",
"symfony/polyfill-mbstring": "^1.0",
"psr/http-message": "^1.0",
"myclabs/php-enum": "^1.5"
"psr/http-message": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5.8 || ^9.4.2",
"guzzlehttp/guzzle": "^6.5.3 || ^7.2.0",
"phpunit/phpunit": "^9.5",
"guzzlehttp/guzzle": "^7.5",
"ext-zip": "*",
"mikey179/vfsstream": "^1.6",
"vimeo/psalm": "^4.1",
"php-coveralls/php-coveralls": "^2.4",
"friendsofphp/php-cs-fixer": "^3.9"
"php-coveralls/php-coveralls": "^2.5",
"friendsofphp/php-cs-fixer": "^3.13",
"vimeo/psalm": "^4.30"
},
"autoload": {
"psr-4": {
"ZipStream\\": "src/"
}
},
"autoload-dev": {
"psr-4": { "ZipStream\\Test\\": "test/" }
},
"scripts": {
"format": "php-cs-fixer fix",
"format": "PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix",
"test": "composer run test:unit && composer run test:formatted && composer run test:lint",
"test:unit": "phpunit --coverage-clover=coverage.clover.xml",
"test:unit:slow": "composer run test:unit -- --group slow",
"test:unit:fast": "composer run test:unit -- --exclude-group slow",
"test:formatted": "composer run format -- --dry-run --stop-on-violation --using-cache=no",
"test:lint": "psalm --stats --show-info --find-unused-psalm-suppress",
"coverage:report": "php-coveralls --coverage_clover=coverage.clover.xml --json_path=coveralls-upload.json -v",
"install:tools": "phive install --trust-gpg-keys 0x67F861C3D889C656",
"docs:generate": "tools/phpdocumentor"
},
"autoload": {
"psr-4": {
"ZipStream\\": "src/"
}
},
"archive": {
"exclude": [
"/composer.lock",
Expand Down

0 comments on commit 7b80980

Please sign in to comment.