Skip to content

Commit

Permalink
PluginConfiguration, TranslatablePackageFactory // ensure that direct…
Browse files Browse the repository at this point in the history
…ory separator is correctly trimmed on end of directory input.

Plugin // changed Plugin::ensureDirectories() to Plugin::ensureDirectoryExists(string $dir) and call when iterating over TranslatablePackage.
Locker // formatting of output.
  • Loading branch information
Chrico committed May 12, 2022
1 parent 050c8fd commit 098c713
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Config/PluginConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private function languageRoot(array $config): string
// version 2.0 supported ["directory" => "/path/"]
// version 2.1 supports ["languageRootDir" => "/path"]
$dir = $config['directory'] ?? $config["languageRootDir"] ?? '';
$dir = trim($dir, DIRECTORY_SEPARATOR);
$dir = trim($dir, "\\/");
if ($dir === '') {
return $root . DIRECTORY_SEPARATOR;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Package/TranslatablePackageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ public function resolveDirectory(PackageInterface $package): ?string
return null;
}

$directory = trim($directory, DIRECTORY_SEPARATOR);
$directory = trim($directory, "\\/");
$resolvedDir = $this->pluginConfiguration->languageRootDir();

if ($directory !== '') {
$resolvedDir .= $directory . DIRECTORY_SEPARATOR;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private function bootstrap(): bool
$cache->gc($config->get('cache-files-ttl'), $config->get('cache-files-maxsize'));
}

$this->ensureDirectories();
$this->ensureDirectoryExists($this->pluginConfig->languageRootDir());

return true;
}
Expand Down Expand Up @@ -272,6 +272,8 @@ public function doUpdatePackages(array $packages)
continue;
}
$processedPackages[$packageName] = true;

$this->ensureDirectoryExists($transPackage->languageDirectory());
$this->downloader->download($transPackage, $allowedLanguages);
}

Expand Down Expand Up @@ -333,10 +335,10 @@ public function uninstall(Composer $composer, IOInterface $io)
{
}

private function ensureDirectories(): bool
private function ensureDirectoryExists(string $dir): bool
{
try {
$this->filesystem->ensureDirectoryExists($this->pluginConfig->languageRootDir());
$this->filesystem->ensureDirectoryExists($dir);

return true;
} catch (\Throwable $exception) {
Expand Down
8 changes: 4 additions & 4 deletions src/Util/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function writeLockFile(): bool
{
try {
$this->io->write(
sprintf("\n<info>Writing new lock data to %s<info>", $this->file->getPath())
sprintf("\n <info>Writing new lock data to %s<info>", $this->file->getPath())
);
$this->file->write($this->lockedData);

Expand All @@ -180,7 +180,7 @@ public function writeLockFile(): bool
public function removeLockFile(): bool
{
$this->io->write(
sprintf("\n<info>Lock file %s was removed.<info>", $this->file->getPath())
sprintf("<info>Lock file %s was removed.<info>", $this->file->getPath())
);

return (new Filesystem())->remove($this->file->getPath());
Expand All @@ -194,7 +194,7 @@ private function loadLockData(): bool
try {
if (!$this->file->exists()) {
$this->io->write(
sprintf('<error>No %s found.</error>', $this->file->getPath()),
sprintf(' <info>No %s found.</info>', $this->file->getPath()),
true,
IOInterface::VERBOSE
);
Expand All @@ -205,7 +205,7 @@ private function loadLockData(): bool
$this->lockedData = $this->file->read();

$this->io->write(
sprintf('<info>Successfully loaded %s.</info>', $this->file->getPath()),
sprintf(" <info>Successfully loaded %s.</info>\n", $this->file->getPath()),
true,
IOInterface::VERBOSE
);
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Config/PluginConfigurationBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public function provideValidValidateSchema(): \Generator
true,
];

yield 'languages - multiple ones' => [
['languages' => ['de_DE', 'de_CH']],
true,
];

yield 'languageRootDir' => [
['languages' => ['de_DE'], 'languageRootDir' => '/foo/bar/'],
true,
Expand Down

0 comments on commit 098c713

Please sign in to comment.