4 * This file is part of Zippy.
6 * (c) Alchemy <info@alchemy.fr>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
11 namespace Alchemy\Zippy\Parser;
14 * This class is responsible of parsing GNUTar command line output
16 class ZipOutputParser implements ParserInterface
18 const LENGTH = '(\d*)';
19 const ISO_DATE = '([0-9]+-[0-9]+-[0-9]+\s+[0-9]+:[0-9]+)';
20 const FILENAME = '(.*)';
28 * @param string $dateFormat
30 public function __construct($dateFormat = "Y-m-d H:i")
32 $this->dateFormat = $dateFormat;
38 public function parseFileListing($output)
40 $lines = array_values(array_filter(explode("\n", $output)));
43 foreach ($lines as $line) {
46 // 785 2012-10-24 10:39 file
47 if (!preg_match_all("#" .
48 self::LENGTH . "\s+" . // match (785)
49 self::ISO_DATE . "\s+" . // match (2012-10-24 10:39)
50 self::FILENAME . // match (file)
52 $line, $matches, PREG_SET_ORDER
57 $chunks = array_shift($matches);
59 if (4 !== count($chunks)) {
64 'location' => $chunks[3],
66 'mtime' => \DateTime::createFromFormat($this->dateFormat, $chunks[2]),
67 'is_dir' => '/' === substr($chunks[3], -1)
77 public function parseInflatorVersion($output)
79 $lines = array_values(array_filter(explode("\n", $output, 3)));
81 $chunks = explode(' ', $lines[1], 3);
83 if (2 > count($chunks)) {
87 list(, $version) = $chunks;
95 public function parseDeflatorVersion($output)
97 $lines = array_values(array_filter(explode("\n", $output, 2)));
98 $firstLine = array_shift($lines);
99 $chunks = explode(' ', $firstLine, 3);
101 if (2 > count($chunks)) {
105 list(, $version) = $chunks;