mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-12-03 13:40:00 +09:00
Dependency updates and update version number
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
namespace Symfony\Component\Translation\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Exception\RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -33,7 +34,7 @@ class XliffLintCommand extends Command
|
||||
private $directoryIteratorProvider;
|
||||
private $isReadableProvider;
|
||||
|
||||
public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
|
||||
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
@@ -81,14 +82,14 @@ EOF
|
||||
|
||||
if (!$filename) {
|
||||
if (!$stdin = $this->getStdin()) {
|
||||
throw new \RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
|
||||
}
|
||||
|
||||
return $this->display($io, array($this->validate($stdin)));
|
||||
}
|
||||
|
||||
if (!$this->isReadable($filename)) {
|
||||
throw new \RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
|
||||
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
|
||||
}
|
||||
|
||||
$filesInfo = array();
|
||||
@@ -101,6 +102,8 @@ EOF
|
||||
|
||||
private function validate($content, $file = null)
|
||||
{
|
||||
$errors = array();
|
||||
|
||||
// Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input
|
||||
if ('' === trim($content)) {
|
||||
return array('file' => $file, 'valid' => true);
|
||||
@@ -110,22 +113,33 @@ EOF
|
||||
|
||||
$document = new \DOMDocument();
|
||||
$document->loadXML($content);
|
||||
if ($document->schemaValidate(__DIR__.'/../Resources/schemas/xliff-core-1.2-strict.xsd')) {
|
||||
return array('file' => $file, 'valid' => true);
|
||||
|
||||
if (null !== $targetLanguage = $this->getTargetLanguageFromFile($document)) {
|
||||
$expectedFileExtension = sprintf('%s.xlf', str_replace('-', '_', $targetLanguage));
|
||||
$realFileExtension = explode('.', basename($file), 2)[1] ?? '';
|
||||
|
||||
if ($expectedFileExtension !== $realFileExtension) {
|
||||
$errors[] = array(
|
||||
'line' => -1,
|
||||
'column' => -1,
|
||||
'message' => sprintf('There is a mismatch between the file extension ("%s") and the "%s" value used in the "target-language" attribute of the file.', $realFileExtension, $targetLanguage),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$errorMessages = array_map(function ($error) {
|
||||
return array(
|
||||
'line' => $error->line,
|
||||
'column' => $error->column,
|
||||
'message' => trim($error->message),
|
||||
);
|
||||
}, libxml_get_errors());
|
||||
$document->schemaValidate(__DIR__.'/../Resources/schemas/xliff-core-1.2-strict.xsd');
|
||||
foreach (libxml_get_errors() as $xmlError) {
|
||||
$errors[] = array(
|
||||
'line' => $xmlError->line,
|
||||
'column' => $xmlError->column,
|
||||
'message' => trim($xmlError->message),
|
||||
);
|
||||
}
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors(false);
|
||||
|
||||
return array('file' => $file, 'valid' => false, 'messages' => $errorMessages);
|
||||
return array('file' => $file, 'valid' => 0 === count($errors), 'messages' => $errors);
|
||||
}
|
||||
|
||||
private function display(SymfonyStyle $io, array $files)
|
||||
@@ -136,7 +150,7 @@ EOF
|
||||
case 'json':
|
||||
return $this->displayJson($io, $files);
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
|
||||
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,4 +256,15 @@ EOF
|
||||
|
||||
return $default($fileOrDirectory);
|
||||
}
|
||||
|
||||
private function getTargetLanguageFromFile(\DOMDocument $xliffContents): ?string
|
||||
{
|
||||
foreach ($xliffContents->getElementsByTagName('file')[0]->attributes ?? array() as $attribute) {
|
||||
if ('target-language' === $attribute->nodeName) {
|
||||
return $attribute->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user