Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review some parameters #89

Merged
merged 4 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 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
- No longer accept `number` for `algorithm`
- No longer accept `integer` for `compression`


## From box2 to 3.0.0-alpha.0

Migration path from [`kherge/box`][box2] to `humbug/box ^3.0`.
Expand Down Expand Up @@ -39,7 +48,7 @@ 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


<br />
Expand Down
83 changes: 43 additions & 40 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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": "?",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.


<br />
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)



Expand Down
14 changes: 7 additions & 7 deletions res/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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"
Expand All @@ -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"]
}
}
}
30 changes: 8 additions & 22 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down Expand Up @@ -879,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(
Expand Down Expand Up @@ -1254,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
Expand Down
20 changes: 0 additions & 20 deletions tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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([
Expand Down