Skip to content

Commit

Permalink
refactor: Migrate Box FileSystem to Fidry FileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Oct 6, 2023
1 parent fc2c209 commit edc2a20
Show file tree
Hide file tree
Showing 41 changed files with 1,091 additions and 2,688 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"composer/semver": "^3.3.2",
"composer/xdebug-handler": "^3.0.3",
"fidry/console": "^0.5.3",
"fidry/filesystem": "^1.0",
"humbug/php-scoper": "^0.18.3",
"justinrainbow/json-schema": "^5.2.12",
"laravel/serializable-closure": "^1.2.2",
Expand Down Expand Up @@ -68,7 +69,6 @@
"KevinGH\\Box\\": "src"
},
"files": [
"src/FileSystem/file_system.php",
"src/consts.php",
"src/functions.php"
],
Expand Down
71 changes: 70 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Amp\MultiReasonException;
use BadMethodCallException;
use Countable;
use Fidry\FileSystem\FS;
use Humbug\PhpScoper\Symbol\SymbolsRegistry;
use KevinGH\Box\Compactor\Compactors;
use KevinGH\Box\Compactor\PhpScoper;
Expand All @@ -41,11 +42,6 @@
use function file_exists;
use function getcwd;
use function is_object;
use function KevinGH\Box\FileSystem\dump_file;
use function KevinGH\Box\FileSystem\file_contents;
use function KevinGH\Box\FileSystem\make_tmp_dir;
use function KevinGH\Box\FileSystem\mkdir;
use function KevinGH\Box\FileSystem\remove;
use function openssl_pkey_export;
use function openssl_pkey_get_details;
use function openssl_pkey_get_private;
Expand Down Expand Up @@ -92,7 +88,7 @@ public static function create(string $pharFilePath, int $pharFlags = 0, ?string
{
// Ensure the parent directory of the PHAR file exists as `new \Phar()` does not create it and would fail
// otherwise.
mkdir(dirname($pharFilePath));
FS::mkdir(dirname($pharFilePath));

return new self(
new Phar($pharFilePath, $pharFlags, $pharAlias),
Expand Down Expand Up @@ -127,7 +123,7 @@ public function endBuffering(?callable $dumpAutoload): void
$dumpAutoload ??= static fn () => null;
$cwd = getcwd();

$tmp = make_tmp_dir('box', self::class);
$tmp = FS::makeTmpDir('box', self::class);
chdir($tmp);

if ([] === $this->bufferedFiles) {
Expand All @@ -138,7 +134,7 @@ public function endBuffering(?callable $dumpAutoload): void

try {
foreach ($this->bufferedFiles as $file => $contents) {
dump_file($file, $contents);
FS::dumpFile($file, $contents);
}

if (null !== $dumpAutoload) {
Expand All @@ -152,7 +148,7 @@ public function endBuffering(?callable $dumpAutoload): void

$this->phar->buildFromDirectory($tmp);
} finally {
remove($tmp);
FS::remove($tmp);
}

$this->buffering = false;
Expand Down Expand Up @@ -283,7 +279,7 @@ public function registerStub(string $file): void
{
$contents = $this->placeholderCompactor->compact(
$file,
file_contents($file),
FS::getFileContents($file),
);

$this->phar->setStub($contents);
Expand Down Expand Up @@ -327,7 +323,7 @@ public function addFile(string $file, ?string $contents = null, bool $binary = f
Assert::true($this->buffering, 'Cannot add files if the buffering has not started.');

if (null === $contents) {
$contents = file_contents($file);
$contents = FS::getFileContents($file);
}

$local = ($this->mapFile)($file);
Expand All @@ -350,7 +346,7 @@ public function getPhar(): Phar
*/
public function signUsingFile(string $file, ?string $password = null): void
{
$this->sign(file_contents($file), $password);
$this->sign(FS::getFileContents($file), $password);
}

/**
Expand Down Expand Up @@ -383,7 +379,7 @@ public function sign(string $key, ?string $password): void

$this->phar->setSignatureAlgorithm(Phar::OPENSSL, $private);

dump_file($pubKey, $details['key']);
FS::dumpFile($pubKey, $details['key']);
}

/**
Expand All @@ -410,7 +406,7 @@ private function processContents(array $files): array
\KevinGH\Box\register_error_handler();
}

$contents = file_contents($file);
$contents = \Fidry\FileSystem\FS::getFileContents($file);

$local = $mapFile($file);

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/ComposerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

namespace KevinGH\Box\Composer;

use Symfony\Component\Filesystem\Path;
use function array_column;
use function array_filter;
use function array_key_exists;
use function array_map;
use function KevinGH\Box\FileSystem\make_path_absolute;
use function realpath;
use const DIRECTORY_SEPARATOR;

Expand Down Expand Up @@ -61,7 +61,7 @@ private static function getDevPackagePaths(
array $composerJsonDecodedContents,
array $composerLockDecodedContents,
): array {
$vendorDir = make_path_absolute(
$vendorDir = Path::makeAbsolute(
self::retrieveVendorDir($composerJsonDecodedContents),
$basePath,
);
Expand Down
7 changes: 3 additions & 4 deletions src/Composer/ComposerOrchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use Composer\Semver\Semver;
use Fidry\Console\Input\IO;
use Fidry\FileSystem\FS;
use Humbug\PhpScoper\Autoload\ScoperAutoloadGenerator;
use Humbug\PhpScoper\Symbol\SymbolsRegistry;
use KevinGH\Box\Console\Logger\CompilerLogger;
Expand All @@ -25,8 +26,6 @@
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\ExecutableFinder;
use Symfony\Component\Process\Process;
use function KevinGH\Box\FileSystem\dump_file;
use function KevinGH\Box\FileSystem\file_contents;
use function preg_replace;
use function sprintf;
use function str_replace;
Expand Down Expand Up @@ -121,10 +120,10 @@ public static function dumpAutoload(

$autoloadContents = self::generateAutoloadStatements(
$symbolsRegistry,
file_contents($autoloadFile),
FS::getFileContents($autoloadFile),
);

dump_file($autoloadFile, $autoloadContents);
FS::dumpFile($autoloadFile, $autoloadContents);
}
}

Expand Down
Loading

0 comments on commit edc2a20

Please sign in to comment.