|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Ide\PhpStorm2017; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
6
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
8
|
|
|
use N98\Magento\Command\Developer\Ide\PhpStorm\MetaCommand as BaseMetaCommand; |
|
9
|
|
|
|
|
10
|
|
|
class MetaCommand extends BaseMetaCommand |
|
11
|
|
|
{ |
|
12
|
|
|
protected function configure() |
|
13
|
|
|
{ |
|
14
|
|
|
$this |
|
15
|
|
|
->setName('dev:ide:phpstorm:meta') |
|
16
|
|
|
->addOption('stdout', null, InputOption::VALUE_NONE, 'Print to stdout instead of files in .phpstorm.meta.php') |
|
|
|
|
|
|
17
|
|
|
->setDescription('Generates meta data file for PhpStorm auto completion') |
|
18
|
|
|
; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param InputInterface $input |
|
23
|
|
|
* @param OutputInterface $output |
|
24
|
|
|
* @param $classMaps |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function writeToOutput(InputInterface $input, OutputInterface $output, $classMaps) |
|
27
|
|
|
{ |
|
28
|
|
|
$baseMap = <<<PHP |
|
29
|
|
|
<?php |
|
30
|
|
|
namespace PHPSTORM_META { |
|
31
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */ |
|
32
|
|
|
/** @noinspection PhpIllegalArrayKeyTypeInspection */ |
|
33
|
|
|
/** @noinspection PhpLanguageLevelInspection */ |
|
34
|
|
|
\$STATIC_METHOD_TYPES = [ |
|
35
|
|
|
PHP; |
|
36
|
|
|
$baseMap .= "\n"; |
|
37
|
|
|
foreach ($this->groupFactories as $group => $methods) { |
|
38
|
|
|
$map = $baseMap; |
|
39
|
|
|
foreach ($methods as $method) { |
|
40
|
|
|
$map .= " " . $method . "('') => [\n"; |
|
41
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
|
42
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
|
43
|
|
|
$map .= " '$classPrefix' instanceof \\$class,\n"; |
|
44
|
|
|
} else { |
|
45
|
|
|
$output->writeln('<warning>Invalid class name <comment>'.$class.'</comment> ignored</warning>'); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
$map .= " ], \n"; |
|
49
|
|
|
} |
|
50
|
|
|
$map .= <<<PHP |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
PHP; |
|
54
|
|
|
if ($input->getOption('stdout')) { |
|
55
|
|
|
$output->writeln($map); |
|
56
|
|
|
} else { |
|
57
|
|
|
$metaPath = $this->_magentoRootFolder . '/.phpstorm.meta.php'; |
|
58
|
|
|
if (is_file($metaPath)) { |
|
59
|
|
|
if (\unlink($metaPath)) { |
|
60
|
|
|
$output->writeln('<info>Deprecated file <comment>.phpstorm.meta.php</comment> removed</info>'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
if (!is_dir($metaPath)) { |
|
64
|
|
|
if (\mkdir($metaPath)) { |
|
65
|
|
|
$output->writeln('<info>Directory <comment>.phpstorm.meta.php</comment> created</info>'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
$group = str_replace(array(' ', '/'), '_', $group); |
|
69
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php/magento_'.$group.'.meta.php', $map)) { |
|
|
|
|
|
|
70
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php/magento_'.$group.'.meta.php</comment> generated</info>'); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.