1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MagentoHackathon\Composer\Magento\Factory; |
4
|
|
|
|
5
|
|
|
use Composer\Package\PackageInterface; |
6
|
|
|
use MagentoHackathon\Composer\Magento\Parser\MapParser; |
7
|
|
|
use MagentoHackathon\Composer\Magento\Parser\ModmanParser; |
8
|
|
|
use MagentoHackathon\Composer\Magento\Parser\PackageXmlParser; |
9
|
|
|
use MagentoHackathon\Composer\Magento\Parser\Parser; |
10
|
|
|
use MagentoHackathon\Composer\Magento\ProjectConfig; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class ParserFactory |
14
|
|
|
* @package MagentoHackathon\Composer\Magento\Factory |
15
|
|
|
* @author Aydin Hassan <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ParserFactory implements ParserFactoryInterface |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var ProjectConfig |
22
|
|
|
*/ |
23
|
|
|
protected $config; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
*/ |
27
|
11 |
|
public function __construct(ProjectConfig $config) |
28
|
|
|
{ |
29
|
11 |
|
$this->config = $config; |
30
|
11 |
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param PackageInterface $package |
34
|
|
|
* @param string $sourceDir |
35
|
|
|
* @return Parser |
36
|
|
|
* @throws \ErrorException |
37
|
|
|
*/ |
38
|
5 |
|
public function make(PackageInterface $package, $sourceDir) |
39
|
|
|
{ |
40
|
5 |
|
$moduleSpecificMap = $this->config->getMagentoMapOverwrite(); |
41
|
5 |
|
if (isset($moduleSpecificMap[$package->getName()])) { |
42
|
1 |
|
$map = $moduleSpecificMap[$package->getName()]; |
43
|
1 |
|
return new MapParser($map); |
44
|
|
|
} |
45
|
|
|
|
46
|
4 |
|
$extra = $package->getExtra(); |
47
|
4 |
|
if (isset($extra['map'])) { |
48
|
1 |
|
return new MapParser($extra['map']); |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
if (isset($extra['package-xml'])) { |
52
|
1 |
|
return new PackageXmlParser(sprintf('%s/%s', $sourceDir, $extra['package-xml'])); |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
$modmanFile = sprintf('%s/modman', $sourceDir); |
56
|
2 |
|
if (file_exists($modmanFile)) { |
57
|
1 |
|
return new ModmanParser($modmanFile); |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
throw new \ErrorException( |
61
|
|
|
sprintf( |
62
|
1 |
|
'Unable to find deploy strategy for module: "%s" no known mapping'.PHP_EOL |
63
|
1 |
|
.'sourceDir: "%s"', |
64
|
1 |
|
$package->getName(), |
65
|
|
|
$sourceDir |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|