-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add back the old PharInfo (#1067)
- Loading branch information
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\PharInfo; | ||
|
||
use KevinGH\Box\Phar\PharInfo as NewPharInfo; | ||
use Phar; | ||
use PharData; | ||
use UnexpectedValueException; | ||
use function KevinGH\Box\unique_id; | ||
use function realpath; | ||
use function str_replace; | ||
|
||
/** | ||
* @deprecated Deprecated since 4.4.1 in favour of \KevinGH\Box\Phar\PharInfo. | ||
*/ | ||
final class PharInfo | ||
{ | ||
private NewPharInfo $decoratedPharInfo; | ||
|
||
private PharData|Phar $phar; | ||
|
||
public function __construct(private readonly string $pharFile) | ||
{ | ||
$this->decoratedPharInfo = new NewPharInfo($pharFile); | ||
} | ||
|
||
public function equals(self $pharInfo): bool | ||
{ | ||
return $this->decoratedPharInfo->equals($pharInfo->decoratedPharInfo); | ||
} | ||
|
||
public function getCompressionCount(): array | ||
{ | ||
return $this->decoratedPharInfo->getFilesCompressionCount(); | ||
} | ||
|
||
public function getPhar(): Phar|PharData | ||
{ | ||
if (!isset($this->phar)) { | ||
try { | ||
$this->phar = new Phar($this->pharFile); | ||
} catch (UnexpectedValueException) { | ||
$this->phar = new PharData($this->pharFile); | ||
} | ||
} | ||
|
||
return $this->phar; | ||
} | ||
|
||
public function getRoot(): string | ||
{ | ||
// Do not cache the result | ||
return 'phar://'.str_replace('\\', '/', realpath($this->phar->getPath())).'/'; | ||
} | ||
|
||
public function getVersion(): string | ||
{ | ||
return $this->decoratedPharInfo->getVersion(); | ||
} | ||
|
||
public function getNormalizedMetadata(): ?string | ||
{ | ||
return $this->decoratedPharInfo->getNormalizedMetadata(); | ||
} | ||
|
||
private function getPharHash(): string | ||
{ | ||
return $this->decoratedPharInfo->getSignature()['hash'] ?? unique_id(''); | ||
} | ||
} |