|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Application; |
|
4
|
|
|
|
|
5
|
|
|
use N98\Util\Console\Helper\MagentoHelper; |
|
6
|
|
|
use N98\Util\OperatingSystem; |
|
7
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
|
8
|
|
|
use Symfony\Component\Console\Input\ArgvInput; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
10
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class MagentoDetector |
|
15
|
|
|
* @package N98\Magento\Application |
|
16
|
|
|
*/ |
|
17
|
|
|
class MagentoDetector |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface|null $input |
|
21
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface|null $output |
|
22
|
|
|
* @param \N98\Magento\Application\Config $config |
|
23
|
|
|
* @param \Symfony\Component\Console\Helper\HelperSet $helperSet |
|
24
|
|
|
* @param string $magentoRootDirectory |
|
|
|
|
|
|
25
|
|
|
* @return \N98\Magento\Application\DetectionResult |
|
26
|
|
|
*/ |
|
27
|
|
|
public function detect( |
|
28
|
|
|
InputInterface $input, |
|
29
|
|
|
OutputInterface $output, |
|
30
|
|
|
Config $config, |
|
31
|
|
|
HelperSet $helperSet, |
|
32
|
|
|
$magentoRootDirectory = null |
|
33
|
|
|
) { |
|
34
|
|
|
$input = $input ?: new ArgvInput(); |
|
35
|
|
|
$output = $output ?: new ConsoleOutput(); |
|
36
|
|
|
|
|
37
|
|
|
$folder = OperatingSystem::getCwd(); |
|
38
|
|
|
$subFolders = []; |
|
39
|
|
|
|
|
40
|
|
|
$directRootDirectory = $this->getDirectRootDirectory($input); |
|
41
|
|
|
|
|
42
|
|
|
if (is_string($directRootDirectory)) { |
|
43
|
|
|
$folder = $this->resolveRootDirOption($directRootDirectory); |
|
44
|
|
|
} elseif ($magentoRootDirectory !== null) { |
|
45
|
|
|
$subFolders = [$magentoRootDirectory]; |
|
46
|
|
|
} else { |
|
47
|
|
|
$subFolders = $config->getDetectSubFolders(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$helperSet->set(new MagentoHelper($input, $output), 'magento'); |
|
51
|
|
|
/* @var $magentoHelper MagentoHelper */ |
|
52
|
|
|
$magentoHelper = $helperSet->get('magento'); |
|
53
|
|
|
|
|
54
|
|
|
return new DetectionResult($magentoHelper, $folder, $subFolders); // @TODO must be refactored |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param InputInterface $input |
|
59
|
|
|
* @return string |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function getDirectRootDirectory(InputInterface $input) |
|
62
|
|
|
{ |
|
63
|
|
|
return $input->getParameterOption('--root-dir'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Set root dir (chdir()) of magento directory |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $path to Magento directory |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
private function resolveRootDirOption($path) |
|
73
|
|
|
{ |
|
74
|
|
|
$path = trim($path); |
|
75
|
|
|
|
|
76
|
|
|
if (strpos($path, '~') === 0) { |
|
77
|
|
|
$path = OperatingSystem::getHomeDir() . substr($path, 1); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$path = realpath($path); |
|
81
|
|
|
|
|
82
|
|
|
if (is_dir($path)) { |
|
83
|
|
|
chdir($path); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $path; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.