-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add sync command * lots of fixes * fix use of mixed quotes * fixed same key in sub arrays * add indentation test case * update readme * update readme * update readme * update readme * phpcbf
- Loading branch information
1 parent
5fee378
commit 2b22add
Showing
24 changed files
with
496 additions
and
94 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
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
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,42 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\LanguageTools\Command; | ||
|
||
use InvalidArgumentException; | ||
use SupportPal\LanguageTools\Command\Output\Formatting; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
use function is_string; | ||
use function sprintf; | ||
|
||
abstract class Command extends \Symfony\Component\Console\Command\Command | ||
{ | ||
use Formatting; | ||
|
||
/** @var InputInterface */ | ||
protected $input; | ||
|
||
/** @var OutputInterface */ | ||
protected $output; | ||
|
||
abstract public function handle(): int; | ||
|
||
public function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->input = $input; | ||
$this->output = $output; | ||
|
||
return $this->handle(); | ||
} | ||
|
||
protected function singleArg(string $name): string | ||
{ | ||
$value = $this->input->getArgument($name); | ||
if (! is_string($value)) { | ||
throw new InvalidArgumentException(sprintf('Argument %s should be a string.', $name)); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
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
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,25 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\LanguageTools\Command\Output; | ||
|
||
use function sprintf; | ||
|
||
trait Formatting | ||
{ | ||
protected function info(string $string): void | ||
{ | ||
$this->line($string, 'info'); | ||
} | ||
|
||
protected function error(string $string): void | ||
{ | ||
$this->line($string, 'error'); | ||
} | ||
|
||
protected function line(string $string, ?string $style = null): void | ||
{ | ||
$styled = $style ? sprintf('<%s>%s</%s>', $style, $string, $style) : $string; | ||
|
||
$this->output->writeln($styled); | ||
} | ||
} |
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,47 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\LanguageTools\Command; | ||
|
||
use SupportPal\LanguageTools\IO\Sync\SyncDirectory; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
use function sprintf; | ||
|
||
use const PHP_EOL; | ||
|
||
class SyncCommand extends Command | ||
{ | ||
/** @var string */ | ||
protected static $defaultName = 'sync'; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName(self::$defaultName) | ||
->setDefinition([ | ||
new InputArgument('dir1', InputArgument::REQUIRED, 'Path to directory containing the base language files.'), | ||
new InputArgument('dir2', InputArgument::REQUIRED, 'Path to directory containing the language files you want to synchronise.'), | ||
]) | ||
->setDescription('Synchronise language files in two directories.') | ||
->setHelp(<<<EOF | ||
The <info>%command.name%</info> synchronises translation files with the English version: | ||
<info>php %command.full_name% resources/lang/en/ resources/lang/es/</info> | ||
EOF | ||
); | ||
} | ||
|
||
public function handle(): int | ||
{ | ||
$dir1 = $this->singleArg('dir1'); | ||
$dir2 = $this->singleArg('dir2'); | ||
|
||
$this->info(sprintf('# Synchronising %s with %s ...' . PHP_EOL, $dir2, $dir1)); | ||
|
||
(new SyncDirectory($dir1, $dir2))->sync(); | ||
|
||
return 0; | ||
} | ||
} |
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,27 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\LanguageTools\IO\Compare; | ||
|
||
use SplFileInfo; | ||
use SupportPal\LanguageTools\IO\Directory; | ||
|
||
class CompareDirectory extends Directory | ||
{ | ||
/** | ||
* @return string[] | ||
*/ | ||
public function diff(): array | ||
{ | ||
$differences = []; | ||
$this->each(function (SplFileInfo $file, SplFileInfo $otherPath) use ($differences) { | ||
$comparison = new CompareFile($file->getPathname(), $otherPath->getPathname()); | ||
if (! $comparison->hasDifferences()) { | ||
return null; | ||
} | ||
|
||
$differences[$file->getFilename()] = $comparison->diff(); | ||
}); | ||
|
||
return $differences; | ||
} | ||
} |
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
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
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,29 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SupportPal\LanguageTools\IO; | ||
|
||
use InvalidArgumentException; | ||
|
||
use function file_exists; | ||
use function sprintf; | ||
|
||
class File | ||
{ | ||
/** @var string */ | ||
protected $file1; | ||
|
||
/** @var string */ | ||
protected $file2; | ||
|
||
public function __construct(string $file1, string $file2) | ||
{ | ||
foreach ([$file1, $file2] as $file) { | ||
if (! file_exists($file)) { | ||
throw new InvalidArgumentException(sprintf('%s does not exist.', $file)); | ||
} | ||
} | ||
|
||
$this->file1 = $file1; | ||
$this->file2 = $file2; | ||
} | ||
} |
Oops, something went wrong.