Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix/timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 5, 2023
2 parents ad55e5e + cc73de9 commit 922852c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 24 deletions.
42 changes: 39 additions & 3 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function compress(CompressionAlgorithm $compressionAlgorithm): ?string

try {
if (CompressionAlgorithm::NONE === $compressionAlgorithm) {
$this->getPhar()->decompressFiles();
$this->phar->decompressFiles();
} else {
$this->phar->compressFiles($compressionAlgorithm->value);
}
Expand Down Expand Up @@ -328,11 +328,47 @@ public function addFile(string $file, ?string $contents = null, bool $binary = f
return $local;
}

/**
* @internal
*/
public function getPhar(): Phar
{
return $this->phar;
}

public function setAlias(string $alias): void
{
$aliasWasAdded = $this->phar->setAlias($alias);

Assert::true(
$aliasWasAdded,
sprintf(
'The alias "%s" is invalid. See Phar::setAlias() documentation for more information.',
$alias,
),
);
}

public function setStub(string $stub): void
{
$this->phar->setStub($stub);
}

public function setDefaultStub(string $main): void
{
$this->phar->setDefaultStub($main);
}

public function setMetadata(mixed $metadata): void
{
$this->phar->setMetadata($metadata);
}

public function extractTo(string $directory, bool $overwrite = false): void
{
$this->phar->extractTo($directory, overwrite: $overwrite);
}

public function signWithTimestamps(
DateTimeImmutable $timestamp,
SigningAlgorithm $signingAlgorithm
Expand Down Expand Up @@ -360,7 +396,7 @@ public function signWithTimestamps(
*/
public function signUsingFile(string $file, ?string $password = null): void
{
$this->signWithPrivateKey(FS::getFileContents($file), $password);
$this->signUsingKey(FS::getFileContents($file), $password);
}

/**
Expand All @@ -369,7 +405,7 @@ public function signUsingFile(string $file, ?string $password = null): void
* @param string $key The private key
* @param null|string $password The private key password
*/
public function signWithPrivateKey(string $key, ?string $password): void
public function signUsingKey(string $key, ?string $password): void
{
$pubKey = $this->pharFilePath.'.pubkey';

Expand Down
24 changes: 6 additions & 18 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Filesystem\Path;
use Webmozart\Assert\Assert;
use function array_map;
use function array_shift;
use function count;
Expand Down Expand Up @@ -283,7 +282,7 @@ private function createPhar(
self::checkComposerFiles($box, $config, $logger);

if ($debug) {
$box->getPhar()->extractTo(self::DEBUG_DIR, null, true);
$box->extractTo(self::DEBUG_DIR, true);
}

self::configureCompressionAlgorithm(
Expand Down Expand Up @@ -602,7 +601,7 @@ private static function registerStub(

$stub = self::createStub($config, $main, $checkRequirements, $logger);

$box->getPhar()->setStub($stub);
$box->setStub($stub);

return;
}
Expand All @@ -621,17 +620,8 @@ private static function registerStub(
return;
}

$aliasWasAdded = $box->getPhar()->setAlias($config->getAlias());

Assert::true(
$aliasWasAdded,
sprintf(
'The alias "%s" is invalid. See Phar::setAlias() documentation for more information.',
$config->getAlias(),
),
);

$box->getPhar()->setDefaultStub($main);
$box->setAlias($config->getAlias());
$box->setDefaultStub($main);

$logger->log(
CompilerLogger::QUESTION_MARK_PREFIX,
Expand All @@ -656,7 +646,7 @@ private static function configureMetadata(Configuration $config, Box $box, Compi
is_string($metadata) ? $metadata : var_export($metadata, true),
);

$box->getPhar()->setMetadata($metadata);
$box->setMetadata($metadata);
}
}

Expand Down Expand Up @@ -785,9 +775,7 @@ private static function signPhar(
$key = $config->getPrivateKeyPath();

if (null === $key) {
$box->getPhar()->setSignatureAlgorithm(
$config->getSigningAlgorithm()->value,
);
$box->sign($config->getSigningAlgorithm());

return;
}
Expand Down
6 changes: 3 additions & 3 deletions tests/BoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ public function test_it_can_sign_the_phar(): void

$this->configureHelloWorldPhar();

$this->box->signWithPrivateKey($key, $password);
$this->box->signUsingKey($key, $password);

self::assertNotSame([], $phar->getSignature(), 'Expected the PHAR to be signed.');
self::assertIsString($phar->getSignature()['hash'], 'Expected the PHAR signature hash to be a string.');
Expand All @@ -1462,7 +1462,7 @@ public function test_it_cannot_sign_if_cannot_get_the_private_key(): void
$this->configureHelloWorldPhar();

try {
$this->box->signWithPrivateKey($key, $password);
$this->box->signUsingKey($key, $password);

self::fail('Expected exception to be thrown.');
} catch (InvalidArgumentException $exception) {
Expand All @@ -1482,7 +1482,7 @@ public function test_it_cannot_sign_if_cannot_create_the_public_key(): void
$this->configureHelloWorldPhar();

try {
$this->box->signWithPrivateKey($key, $password);
$this->box->signUsingKey($key, $password);

self::fail('Expected exception to be thrown.');
} catch (InvalidArgumentException $exception) {
Expand Down

0 comments on commit 922852c

Please sign in to comment.