diff --git a/src/Phar/PharInfo.php b/src/Phar/PharInfo.php index 90cf8922e..58a7657fa 100644 --- a/src/Phar/PharInfo.php +++ b/src/Phar/PharInfo.php @@ -237,6 +237,11 @@ public function getNormalizedMetadata(): ?string return $this->meta->normalizedMetadata; } + public function getTimestamp(): int + { + return $this->meta->timestamp; + } + public function getSignature(): ?array { return $this->meta->signature; diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index 1e4967fea..af51a3a4b 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -52,6 +52,7 @@ public function __construct( public readonly ?string $stub, public readonly ?string $version, public readonly ?string $normalizedMetadata, + public readonly int $timestamp, public readonly ?string $pubKeyContent, public readonly array $filesMeta, ) { @@ -64,6 +65,7 @@ public static function fromPhar(Phar|PharData $phar, ?string $pubKeyContent): se $stub = $phar->getStub(); $version = $phar->getVersion(); $metadata = $phar->getMetadata(); + $timestamp = $phar->getMTime(); return new self( false === $compression ? CompressionAlgorithm::NONE : CompressionAlgorithm::from($compression), @@ -72,6 +74,7 @@ public static function fromPhar(Phar|PharData $phar, ?string $pubKeyContent): se '' === $version ? null : $version, // TODO: check $unserializeOptions here null === $metadata ? null : var_export($metadata, true), + $timestamp, $pubKeyContent, self::collectFilesMeta($phar), ); @@ -93,6 +96,7 @@ public static function fromJson(string $json): self $decodedJson['stub'], $decodedJson['version'], $decodedJson['normalizedMetadata'], + $decodedJson['timestamp'], $decodedJson['pubKeyContent'], $filesMeta, ); @@ -106,6 +110,7 @@ public function toJson(): string 'stub' => $this->stub, 'version' => $this->version, 'normalizedMetadata' => $this->normalizedMetadata, + 'timestamp' => $this->timestamp, 'pubKeyContent' => $this->pubKeyContent, 'filesMeta' => $this->filesMeta, ]); diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index efe8787aa..484e609ac 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -84,6 +84,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, + 1559806605, null, [ '.hidden' => [ @@ -128,6 +129,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, + 1559807994, null, [ '.hidden' => [ @@ -160,6 +162,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, + 1374531272, null, [ 'index.php' => [ @@ -187,6 +190,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, + 1374531313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b diff --git a/tests/Phar/PharMetaTest.php b/tests/Phar/PharMetaTest.php index d7afd00fb..7dde21c9a 100644 --- a/tests/Phar/PharMetaTest.php +++ b/tests/Phar/PharMetaTest.php @@ -47,6 +47,7 @@ public static function pharMetaProvider(): iterable null, null, null, + 1509920675, null, [], ), @@ -63,6 +64,7 @@ public static function pharMetaProvider(): iterable 'action' => 'sayHello', ) EOL, + 1509920675, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -121,6 +123,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, + 1680285013, null, [ 'sample.php' => [ @@ -143,6 +146,7 @@ public static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, + 1509920675, null, [ 'foo.php' => [ @@ -165,6 +169,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, + 1680680933, null, [ 'sample.php' => [ @@ -192,6 +197,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, + 1680469485, null, [ 'sample.php' => [ @@ -216,6 +222,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, + 1680469504, null, [ 'sample.php' => [ @@ -239,6 +246,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, + 1374531272, null, [ 'index.php' => [ @@ -261,6 +269,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, + 1374531313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -289,6 +298,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', "'Hello world!'", + 1680366918, null, [ 'sample.php' => [ @@ -311,6 +321,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', '-19.8', + 1680366947, null, [ 'sample.php' => [ @@ -337,6 +348,7 @@ public static function pharProvider(): iterable 'action' => 'sayHello', ) EOL, + 1680367053, null, [ 'sample.php' => [ @@ -356,6 +368,7 @@ public static function pharProvider(): iterable null, null, null, + 1680284754, null, [ 'sample.txt' => [ @@ -376,6 +389,7 @@ public static function pharProvider(): iterable null, null, null, + 1680284663, null, [ 'sample.txt' => [ @@ -397,6 +411,7 @@ public static function pharProvider(): iterable null, null, null, + 1680284660, null, [ 'sample.txt' => [ @@ -418,6 +433,7 @@ public static function pharProvider(): iterable null, null, null, + 1680284663, null, [ 'sample.txt' => [ @@ -441,6 +457,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, + 1680645848, null, [ '.hidden-dir/.hidden-file' => [