From 69c74755ca2a9169c1fe2cdc8df3fed20a519771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 5 Mar 2018 20:12:25 +0000 Subject: [PATCH 1/4] Do not allow strings for compactors --- UPGRADE.md | 7 +++++++ src/Configuration.php | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/UPGRADE.md b/UPGRADE.md index 2ad976138..387a64969 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,10 @@ +## From 3.0.0-alpha.0 to 3.0.0-alpha.1 + +### Backward-compatibility (BC) breaks + +- The option `compactors` no longer accepts a string value + + ## From box2 to 3.0.0-alpha.0 Migration path from [`kherge/box`][box2] to `humbug/box ^3.0`. diff --git a/src/Configuration.php b/src/Configuration.php index 6520c9a6f..8b74cb88c 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -838,7 +838,6 @@ private static function normalizePath(string $file, string $basePath): string */ private static function retrieveCompactors(stdClass $raw, string $basePath): array { - // TODO: only accept arrays when set unlike the doc says (it allows a string). if (false === isset($raw->compactors)) { return []; } From 228d3fba085680e36c69bb70453c2aa56629a3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 5 Mar 2018 21:00:04 +0000 Subject: [PATCH 2/4] Rework doc - Allow `null` for `algorithm` and `compression - Drop support for numerical values for `algorithm` and `compression` --- README.md | 3 ++ UPGRADE.md | 4 ++- doc/configuration.md | 83 ++++++++++++++++++++++--------------------- res/schema.json | 14 ++++---- src/Configuration.php | 29 +++++---------- 5 files changed, 64 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 1f7920889..405abd630 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ great things: 1. [Base path](doc/configuration.md#base-path-base-path) 1. [Output](doc/configuration.md#output-output) 1. [Main](doc/configuration.md#main-main) + 1. [Permissions][doc/configuration.md#permissions-chmod] 1. [Including files](doc/configuration.md#including-files) 1. [Files (`files` and `files-bin`)](doc/configuration.md#files-files-and-files-bin) 1. [Directories (`directories` and `directories-bin`)](doc/configuration.md#directories-directories-and-directories-bin) @@ -52,6 +53,8 @@ great things: 1. [Banner (`banner`)](doc/configuration.md#banner-banner) 1. [Banner file (`banner-file`)](doc/configuration.md#banner-file-banner-file) 1. [Compactors (`compactors`)](doc/configuration.md#compactors-compactors) + 1. [Compression algorithm (`compression`)](doc/configuration.md#compression-algorithm-compression) + 1. [Signing algorithm (`algorithm`)](doc/configuration.md#signing-algorithm-algorithm) 1. [Contributing](#contributing) 1. [Upgrade](#upgrade) 1. [Credits](#credits) diff --git a/UPGRADE.md b/UPGRADE.md index 387a64969..df6b26958 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -46,7 +46,9 @@ Migration path from [`kherge/box`][box2] to `humbug/box ^3.0`. - Make the main script path relative to the base path - Do not allow a config with no file registered - Make main script mandatory (the value, not the setting) -- Exclude symlinks +- Exclude symlinks from the files collected +- No longer accept `number` for `algorithm` +- No longer accept `integer` for `compression`
diff --git a/doc/configuration.md b/doc/configuration.md index f7fc1ad72..be49fc73e 100644 --- a/doc/configuration.md +++ b/doc/configuration.md @@ -3,6 +3,7 @@ 1. [Base path][base-path] 1. [Output][output] 1. [Main][main] +1. [Permissions][permissions] 1. [Including files][including-files] 1. [Files (`files` and `files-bin`)][files] 1. [Directories (`directories` and `directories-bin`)][directories] @@ -15,6 +16,8 @@ 1. [Banner (`banner`)][banner] 1. [Banner file (`banner-file`)][banner-file] 1. [Compactors (`compactors`)][compactors] +1. [Compression algorithm (`compression`)][compression] +1. [Signing algorithm (`algorithm`)][algorithm] // TODO: do not mention when an option is optional but add a red asterix with a foot note for the mandatory @@ -38,7 +41,6 @@ The configuration file is a JSON object saved to a file. Note that all settings "banner-file": "?", "base-path": "?", "blacklist": "?", - "bootstrap": "?", "chmod": "?", "compactors": "?", "compression": "?", @@ -94,6 +96,15 @@ If the main file starts with a shebang line (`#!`), it will be automatically rem [stub][stub] for a PHAR and is configured by the [shebang][shebang] setting). +## Permissions (`chmod`) + +The chmod (`string`|`null`) setting is used to change the file permissions of the newly built PHAR. The string contains +an octal value e.g. `0750`. By default the permissions of the created PHAR are unchanged so it should be `0644`. + +Check the following [link](https://secure.php.net/manual/en/function.chmod.php) for more on the possible values. + + + ## Including files There is two ways to include files. The first one is to not be picky about which files are shipped in the PHAR. If you @@ -364,7 +375,7 @@ If this parameter is set, then the value of [`banner`][banner] will be discarded ## Compactors (`compactors`) -The compactors (`string[]) setting is a list of file contents compacting classes that must be registered. A file +The compactors (`string[]`) setting is a list of file contents compacting classes that must be registered. A file compacting class is used to reduce the size of a specific file type. The following is a simple example: ```php @@ -397,6 +408,30 @@ The following compactors are included with Box: - `KevinGH\Box\Compactor\PhpScoper`: isolate the code using [PhpScoper][phpscoper] +## Compression algorithm (`compression`) + +The compression (`string`|`null`) setting is the compression algorithm to use when the PHAR is built. The compression +affects the individual files within the PHAR and not the PHAR as a whole ([`Phar::compressFiles()`][phar.compress]). The +following is a list of the signature algorithms available: + +- `BZ2` +- `GZ` (the most efficient most of the time) +- `NONE` (default) + + +## Signing algorithm (`algorithm`) + +The algorithm (`string`|`null`) setting is the signing algorithm to use when the PHAR is built ( +[`Phar::setSignatureAlgorithm()`][phar.setsignaturealgorithm]). The following is a list of the signature algorithms +available: + +- `MD5` +- `SHA1` +- `SHA256` +- `SHA512` +- `OPENSSL` + +By default the PHAR is not signed.
@@ -425,32 +460,21 @@ The following compactors are included with Box: [phar.webphar]: https://secure.php.net/manual/en/phar.webphar.php [phar.fileformat.stub]: https://secure.php.net/manual/en/phar.fileformat.stub.php [phar.interceptfilefuncs]: https://secure.php.net/manual/en/phar.interceptfilefuncs.php +[phar.setsignaturealgorithm]: https://secure.php.net/manual/en/phar.setsignaturealgorithm.php +[phar.compress]: https://secure.php.net/manual/en/phar.compress.php [symfony-finder]: https://symfony.com/doc/current//components/finder.html [phpscoper]: https://github.com/humbug/php-scoper [compactors]: #compactors-compactors - -TODO: double check all the links -TODO: for the Finder: - - add tests regarding the note about (key, arguments) - - paths should be relative not only for `in` but the others as well, double check that - -//TODO: rework the rest +[permissions]: #permissions-chmod +[compression]: #compression-algorithm-compression +[algorithm]: #signing-algorithm-algorithm -The (optional) algorithm (string) setting is the signing algorithm to use when -the PHAR is built (Phar::setSignatureAlgorithm()). The following is a list of -the signature algorithms available: -- MD5 (Phar::MD5) -- SHA1 (Phar::SHA1) -- SHA256 (Phar::SHA256) -- SHA512 (Phar::SHA512) -- OPENSSL (Phar::OPENSSL) +//TODO: rework the rest -Further help: -https://secure.php.net/manual/en/phar.setsignaturealgorithm.php The annotations (boolean, object) setting is used to enable compacting @@ -478,30 +502,9 @@ https://github.com/herrera-io/php-annotations -The bootstrap (string) setting allows you to specify a PHP file that will be -loaded before the build or add commands are used. This is useful for loading -third-party file contents compacting classes that were configured using the -compactors setting. - -The chmod (string) setting is used to change the file permissions of the newly -built PHAR. The string contains an octal value: 0750. - -Check the following link for more on the possible values: - -https://secure.php.net/manual/en/function.chmod.php - - - -The compression (string) setting is the compression algorithm to use when the -PHAR is built. The compression affects the individual files within the PHAR, -and not the PHAR as a whole (Phar::compressFiles()). The following is a list -of the signature algorithms listed on the help page: -- BZ2 (Phar::BZ2) -- GZ (Phar::GZ) -- NONE (Phar::NONE) diff --git a/res/schema.json b/res/schema.json index 6e2711be0..831b79dca 100644 --- a/res/schema.json +++ b/res/schema.json @@ -5,7 +5,7 @@ "properties": { "algorithm": { "description": "The algorithm to use for signing the PHAR.", - "type": ["string", "number"] + "type": ["string", "null"] }, "alias": { "description": "The internal PHAR alias used for I/O streams.", @@ -49,7 +49,7 @@ }, "chmod": { "description": "The permission mode for the new PHAR.", - "type": "string" + "type": ["string", "null"] }, "compactors": { "description": "The list of file contents compactor classes to register.", @@ -60,7 +60,7 @@ }, "compression": { "description": "The compression algorithm to use for the PHAR.", - "type": ["string", "number"] + "type": ["string", "null"] }, "datetime": { "description": "The replacement date for the current date and time.", @@ -162,6 +162,10 @@ "description": "The file name or path of the new PHAR.", "type": "string" }, + "php-scoper": { + "description": "Path to the PHP-Scoper configuration file.", + "type": ["string"] + }, "replacement-sigil": { "description": "The sigil that surrounds the replacement names.", "type": "string" @@ -177,10 +181,6 @@ "stub": { "description": "The relative file path to the stub file, or the flag to use the default stub.", "type": ["boolean", "string"] - }, - "php-scoper": { - "description": "Path to the PHP-Scoper configuration file.", - "type": ["string"] } } } diff --git a/src/Configuration.php b/src/Configuration.php index 8b74cb88c..f7b671020 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -878,15 +878,6 @@ private static function retrieveCompressionAlgorithm(stdClass $raw): ?int return null; } - if (false === is_string($raw->compression)) { - Assertion::integer( - $raw->compression, - 'Expected compression to be an algorithm name, found %s instead.' - ); - - return $raw->compression; - } - $knownAlgorithmNames = array_keys(get_phar_compression_algorithms()); Assertion::inArray( @@ -1253,20 +1244,16 @@ private static function retrieveSigningAlgorithm(stdClass $raw): int return Phar::SHA1; } - if (is_string($raw->algorithm)) { - if (false === defined('Phar::'.$raw->algorithm)) { - throw new InvalidArgumentException( - sprintf( - 'The signing algorithm "%s" is not supported.', - $raw->algorithm - ) - ); - } - - return constant('Phar::'.$raw->algorithm); + if (false === defined('Phar::'.$raw->algorithm)) { + throw new InvalidArgumentException( + sprintf( + 'The signing algorithm "%s" is not supported.', + $raw->algorithm + ) + ); } - return $raw->algorithm; + return constant('Phar::'.$raw->algorithm); } private static function retrieveStubBannerContents(stdClass $raw): ?string From 5ec1c74aebe52cdd756625d32ea4baebf59baf0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 5 Mar 2018 21:04:38 +0000 Subject: [PATCH 3/4] Fix tests --- tests/ConfigurationTest.php | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/tests/ConfigurationTest.php b/tests/ConfigurationTest.php index b624b8df5..3c28e83e8 100644 --- a/tests/ConfigurationTest.php +++ b/tests/ConfigurationTest.php @@ -1831,16 +1831,6 @@ public function test_no_compression_algorithm_is_configured_by_default(): void $this->assertNull($this->getNoFileConfig()->getCompressionAlgorithm()); } - public function test_the_compression_algorithm_can_be_configured(): void - { - $this->setConfig([ - 'files' => [self::DEFAULT_FILE], - 'compression' => Phar::BZ2, - ]); - - $this->assertSame(Phar::BZ2, $this->config->getCompressionAlgorithm()); - } - public function test_the_compression_algorithm_with_a_string(): void { $this->setConfig([ @@ -2303,16 +2293,6 @@ public function testGetSigningAlgorithm(): void $this->assertSame(Phar::SHA1, $this->config->getSigningAlgorithm()); } - public function testGetSigningAlgorithmSet(): void - { - $this->setConfig([ - 'algorithm' => Phar::MD5, - 'files' => [self::DEFAULT_FILE], - ]); - - $this->assertSame(Phar::MD5, $this->config->getSigningAlgorithm()); - } - public function testGetSigningAlgorithmSetString(): void { $this->setConfig([ From c9037bb3724d29f049c90db95fccf0f5a5776e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Mon, 5 Mar 2018 21:06:09 +0000 Subject: [PATCH 4/4] fix --- UPGRADE.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index df6b26958..242e2c4f7 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -3,6 +3,8 @@ ### Backward-compatibility (BC) breaks - The option `compactors` no longer accepts a string value +- No longer accept `number` for `algorithm` +- No longer accept `integer` for `compression` ## From box2 to 3.0.0-alpha.0 @@ -47,8 +49,6 @@ Migration path from [`kherge/box`][box2] to `humbug/box ^3.0`. - Do not allow a config with no file registered - Make main script mandatory (the value, not the setting) - Exclude symlinks from the files collected -- No longer accept `number` for `algorithm` -- No longer accept `integer` for `compression`