Update jQuery from 1.12.4 to 3.7.1
[phorkie.git] / src / phorkie / Tool / Xmllint.php
1 <?php
2 namespace phorkie;
3
4 class Tool_Xmllint
5 {
6     public static $arSupportedExtensions = array(
7         'htm', 'html', 'xml'
8     );
9
10     public function run(File $file)
11     {
12         $fpath = $file->getFullPath();
13         $fpathlen = strlen($fpath);
14
15         $res = new Tool_Result();
16         $cmd = 'xmllint --noout ' . escapeshellarg($fpath) . ' 2>&1';
17         exec($cmd, $output, $retval);
18         if ($retval == 0) {
19             $res->annotations['general'][] = new Tool_Result_Line(
20                 'XML is well-formed', 'ok'
21             );
22             return $res;
23         }
24
25         for ($i = 0; $i < count($output); $i += 3) {
26             $line = $output[$i];
27             if (substr($line, 0, $fpathlen) != $fpath) {
28                 throw new Exception('xmllint does not behave as expected: ' . $line);
29             }
30             list($linenum, $msg) = explode(':', substr($line, $fpathlen + 1), 2);
31             $res->annotations[$linenum][] = new Tool_Result_Line(
32                 $msg, 'error'
33             );
34         }
35
36         $res->annotations['general'][] = new Tool_Result_Line(
37             'XML is not well-formed', 'error'
38         );
39
40         return $res;
41     }
42 }
43
44 ?>