Skip to content

Commit

Permalink
Rework default values (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored May 31, 2018
1 parent ac0b91b commit e831cb5
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 121 deletions.
163 changes: 83 additions & 80 deletions doc/configuration.md

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions res/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
},
"alias": {
"description": "The internal PHAR alias used for I/O streams.",
"type": "string"
"type": ["string", "null"]
},
"annotations": {
"description": "The PHP annotation compactor settings.",
"type": ["boolean", "object"],
"type": ["boolean", "object", "null"],
"properties": {
"ignore": {
"description": "A list of annotation names to ignore.",
Expand All @@ -26,11 +26,11 @@
},
"banner": {
"description": "The header comment for the generated stub.",
"type": ["array", "string", "null"]
"type": ["array", "boolean", "string", "null"]
},
"banner-file": {
"description": "The header comment file for the generated stub.",
"type": "string"
"type": ["string", "null"]
},
"base-path": {
"description": "The base path where relative paths are resolved to.",
Expand All @@ -41,11 +41,11 @@
"items": {
"type": "string"
},
"type": ["array"]
"type": ["array", "null"]
},
"check-requirements": {
"description": "If enabled, the PHAR will be able to check if the PHP environment used meets all the requirements to run the application.",
"type": ["boolean"]
"type": ["boolean", "null"]
},
"chmod": {
"description": "The permission mode for the new PHAR.",
Expand All @@ -56,7 +56,7 @@
"items": {
"type": "string"
},
"type": ["array", "string"]
"type": ["array", "string", "null"]
},
"compression": {
"description": "The compression algorithm to use for the PHAR.",
Expand All @@ -79,14 +79,14 @@
"items": {
"type": "string"
},
"type": ["array"]
"type": ["array", "null"]
},
"directories-bin": {
"description": "A list of directory paths to search for binary safe files.",
"items": {
"type": "string"
},
"type": ["array"]
"type": ["array", "null"]
},
"dump-autoload": {
"description": "Will dump the optimized Composer autoloader.",
Expand All @@ -101,68 +101,68 @@
"items": {
"type": "string"
},
"type": ["array"]
"type": ["array", "null"]
},
"files-bin": {
"description": "A list of binary safe file paths to include.",
"items": {
"type": "string"
},
"type": ["array"]
"type": ["array", "null"]
},
"finder": {
"description": "A list of Finder configuration settings.",
"items": {
"type": "object"
},
"type": "array"
"type": ["array", "null"]
},
"finder-bin": {
"description": "A list of Finder configuration settings for binary safe files.",
"items": {
"type": "object"
},
"type": "array"
"type": ["array", "null"]
},
"git": {
"description": "The replacement name for the current pretty git version format.",
"type": "string"
"type": ["string", "null"]
},
"git-commit": {
"description": "The replacement name for the current git full commit hash.",
"type": "string"
"type": ["string", "null"]
},
"git-commit-short": {
"description": "The replacement name for the current git short commit hash.",
"type": "string"
"type": ["string", "null"]
},
"git-tag": {
"description": "The replacement name for the current git tag.",
"type": "string"
"type": ["string", "null"]
},
"git-version": {
"description": "The replacement name for the current git tag or commit hash.",
"type": "string"
"type": ["string", "null"]
},
"intercept": {
"description": "Allow the PHAR to intercept file functions?",
"type": "boolean"
"type": ["boolean", "null"]
},
"key": {
"description": "The path to the private key used for signing.",
"type": "string"
"type": ["string", "null"]
},
"key-pass": {
"description": "The password or prompt flag used for the private key.",
"type": ["boolean", "string"]
"type": ["boolean", "string", "null"]
},
"main": {
"description": "The file path to the main script.",
"type": ["boolean", "string"]
"type": ["boolean", "string", "null"]
},
"map": {
"description": "The mapping of file system paths to phar paths.",
"type": "array",
"type": ["array", "null"],
"items": {
"type": "object"
}
Expand All @@ -172,27 +172,27 @@
},
"output": {
"description": "The file name or path of the new PHAR.",
"type": "string"
"type": ["string", "null"]
},
"php-scoper": {
"description": "Path to the PHP-Scoper configuration file.",
"type": ["string"]
"type": ["string", "null"]
},
"replacement-sigil": {
"description": "The sigil that surrounds the replacement names.",
"type": ["string", "null"]
},
"replacements": {
"description": "A list of replacement names and their values.",
"type": "object"
"type": ["object", "null"]
},
"shebang": {
"description": "The shebang line to use for the generated stub.",
"type": ["string", "null"]
"type": ["string", "boolean", "null"]
},
"stub": {
"description": "The relative file path to the stub file, or the flag to use the default stub.",
"type": ["boolean", "string"]
"type": ["boolean", "string", "null"]
}
}
}
23 changes: 17 additions & 6 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use function is_file;
use function is_link;
use function is_readable;
use function is_string;
use function iter\fn\method;
use function iter\map;
use function iter\toArray;
Expand Down Expand Up @@ -369,7 +370,7 @@ public static function create(?string $file, stdClass $raw): self
);
}

public function getFile(): ?string
public function getConfigurationFile(): ?string
{
return $this->file;
}
Expand Down Expand Up @@ -1717,11 +1718,19 @@ private static function retrieveShebang(stdClass $raw): ?string
return self::DEFAULT_SHEBANG;
}

if (null === $raw->shebang) {
$shebang = $raw->shebang;

if (false === $shebang) {
return null;
}

$shebang = trim($raw->shebang);
if (null === $shebang) {
$shebang = self::DEFAULT_SHEBANG;
}

Assertion::string($shebang, 'Expected shebang to be either a string, false or null, found true');

$shebang = trim($shebang);

Assertion::notEmpty($shebang, 'The shebang should not be empty.');
Assertion::true(
Expand Down Expand Up @@ -1758,15 +1767,17 @@ private static function retrieveSigningAlgorithm(stdClass $raw): int

private static function retrieveStubBannerContents(stdClass $raw): ?string
{
if (false === array_key_exists('banner', (array) $raw)) {
if (false === array_key_exists('banner', (array) $raw) || null === $raw->banner) {
return self::DEFAULT_BANNER;
}

if (null === $raw->banner) {
$banner = $raw->banner;

if (false === $banner) {
return null;
}

$banner = $raw->banner;
Assertion::true(is_string($banner) || is_array($banner), 'The banner cannot accept true as a value');

if (is_array($banner)) {
$banner = implode("\n", $banner);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function removeExistingArtifacts(Configuration $config, BuildLogger $log
remove(self::DEBUG_DIR);

$date = (new DateTimeImmutable('now', new DateTimeZone('UTC')))->format(DATE_ATOM);
$file = null !== $config->getFile() ? $config->getFile() : 'No config file';
$file = null !== $config->getConfigurationFile() ? $config->getConfigurationFile() : 'No config file';

remove(self::DEBUG_DIR);

Expand Down
Loading

0 comments on commit e831cb5

Please sign in to comment.