|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Composer Magento Installer |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace MagentoHackathon\Composer\Magento\Parser; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Parsers modman files |
|
10
|
|
|
*/ |
|
11
|
|
|
class ModmanParser implements Parser |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var \SplFileObject The modman file |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $file; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* |
|
21
|
|
|
* @param string $modManFile |
|
22
|
|
|
*/ |
|
23
|
4 |
|
public function __construct($modManFile) |
|
24
|
|
|
{ |
|
25
|
4 |
|
$this->file = new \SplFileObject($modManFile); |
|
26
|
4 |
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return array |
|
30
|
|
|
* @throws \ErrorException |
|
31
|
|
|
*/ |
|
32
|
4 |
|
public function getMappings() |
|
33
|
|
|
{ |
|
34
|
4 |
|
if (!$this->file->isReadable()) { |
|
35
|
1 |
|
throw new \ErrorException(sprintf('modman file "%s" not readable', $this->file->getPathname())); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
3 |
|
$map = $this->parseMappings(); |
|
39
|
2 |
|
return $map; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @throws \ErrorException |
|
44
|
|
|
* @return array |
|
45
|
|
|
*/ |
|
46
|
2 |
|
protected function parseMappings() |
|
47
|
|
|
{ |
|
48
|
2 |
|
$map = array(); |
|
49
|
2 |
|
foreach ($this->file as $line => $row) { |
|
50
|
2 |
|
$row = trim($row); |
|
51
|
2 |
|
if ('' === $row || in_array($row[0], array('#', '@'))) { |
|
52
|
1 |
|
continue; |
|
53
|
|
|
} |
|
54
|
2 |
|
$parts = preg_split('/\s+/', $row, -1, PREG_SPLIT_NO_EMPTY); |
|
55
|
2 |
|
if (count($parts) === 1) { |
|
56
|
|
|
$part = reset($parts); |
|
57
|
|
|
$map[] = array($part, $part); |
|
58
|
2 |
|
} elseif (is_int(count($parts) / 2)) { |
|
59
|
1 |
|
$partCountSplit = count($parts) / 2; |
|
60
|
1 |
|
$map[] = array( |
|
61
|
1 |
|
implode(' ', array_slice($parts, 0, $partCountSplit)), |
|
62
|
1 |
|
implode(' ', array_slice($parts, $partCountSplit)), |
|
63
|
|
|
); |
|
64
|
|
|
} else { |
|
65
|
1 |
|
throw new \ErrorException( |
|
66
|
2 |
|
sprintf('Invalid row on line %d has %d parts, expected 2', $line, count($parts)) |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
1 |
|
return $map; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|