Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/translation/Command/XliffLintCommand.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
83 if (!$filename) { | 83 if (!$filename) { |
84 if (!$stdin = $this->getStdin()) { | 84 if (!$stdin = $this->getStdin()) { |
85 throw new RuntimeException('Please provide a filename or pipe file content to STDIN.'); | 85 throw new RuntimeException('Please provide a filename or pipe file content to STDIN.'); |
86 } | 86 } |
87 | 87 |
88 return $this->display($io, array($this->validate($stdin))); | 88 return $this->display($io, [$this->validate($stdin)]); |
89 } | 89 } |
90 | 90 |
91 if (!$this->isReadable($filename)) { | 91 if (!$this->isReadable($filename)) { |
92 throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename)); | 92 throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename)); |
93 } | 93 } |
94 | 94 |
95 $filesInfo = array(); | 95 $filesInfo = []; |
96 foreach ($this->getFiles($filename) as $file) { | 96 foreach ($this->getFiles($filename) as $file) { |
97 $filesInfo[] = $this->validate(file_get_contents($file), $file); | 97 $filesInfo[] = $this->validate(file_get_contents($file), $file); |
98 } | 98 } |
99 | 99 |
100 return $this->display($io, $filesInfo); | 100 return $this->display($io, $filesInfo); |
102 | 102 |
103 private function validate($content, $file = null) | 103 private function validate($content, $file = null) |
104 { | 104 { |
105 // Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input | 105 // Avoid: Warning DOMDocument::loadXML(): Empty string supplied as input |
106 if ('' === trim($content)) { | 106 if ('' === trim($content)) { |
107 return array('file' => $file, 'valid' => true); | 107 return ['file' => $file, 'valid' => true]; |
108 } | 108 } |
109 | 109 |
110 libxml_use_internal_errors(true); | 110 libxml_use_internal_errors(true); |
111 | 111 |
112 $document = new \DOMDocument(); | 112 $document = new \DOMDocument(); |
113 $document->loadXML($content); | 113 $document->loadXML($content); |
114 if ($document->schemaValidate(__DIR__.'/../Resources/schemas/xliff-core-1.2-strict.xsd')) { | 114 if ($document->schemaValidate(__DIR__.'/../Resources/schemas/xliff-core-1.2-strict.xsd')) { |
115 return array('file' => $file, 'valid' => true); | 115 return ['file' => $file, 'valid' => true]; |
116 } | 116 } |
117 | 117 |
118 $errorMessages = array_map(function ($error) { | 118 $errorMessages = array_map(function ($error) { |
119 return array( | 119 return [ |
120 'line' => $error->line, | 120 'line' => $error->line, |
121 'column' => $error->column, | 121 'column' => $error->column, |
122 'message' => trim($error->message), | 122 'message' => trim($error->message), |
123 ); | 123 ]; |
124 }, libxml_get_errors()); | 124 }, libxml_get_errors()); |
125 | 125 |
126 libxml_clear_errors(); | 126 libxml_clear_errors(); |
127 libxml_use_internal_errors(false); | 127 libxml_use_internal_errors(false); |
128 | 128 |
129 return array('file' => $file, 'valid' => false, 'messages' => $errorMessages); | 129 return ['file' => $file, 'valid' => false, 'messages' => $errorMessages]; |
130 } | 130 } |
131 | 131 |
132 private function display(SymfonyStyle $io, array $files) | 132 private function display(SymfonyStyle $io, array $files) |
133 { | 133 { |
134 switch ($this->format) { | 134 switch ($this->format) { |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 private function displayTxt(SymfonyStyle $io, array $filesInfo) | 144 private function displayTxt(SymfonyStyle $io, array $filesInfo) |
145 { | 145 { |
146 $countFiles = count($filesInfo); | 146 $countFiles = \count($filesInfo); |
147 $erroredFiles = 0; | 147 $erroredFiles = 0; |
148 | 148 |
149 foreach ($filesInfo as $info) { | 149 foreach ($filesInfo as $info) { |
150 if ($info['valid'] && $this->displayCorrectFiles) { | 150 if ($info['valid'] && $this->displayCorrectFiles) { |
151 $io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : '')); | 151 $io->comment('<info>OK</info>'.($info['file'] ? sprintf(' in %s', $info['file']) : '')); |
191 | 191 |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) { | 195 foreach ($this->getDirectoryIterator($fileOrDirectory) as $file) { |
196 if (!in_array($file->getExtension(), array('xlf', 'xliff'))) { | 196 if (!\in_array($file->getExtension(), ['xlf', 'xliff'])) { |
197 continue; | 197 continue; |
198 } | 198 } |
199 | 199 |
200 yield $file; | 200 yield $file; |
201 } | 201 } |
223 \RecursiveIteratorIterator::LEAVES_ONLY | 223 \RecursiveIteratorIterator::LEAVES_ONLY |
224 ); | 224 ); |
225 }; | 225 }; |
226 | 226 |
227 if (null !== $this->directoryIteratorProvider) { | 227 if (null !== $this->directoryIteratorProvider) { |
228 return call_user_func($this->directoryIteratorProvider, $directory, $default); | 228 return \call_user_func($this->directoryIteratorProvider, $directory, $default); |
229 } | 229 } |
230 | 230 |
231 return $default($directory); | 231 return $default($directory); |
232 } | 232 } |
233 | 233 |
236 $default = function ($fileOrDirectory) { | 236 $default = function ($fileOrDirectory) { |
237 return is_readable($fileOrDirectory); | 237 return is_readable($fileOrDirectory); |
238 }; | 238 }; |
239 | 239 |
240 if (null !== $this->isReadableProvider) { | 240 if (null !== $this->isReadableProvider) { |
241 return call_user_func($this->isReadableProvider, $fileOrDirectory, $default); | 241 return \call_user_func($this->isReadableProvider, $fileOrDirectory, $default); |
242 } | 242 } |
243 | 243 |
244 return $default($fileOrDirectory); | 244 return $default($fileOrDirectory); |
245 } | 245 } |
246 } | 246 } |