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

refactor: Move the dumped PHAR meta JSON to .phar #1110

Merged
merged 1 commit into from
Oct 22, 2023
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
2 changes: 1 addition & 1 deletion requirement-checker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ $(PHAR): $(PHAR_SRC_FILES) $(BOX_BIN) $(PHAR_PREFIX)

$(PHAR_EXTRACT): $(PHAR) $(BOX_BIN)
$(BOX) extract $(PHAR) $(PHAR_EXTRACT)
rm -rf $(PHAR_EXTRACT)/.phar_meta.json
rm -rf $(PHAR_EXTRACT)/.phar
touch -c $@

$(BOX_BIN):
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
final class Extract implements Command
{
public const STUB_PATH = '.phar/stub.php';
public const PHAR_META_PATH = '.phar_meta.json';
public const PHAR_META_PATH = '.phar/meta.json';

private const PHAR_ARG = 'phar';
private const OUTPUT_ARG = 'output';
Expand Down
9 changes: 7 additions & 2 deletions src/Console/PharInfoRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,14 @@ public static function renderShortSummary(
self::renderContentsSummary(...),
];

foreach ($methods as $method) {
$lastIndex = count($methods) - 1;

foreach ($methods as $index => $method) {
$method($pharInfo, $io);
$separator();

if ($index !== $lastIndex) {
$separator();
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Phar/PharInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
use function iter\toArrayWithKeys;
use function random_bytes;
use function sprintf;
use const DIRECTORY_SEPARATOR;

/**
* @private
Expand Down Expand Up @@ -321,7 +322,7 @@ private static function loadDumpedPharFiles(string $tmp): array
),
);

$meta = PharMeta::fromJson($dumpedFiles[Extract::PHAR_META_PATH]->getContents());
$meta = PharMeta::fromJson(FS::getFileContents($tmp.DIRECTORY_SEPARATOR.Extract::PHAR_META_PATH));
unset($dumpedFiles[Extract::PHAR_META_PATH]);

return [$meta, $dumpedFiles];
Expand Down
4 changes: 2 additions & 2 deletions tests/Console/Command/DiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ public static function GNUDiffPharsProvider(): iterable
// Comparing the two archives contents (gnu diff)...

Common subdirectories: simple-phar-bar.phar/.phar and simple-phar-baz.phar/.phar
diff --exclude=.phar_meta.json simple-phar-bar.phar/bar.php simple-phar-baz.phar/bar.php
diff --exclude=.phar/meta.json simple-phar-bar.phar/bar.php simple-phar-baz.phar/bar.php
3c3
< echo "Hello world!";
---
Expand Down Expand Up @@ -770,7 +770,7 @@ public static function GNUDiffPharsProvider(): iterable
// Comparing the two archives contents (gnu diff)...

Common subdirectories: simple-phar-bar.phar/.phar and simple-phar-baz.phar/.phar
diff '--exclude=.phar_meta.json' simple-phar-bar.phar/bar.php simple-phar-baz.phar/bar.php
diff '--exclude=.phar/meta.json' simple-phar-bar.phar/bar.php simple-phar-baz.phar/bar.php
3c3
< echo "Hello world!";
---
Expand Down
28 changes: 14 additions & 14 deletions tests/Console/Command/ExtractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ private static function pharProvider(): iterable
);

$expectedSimplePharFiles = [
'.phar/meta.json' => $pharMeta->toJson(),
'.phar/stub.php' => $oldDefaultPharStub,
'.hidden' => 'baz',
'foo' => 'bar',
'.phar_meta.json' => $pharMeta->toJson(),
];

yield 'simple PHAR' => [
Expand All @@ -122,7 +122,7 @@ private static function pharProvider(): iterable
'.phar/stub.php' => $oldDefaultPharStub,
'.hidden' => 'baz',
'foo' => 'bar',
'.phar_meta.json' => (new PharMeta(
'.phar/meta.json' => (new PharMeta(
CompressionAlgorithm::NONE,
[
'hash' => '3CCDA01B80C1CAC91494EA59BBAFA479E38CD120',
Expand Down Expand Up @@ -151,12 +151,7 @@ private static function pharProvider(): iterable
yield 'sha512 signed PHAR' => [
self::FIXTURES_DIR.'/sha512.phar',
[
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

PHP,
'.phar_meta.json' => (new PharMeta(
'.phar/meta.json' => (new PharMeta(
CompressionAlgorithm::NONE,
[
'hash' => 'B4CAE177138A773283A748C8770A7142F0CC36D6EE88E37900BCF09A92D840D237CE3F3B47C2C7B39AC2D2C0F9A16D63FE70E1A455723DD36840B6E2E64E2130',
Expand All @@ -174,18 +169,18 @@ private static function pharProvider(): iterable
],
],
))->toJson(),
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

PHP,
],
];

yield 'OpenSSL signed PHAR' => [
self::FIXTURES_DIR.'/openssl.phar',
[
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

PHP,
'.phar_meta.json' => (new PharMeta(
'.phar/meta.json' => (new PharMeta(
CompressionAlgorithm::NONE,
[
'hash' => '54AF1D4E5459D3A77B692E46FDB9C965D1C7579BD1F2AD2BECF4973677575444FE21E104B7655BA3D088090C28DF63D14876B277C423C8BFBCDB9E3E63F9D61A',
Expand All @@ -209,6 +204,11 @@ private static function pharProvider(): iterable
],
],
))->toJson(),
'.phar/stub.php' => $sha512Stub,
'index.php' => <<<'PHP'
<?php echo "Hello, world!\n";

PHP,
],
];
}
Expand Down
Loading