1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Developer\Ide\PhpStorm; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
7
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
10
|
|
|
use Symfony\Component\Finder\Finder; |
11
|
|
|
use Symfony\Component\Finder\SplFileInfo; |
12
|
|
|
use UnexpectedValueException; |
13
|
|
|
use Varien_Simplexml_Element; |
14
|
|
|
|
15
|
|
|
class MetaCommand extends AbstractMagentoCommand |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $groups = array( |
21
|
|
|
'blocks', |
22
|
|
|
'helpers', |
23
|
|
|
'models', |
24
|
|
|
'resource models', |
25
|
|
|
'resource helpers', |
26
|
|
|
); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* List of supported static factory methods |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $groupFactories = array( |
34
|
|
|
'blocks' => array( |
35
|
|
|
'\Mage::getBlockSingleton', |
36
|
|
|
), |
37
|
|
|
'helpers' => array( |
38
|
|
|
'\Mage::helper', |
39
|
|
|
), |
40
|
|
|
'models' => array( |
41
|
|
|
'\Mage::getModel', |
42
|
|
|
'\Mage::getSingleton', |
43
|
|
|
), |
44
|
|
|
'resource helpers' => array( |
45
|
|
|
'\Mage::getResourceHelper', |
46
|
|
|
), |
47
|
|
|
'resource models' => array( |
48
|
|
|
'\Mage::getResourceModel', |
49
|
|
|
'\Mage::getResourceSingleton', |
50
|
|
|
), |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* List of supported helper methods |
55
|
|
|
* |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
protected $methodFactories = array( |
59
|
|
|
'blocks' => array( |
60
|
|
|
'\Mage_Core_Model_Layout::createBlock', |
61
|
|
|
), |
62
|
|
|
'helpers' => array( |
63
|
|
|
'\Mage_Admin_Model_User::_getHelper', |
64
|
|
|
'\Mage_Adminhtml_Controller_Rss_Abstract::_getHelper', |
65
|
|
|
'\Mage_Adminhtml_Tax_RuleController::_getHelperModel', |
66
|
|
|
'\Mage_Api_Model_User::_getHelper', |
67
|
|
|
'\Mage_Bundle_Model_Product_Price::_getHelperData', |
68
|
|
|
'\Mage_Core_Block_Abstract::helper', |
69
|
|
|
'\Mage_Core_Model_App::getHelper', |
70
|
|
|
'\Mage_Core_Model_Factory::getHelper', |
71
|
|
|
'\Mage_Core_Model_Layout::helper', |
72
|
|
|
'\Mage_Customer_AccountController::_getHelper', |
73
|
|
|
'\Mage_Customer_Model_Customer::_getHelper', |
74
|
|
|
'\Mage_ImportExport_Model_Import_Entity_Product::getHelper', |
75
|
|
|
'\Mage_Rss_Controller_Abstract::_getHelper', |
76
|
|
|
'\Mage_SalesRule_Model_Validator::_getHelper', |
77
|
|
|
'\Mage_Weee_Helper_Data::_getHelper', |
78
|
|
|
'\Mage_Weee_Model_Config_Source_Fpt_Tax::_getHelper', |
79
|
|
|
), |
80
|
|
|
'models' => array( |
81
|
|
|
'\Mage_Adminhtml_Tax_RuleController::_getSingletonModel', |
82
|
|
|
'\Mage_Catalog_Block_Product_Abstract::_getSingletonModel', |
83
|
|
|
'\Mage_Checkout_Helper_Cart::_getSingletonModel', |
84
|
|
|
'\Mage_Core_Model_Factory::getModel', |
85
|
|
|
'\Mage_Core_Model_Factory::getSingleton', |
86
|
|
|
'\Mage_Customer_AccountController::_getModel', |
87
|
|
|
'\Mage_SalesRule_Model_Validator::_getSingleton', |
88
|
|
|
'\Mage_Shipping_Model_Carrier_Tablerate::_getModel', |
89
|
|
|
'\Mage_Wishlist_Helper_Data::_getSingletonModel', |
90
|
|
|
), |
91
|
|
|
'resource models' => array( |
92
|
|
|
'\Mage_Core_Model_Factory::getResourceModel', |
93
|
|
|
), |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var array |
98
|
|
|
*/ |
99
|
|
|
protected $missingHelperDefinitionModules = array( |
100
|
|
|
'Backup', |
101
|
|
|
'Bundle', |
102
|
|
|
'Captcha', |
103
|
|
|
'Catalog', |
104
|
|
|
'Centinel', |
105
|
|
|
'Checkout', |
106
|
|
|
'Cms', |
107
|
|
|
'Core', |
108
|
|
|
'Customer', |
109
|
|
|
'Dataflow', |
110
|
|
|
'Directory', |
111
|
|
|
'Downloadable', |
112
|
|
|
'Eav', |
113
|
|
|
'Index', |
114
|
|
|
'Install', |
115
|
|
|
'Log', |
116
|
|
|
'Media', |
117
|
|
|
'Newsletter', |
118
|
|
|
'Page', |
119
|
|
|
'Payment', |
120
|
|
|
'Paypal', |
121
|
|
|
'Persistent', |
122
|
|
|
'Poll', |
123
|
|
|
'Rating', |
124
|
|
|
'Reports', |
125
|
|
|
'Review', |
126
|
|
|
'Rss', |
127
|
|
|
'Rule', |
128
|
|
|
'Sales', |
129
|
|
|
'Shipping', |
130
|
|
|
'Sitemap', |
131
|
|
|
'Tag', |
132
|
|
|
'Tax', |
133
|
|
|
'Usa', |
134
|
|
|
'Weee', |
135
|
|
|
'Widget', |
136
|
|
|
'Wishlist', |
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
const VERSION_OLD = 'old'; |
140
|
|
|
const VERSION_2017 = '2016.2+'; |
141
|
|
|
const VERSION_2019 = '2019.1+'; |
142
|
|
|
|
143
|
|
|
protected function configure() |
144
|
|
|
{ |
145
|
|
|
$this |
146
|
|
|
->setName('dev:ide:phpstorm:meta') |
147
|
|
|
->addOption( |
148
|
|
|
'meta-version', |
149
|
|
|
null, |
150
|
|
|
InputOption::VALUE_REQUIRED, |
151
|
|
|
'PhpStorm Meta version (' . self::VERSION_OLD . ', ' . self::VERSION_2017 . ', ' . self::VERSION_2019 . ')', |
152
|
|
|
self::VERSION_2019 |
153
|
|
|
) |
154
|
|
|
->addOption('stdout', null, InputOption::VALUE_NONE, 'Print to stdout instead of file .phpstorm.meta.php') |
155
|
|
|
->setDescription('Generates meta data file for PhpStorm auto completion (default version : ' . self::VERSION_2019 . ')'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param InputInterface $input |
160
|
|
|
* @param OutputInterface $output |
161
|
|
|
* |
162
|
|
|
* @internal param string $package |
163
|
|
|
* @return void |
164
|
|
|
*/ |
165
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
166
|
|
|
{ |
167
|
|
|
$this->detectMagento($output); |
168
|
|
|
if (!$this->initMagento()) { |
169
|
|
|
return; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
if ($this->_magentoMajorVersion == self::MAGENTO_MAJOR_VERSION_1) { |
173
|
|
|
$classMaps = array(); |
174
|
|
|
|
175
|
|
|
foreach ($this->groups as $group) { |
176
|
|
|
$classMaps[$group] = $this->getClassMapForGroup($group, $output); |
177
|
|
|
|
178
|
|
|
if (!$input->getOption('stdout') && count($classMaps[$group]) > 0) { |
179
|
|
|
$output->writeln( |
180
|
|
|
'<info>Generated definitions for <comment>' . $group . '</comment> group</info>' |
181
|
|
|
); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
$version = $input->getOption('meta-version'); |
186
|
|
|
if ($version == self::VERSION_OLD) { |
187
|
|
|
$this->writeToOutputOld($input, $output, $classMaps); |
188
|
|
|
} elseif ($version == self::VERSION_2017) { |
189
|
|
|
$this->writeToOutputV2017($input, $output, $classMaps); |
190
|
|
|
} elseif ($version == self::VERSION_2019) { |
191
|
|
|
$this->writeToOutputV2019($input, $output, $classMaps); |
192
|
|
|
} |
193
|
|
|
} else { |
194
|
|
|
$output->write('Magento 2 is currently not supported'); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param SplFileInfo $file |
200
|
|
|
* @param string $classPrefix |
201
|
|
|
* @return string |
202
|
|
|
*/ |
203
|
|
|
protected function getRealClassname(SplFileInfo $file, $classPrefix) |
204
|
|
|
{ |
205
|
|
|
$path = $file->getRelativePathname(); |
206
|
|
|
if (substr($path, -4) !== '.php') { |
207
|
|
|
throw new UnexpectedValueException( |
208
|
|
|
sprintf('Expected that relative file %s ends with ".php"', var_export($path, true)) |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
$path = substr($path, 0, -4); |
212
|
|
|
$path = strtr($path, '\\', '/'); |
213
|
|
|
|
214
|
|
|
return trim($classPrefix . '_' . strtr($path, '/', '_'), '_'); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param SplFileInfo $file |
219
|
|
|
* @param string $classPrefix |
220
|
|
|
* @param string $group |
221
|
|
|
* @return string |
222
|
|
|
*/ |
223
|
|
|
protected function getClassIdentifier(SplFileInfo $file, $classPrefix, $group = '') |
224
|
|
|
{ |
225
|
|
|
$path = str_replace('.php', '', $file->getRelativePathname()); |
226
|
|
|
$path = str_replace('\\', '/', $path); |
227
|
|
|
$parts = explode('/', $path); |
228
|
|
|
$parts = array_map('lcfirst', $parts); |
229
|
|
|
if ($path == 'Data' && ($group == 'helpers')) { |
230
|
|
|
array_pop($parts); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
return rtrim($classPrefix . '/' . implode('_', $parts), '/'); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Verify whether given class is defined in given file because there is no sense in adding class with incorrect |
238
|
|
|
* file or path. Examples: |
239
|
|
|
* app/code/core/Mage/Core/Model/Mysql4/Design/Theme/Collection.php -> Mage_Core_Model_Mysql4_Design_Theme |
240
|
|
|
* app/code/core/Mage/Payment/Model/Paygate/Request.php -> Mage_Paygate_Model_Authorizenet_Request |
241
|
|
|
* app/code/core/Mage/Dataflow/Model/Convert/Iterator.php -> Mage_Dataflow_Model_Session_Adapter_Iterator |
242
|
|
|
* |
243
|
|
|
* @param SplFileInfo $file |
244
|
|
|
* @param string $className |
245
|
|
|
* @param OutputInterface $output |
246
|
|
|
* @return bool |
247
|
|
|
*/ |
248
|
|
|
protected function isClassDefinedInFile(SplFileInfo $file, $className, OutputInterface $output) |
249
|
|
|
{ |
250
|
|
|
try { |
251
|
|
|
return preg_match("/class\s+{$className}/m", $file->getContents()); |
252
|
|
|
} catch (Exception $e) { |
253
|
|
|
$output->writeln('<error>File: ' . $file->__toString() . ' | ' . $e->getMessage() . '</error>'); |
254
|
|
|
return false; |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* Resource helper is always one per module for each db type and uses model alias |
260
|
|
|
* |
261
|
|
|
* @return array |
262
|
|
|
*/ |
263
|
|
|
protected function getResourceHelperMap() |
264
|
|
|
{ |
265
|
|
|
$classes = array(); |
266
|
|
|
|
267
|
|
|
if (($this->_magentoEnterprise && version_compare(\Mage::getVersion(), '1.11.2.0', '<=')) |
268
|
|
|
|| (!$this->_magentoEnterprise && version_compare(\Mage::getVersion(), '1.6.2.0', '<')) |
269
|
|
|
) { |
270
|
|
|
return $classes; |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
$modelAliases = array_keys((array) \Mage::getConfig()->getNode('global/models')); |
274
|
|
|
foreach ($modelAliases as $modelAlias) { |
275
|
|
|
$resourceHelper = @\Mage::getResourceHelper($modelAlias); |
276
|
|
|
if (is_object($resourceHelper)) { |
277
|
|
|
$classes[$modelAlias] = get_class($resourceHelper); |
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
return $classes; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @param string $group |
286
|
|
|
* @param OutputInterface $output |
287
|
|
|
* |
288
|
|
|
*@return array |
289
|
|
|
*/ |
290
|
|
|
protected function getClassMapForGroup($group, OutputInterface $output) |
291
|
|
|
{ |
292
|
|
|
/** |
293
|
|
|
* Generate resource helper only for Magento >= EE 1.11 or CE 1.6 |
294
|
|
|
*/ |
295
|
|
|
if ($group == 'resource helpers') { |
296
|
|
|
return $this->getResourceHelperMap(); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
$classes = array(); |
300
|
|
|
foreach ($this->getGroupXmlDefinition($group) as $prefix => $modelDefinition) { |
301
|
|
|
if ($group == 'resource models') { |
302
|
|
|
if (empty($modelDefinition->resourceModel)) { |
303
|
|
|
continue; |
304
|
|
|
} |
305
|
|
|
$resourceModelNodePath = 'global/models/' . strval($modelDefinition->resourceModel); |
306
|
|
|
$resourceModelConfig = \Mage::getConfig()->getNode($resourceModelNodePath); |
307
|
|
|
if ($resourceModelConfig) { |
308
|
|
|
$classPrefix = strval($resourceModelConfig->class); |
309
|
|
|
} |
310
|
|
|
} else { |
311
|
|
|
$classPrefix = strval($modelDefinition->class); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
if (empty($classPrefix)) { |
315
|
|
|
continue; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
$classBaseFolder = str_replace('_', '/', $classPrefix); |
319
|
|
|
$searchFolders = array( |
320
|
|
|
\Mage::getBaseDir('code') . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . $classBaseFolder, |
321
|
|
|
\Mage::getBaseDir('code') . DIRECTORY_SEPARATOR . 'community' . DIRECTORY_SEPARATOR . $classBaseFolder, |
322
|
|
|
\Mage::getBaseDir('code') . DIRECTORY_SEPARATOR . 'local' . DIRECTORY_SEPARATOR . $classBaseFolder, |
323
|
|
|
); |
324
|
|
|
foreach ($searchFolders as $key => $folder) { |
325
|
|
|
if (!is_dir($folder)) { |
326
|
|
|
unset($searchFolders[$key]); |
327
|
|
|
} |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
if (empty($searchFolders)) { |
331
|
|
|
continue; |
332
|
|
|
} |
333
|
|
|
|
334
|
|
|
$finder = Finder::create(); |
335
|
|
|
$finder |
336
|
|
|
->files() |
337
|
|
|
->in($searchFolders) |
338
|
|
|
->followLinks() |
339
|
|
|
->ignoreUnreadableDirs(true) |
340
|
|
|
->name('*.php') |
341
|
|
|
->notName('install-*') |
342
|
|
|
->notName('upgrade-*') |
343
|
|
|
->notName('mysql4-*') |
344
|
|
|
->notName('mssql-*') |
345
|
|
|
->notName('oracle-*'); |
346
|
|
|
|
347
|
|
|
foreach ($finder as $file) { |
348
|
|
|
$classIdentifier = $this->getClassIdentifier($file, $prefix, $group); |
349
|
|
|
$classNameByPath = $this->getRealClassname($file, $classPrefix); |
350
|
|
|
|
351
|
|
|
switch ($group) { |
352
|
|
|
case 'blocks': |
353
|
|
|
$classNameAfterRewrites = \Mage::getConfig()->getBlockClassName($classIdentifier); |
354
|
|
|
break; |
355
|
|
|
|
356
|
|
|
case 'helpers': |
357
|
|
|
$classNameAfterRewrites = \Mage::getConfig()->getHelperClassName($classIdentifier); |
358
|
|
|
break; |
359
|
|
|
|
360
|
|
|
case 'models': |
361
|
|
|
$classNameAfterRewrites = \Mage::getConfig()->getModelClassName($classIdentifier); |
362
|
|
|
break; |
363
|
|
|
|
364
|
|
|
case 'resource models': |
365
|
|
|
default: |
366
|
|
|
$classNameAfterRewrites = \Mage::getConfig()->getResourceModelClassName($classIdentifier); |
367
|
|
|
break; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
if ($classNameAfterRewrites) { |
371
|
|
|
$addToList = true; |
372
|
|
|
if ($classNameAfterRewrites === $classNameByPath |
373
|
|
|
&& !$this->isClassDefinedInFile($file, $classNameByPath, $output) |
|
|
|
|
374
|
|
|
) { |
375
|
|
|
$addToList = false; |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
if ($addToList) { |
379
|
|
|
$classes[$classIdentifier] = $classNameAfterRewrites; |
380
|
|
|
|
381
|
|
|
if ($group == 'helpers' && strpos($classIdentifier, '/') === false) { |
382
|
|
|
$classes[$classIdentifier . '/data'] = $classNameAfterRewrites; |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
} |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
return $classes; |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
/** |
393
|
|
|
* @param InputInterface $input |
394
|
|
|
* @param OutputInterface $output |
395
|
|
|
* @param $classMaps |
396
|
|
|
*/ |
397
|
|
|
protected function writeToOutputOld(InputInterface $input, OutputInterface $output, $classMaps) |
398
|
|
|
{ |
399
|
|
|
$map = <<<PHP |
400
|
|
|
<?php |
401
|
|
|
namespace PHPSTORM_META { |
402
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */ |
403
|
|
|
/** @noinspection PhpIllegalArrayKeyTypeInspection */ |
404
|
|
|
/** @noinspection PhpLanguageLevelInspection */ |
405
|
|
|
\$STATIC_METHOD_TYPES = [ |
406
|
|
|
PHP; |
407
|
|
|
$map .= "\n"; |
408
|
|
View Code Duplication |
foreach ($this->groupFactories as $group => $methods) { |
|
|
|
|
409
|
|
|
foreach ($methods as $method) { |
410
|
|
|
$map .= " " . $method . "('') => [\n"; |
411
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
412
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
413
|
|
|
$map .= " '$classPrefix' instanceof \\$class,\n"; |
414
|
|
|
} else { |
415
|
|
|
$output->writeln('<warning>Invalid class name <comment>' . $class . '</comment> ignored</warning>'); |
416
|
|
|
} |
417
|
|
|
} |
418
|
|
|
$map .= " ], \n"; |
419
|
|
|
} |
420
|
|
|
} |
421
|
|
|
$map .= <<<PHP |
422
|
|
|
]; |
423
|
|
|
} |
424
|
|
|
PHP; |
425
|
|
|
if ($input->getOption('stdout')) { |
426
|
|
|
$output->writeln($map); |
427
|
|
|
} else { |
428
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php', $map)) { |
429
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php</comment> generated</info>'); |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* @param InputInterface $input |
436
|
|
|
* @param OutputInterface $output |
437
|
|
|
* @param $classMaps |
438
|
|
|
*/ |
439
|
|
|
protected function writeToOutputV2017(InputInterface $input, OutputInterface $output, $classMaps) |
440
|
|
|
{ |
441
|
|
|
$baseMap = <<<PHP |
442
|
|
|
<?php |
443
|
|
|
namespace PHPSTORM_META { |
444
|
|
|
/** @noinspection PhpUnusedLocalVariableInspection */ |
445
|
|
|
/** @noinspection PhpIllegalArrayKeyTypeInspection */ |
446
|
|
|
/** @noinspection PhpLanguageLevelInspection */ |
447
|
|
|
\$STATIC_METHOD_TYPES = [ |
448
|
|
|
PHP; |
449
|
|
|
$baseMap .= "\n"; |
450
|
|
|
foreach ($this->groupFactories as $group => $methods) { |
451
|
|
|
$map = $baseMap; |
452
|
|
View Code Duplication |
foreach ($methods as $method) { |
|
|
|
|
453
|
|
|
$map .= " " . $method . "('') => [\n"; |
454
|
|
|
asort($classMaps[$group]); |
455
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
456
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
457
|
|
|
$map .= " '$classPrefix' instanceof \\$class,\n"; |
458
|
|
|
} else { |
459
|
|
|
$output->writeln('<warning>Invalid class name <comment>' . $class . '</comment> ignored</warning>'); |
460
|
|
|
} |
461
|
|
|
} |
462
|
|
|
$map .= " ], \n"; |
463
|
|
|
} |
464
|
|
|
$map .= <<<PHP |
465
|
|
|
]; |
466
|
|
|
} |
467
|
|
|
PHP; |
468
|
|
View Code Duplication |
if ($input->getOption('stdout')) { |
|
|
|
|
469
|
|
|
$output->writeln($map); |
470
|
|
|
} else { |
471
|
|
|
$metaPath = $this->_magentoRootFolder . '/.phpstorm.meta.php'; |
472
|
|
|
if (is_file($metaPath)) { |
473
|
|
|
if (\unlink($metaPath)) { |
474
|
|
|
$output->writeln('<info>Deprecated file <comment>.phpstorm.meta.php</comment> removed</info>'); |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
if (!is_dir($metaPath)) { |
478
|
|
|
if (\mkdir($metaPath)) { |
479
|
|
|
$output->writeln('<info>Directory <comment>.phpstorm.meta.php</comment> created</info>'); |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
$group = str_replace(array(' ', '/'), '_', $group); |
483
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php/magento_' . $group . '.meta.php', $map)) { |
484
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php/magento_' . $group . '.meta.php</comment> generated</info>'); |
485
|
|
|
} |
486
|
|
|
} |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
$baseMap = <<<PHP |
490
|
|
|
<?php |
491
|
|
|
namespace PHPSTORM_META { |
492
|
|
|
PHP; |
493
|
|
|
$baseMap .= "\n"; |
494
|
|
View Code Duplication |
foreach ($this->methodFactories as $group => $methods) { |
|
|
|
|
495
|
|
|
$map = $baseMap; |
496
|
|
|
foreach ($methods as $method) { |
497
|
|
|
$map .= " override( " . $method . "(0),\n"; |
498
|
|
|
$map .= " map( [\n"; |
499
|
|
|
asort($classMaps[$group]); |
500
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
501
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
502
|
|
|
$map .= " '$classPrefix' => \\$class::class,\n"; |
503
|
|
|
} else { |
504
|
|
|
$output->writeln('<warning>Invalid class name <comment>' . $class . '</comment> ignored</warning>'); |
505
|
|
|
} |
506
|
|
|
} |
507
|
|
|
$map .= " ])\n"; |
508
|
|
|
$map .= " );\n"; |
509
|
|
|
} |
510
|
|
|
$map .= <<<PHP |
511
|
|
|
} |
512
|
|
|
PHP; |
513
|
|
|
if ($input->getOption('stdout')) { |
514
|
|
|
$output->writeln($map); |
515
|
|
|
} else { |
516
|
|
|
$group = str_replace(array(' ', '/'), '_', $group); |
517
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php/magento_' . $group . '_methods.meta.php', $map)) { |
518
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php/magento_' . $group . '_methods.meta.php</comment> generated</info>'); |
519
|
|
|
} |
520
|
|
|
} |
521
|
|
|
} |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
protected function writeToOutputV2019(InputInterface $input, OutputInterface $output, $classMaps) |
525
|
|
|
{ |
526
|
|
|
$baseMap = <<<PHP |
527
|
|
|
<?php |
528
|
|
|
namespace PHPSTORM_META { |
529
|
|
|
PHP; |
530
|
|
|
$baseMap .= "\n"; |
531
|
|
|
foreach ($this->groupFactories as $group => $methods) { |
532
|
|
|
$map = $baseMap; |
533
|
|
|
foreach ($methods as $method) { |
534
|
|
|
$map .= " override( " . $method . "(0),\n"; |
535
|
|
|
$map .= " map( [\n"; |
536
|
|
|
asort($classMaps[$group]); |
537
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
538
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
539
|
|
|
$map .= " '$classPrefix' => \\$class::class,\n"; |
540
|
|
|
} else { |
541
|
|
|
$output->writeln('<warning>Invalid class name <comment>' . $class . '</comment> ignored</warning>'); |
542
|
|
|
} |
543
|
|
|
} |
544
|
|
|
$map .= " ])\n"; |
545
|
|
|
$map .= " );\n"; |
546
|
|
|
} |
547
|
|
|
$map .= <<<PHP |
548
|
|
|
} |
549
|
|
|
PHP; |
550
|
|
View Code Duplication |
if ($input->getOption('stdout')) { |
|
|
|
|
551
|
|
|
$output->writeln($map); |
552
|
|
|
} else { |
553
|
|
|
$metaPath = $this->_magentoRootFolder . '/.phpstorm.meta.php'; |
554
|
|
|
if (is_file($metaPath)) { |
555
|
|
|
if (\unlink($metaPath)) { |
556
|
|
|
$output->writeln('<info>Deprecated file <comment>.phpstorm.meta.php</comment> removed</info>'); |
557
|
|
|
} |
558
|
|
|
} |
559
|
|
|
if (!is_dir($metaPath)) { |
560
|
|
|
if (\mkdir($metaPath)) { |
561
|
|
|
$output->writeln('<info>Directory <comment>.phpstorm.meta.php</comment> created</info>'); |
562
|
|
|
} |
563
|
|
|
} |
564
|
|
|
$group = str_replace(array(' ', '/'), '_', $group); |
565
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php/magento_' . $group . '.meta.php', $map)) { |
566
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php/magento_' . $group . '.meta.php</comment> generated</info>'); |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
} |
570
|
|
|
|
571
|
|
|
$baseMap = <<<PHP |
572
|
|
|
<?php |
573
|
|
|
namespace PHPSTORM_META { |
574
|
|
|
PHP; |
575
|
|
|
$baseMap .= "\n"; |
576
|
|
View Code Duplication |
foreach ($this->methodFactories as $group => $methods) { |
|
|
|
|
577
|
|
|
$map = $baseMap; |
578
|
|
|
foreach ($methods as $method) { |
579
|
|
|
$map .= " override( " . $method . "(0),\n"; |
580
|
|
|
$map .= " map( [\n"; |
581
|
|
|
asort($classMaps[$group]); |
582
|
|
|
foreach ($classMaps[$group] as $classPrefix => $class) { |
583
|
|
|
if (preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $class)) { |
584
|
|
|
$map .= " '$classPrefix' => \\$class::class,\n"; |
585
|
|
|
} else { |
586
|
|
|
$output->writeln('<warning>Invalid class name <comment>' . $class . '</comment> ignored</warning>'); |
587
|
|
|
} |
588
|
|
|
} |
589
|
|
|
$map .= " ])\n"; |
590
|
|
|
$map .= " );\n"; |
591
|
|
|
} |
592
|
|
|
$map .= <<<PHP |
593
|
|
|
} |
594
|
|
|
PHP; |
595
|
|
|
if ($input->getOption('stdout')) { |
596
|
|
|
$output->writeln($map); |
597
|
|
|
} else { |
598
|
|
|
$group = str_replace(array(' ', '/'), '_', $group); |
599
|
|
|
if (\file_put_contents($this->_magentoRootFolder . '/.phpstorm.meta.php/magento_' . $group . '_methods.meta.php', $map)) { |
600
|
|
|
$output->writeln('<info>File <comment>.phpstorm.meta.php/magento_' . $group . '_methods.meta.php</comment> generated</info>'); |
601
|
|
|
} |
602
|
|
|
} |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* @param string $group |
608
|
|
|
* @return \Mage_Core_Model_Config_Element |
609
|
|
|
*/ |
610
|
|
|
protected function getGroupXmlDefinition($group) |
611
|
|
|
{ |
612
|
|
|
if ($group == 'resource models') { |
613
|
|
|
$group = 'models'; |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
$definitions = \Mage::getConfig()->getNode('global/' . $group); |
617
|
|
|
|
618
|
|
|
switch ($group) { |
619
|
|
|
case 'blocks': |
620
|
|
|
$groupClassType = 'Block'; |
621
|
|
|
break; |
622
|
|
|
|
623
|
|
|
case 'helpers': |
624
|
|
|
$groupClassType = 'Helper'; |
625
|
|
|
break; |
626
|
|
|
|
627
|
|
|
case 'models': |
628
|
|
|
$groupClassType = 'Model'; |
629
|
|
|
break; |
630
|
|
|
|
631
|
|
|
default: |
632
|
|
|
return $definitions->children(); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
foreach ($this->missingHelperDefinitionModules as $moduleName) { |
636
|
|
|
$children = new Varien_Simplexml_Element(sprintf("<%s/>", strtolower($moduleName))); |
637
|
|
|
$children->class = sprintf('Mage_%s_%s', $moduleName, $groupClassType); |
638
|
|
|
$definitions->appendChild($children); |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
return $definitions->children(); |
642
|
|
|
} |
643
|
|
|
} |
644
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: