forked from aligent/Cm_StampedeResistantConfig
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfig.php
1692 lines (1527 loc) · 48.7 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Core configuration class
*
* @category Mage
* @package Mage_Core
* @author Magento Core Team <core@magentocommerce.com>
*/
class Mage_Core_Model_Config extends Mage_Core_Model_Config_Base
{
const CACHE_TAG = 'CONFIG';
/**
* Flag which allow use cache logic
*
* @var bool
*/
protected $_useCache = false;
/**
* Instructions for spitting config cache
* array(
* $sectionName => $recursionLevel
* )
* Recursion level provide availability cache subnodes separatly
*
* @var array
*/
protected $_cacheSections = array(
'admin' => 0,
'adminhtml' => 0,
'crontab' => 0,
'install' => 0,
'stores' => 1,
'websites' => 0
);
/**
* Loaded Configuration by cached sections
*
* @var array
*/
protected $_cacheLoadedSections = array();
/**
* Configuration options
*
* @var Mage_Core_Model_Config_Options
*/
protected $_options;
/**
* Storage for generated class names
*
* @var array
*/
protected $_classNameCache = array();
/**
* Storage for generated block class names
*
* @var unknown_type
*/
protected $_blockClassNameCache = array();
/**
* Storage of validated secure urls
*
* @var array
*/
protected $_secureUrlCache = array();
/**
* System environment server variables
*
* @var array
*/
protected $_distroServerVars;
/**
* Array which is using for replace placeholders of server variables
*
* @var array
*/
protected $_substServerVars;
/**
* Resource model
* Used for operations with DB
*
* @var Mage_Core_Model_Mysql4_Config
*/
protected $_resourceModel;
/**
* Configuration for events by area
*
* @var array
*/
protected $_eventAreas;
/**
* Flag cache for existing or already created directories
*
* @var array
*/
protected $_dirExists = array();
/**
* Flach which allow using cache for config initialization
*
* @var bool
*/
protected $_allowCacheForInit = true;
/**
* Property used during cache save process
*
* @var array
*/
protected $_cachePartsForSave = array();
/**
* Empty configuration object for loading and megring configuration parts
*
* @var Mage_Core_Model_Config_Base
*/
protected $_prototype;
/**
* Flag which identify what local configuration is loaded
*
* @var bool
*/
protected $_isLocalConfigLoaded = false;
/**
* Depricated properties
*
* @deprecated
*/
protected $_baseDirCache = array();
protected $_customEtcDir = null;
/**
* Flag which allow to use modules from local code pool
*
* @var bool
*/
protected $_canUseLocalModules = null;
/**
* Active modules array per namespace
* @var array
*/
private $_moduleNamespaces = null;
/**
* Modules allowed to load
* If empty - all modules are allowed
*
* @var array
*/
protected $_allowedModules = array();
/**
* Class construct
*
* @param mixed $sourceData
*/
public function __construct($sourceData=null)
{
$this->setCacheId('config_global');
$this->_options = new Mage_Core_Model_Config_Options($sourceData);
$this->_prototype = new Mage_Core_Model_Config_Base();
$this->_cacheChecksum = null;
parent::__construct($sourceData);
}
/**
* Get config resource model
*
* @return Mage_Core_Store_Mysql4_Config
*/
public function getResourceModel()
{
if (is_null($this->_resourceModel)) {
$this->_resourceModel = Mage::getResourceModel('core/config');
}
return $this->_resourceModel;
}
/**
* Get configuration options object
*
* @return Mage_Core_Model_Config_Options
*/
public function getOptions()
{
return $this->_options;
}
/**
* Set configuration options
*
* @param array $options
* @return Mage_Core_Model_Config
*/
public function setOptions($options)
{
if (is_array($options)) {
$this->getOptions()->addData($options);
}
return $this;
}
/**
* Initialization of core configuration
*
* @return Mage_Core_Model_Config
*/
public function init($options=array())
{
$this->setCacheChecksum(null);
$this->_cacheLoadedSections = array();
$this->setOptions($options);
$this->loadBase();
$cacheLoad = $this->loadModulesCache();
if ($cacheLoad) {
return $this;
}
$this->loadModules();
$this->loadDb();
$this->saveCache();
return $this;
}
/**
* Load base system configuration (config.xml and local.xml files)
*
* @return Mage_Core_Model_Config
*/
public function loadBase()
{
$etcDir = $this->getOptions()->getEtcDir();
$files = glob($etcDir.DS.'*.xml');
$this->loadFile(current($files));
while ($file = next($files)) {
$merge = clone $this->_prototype;
$merge->loadFile($file);
$this->extend($merge);
}
if (in_array($etcDir.DS.'local.xml', $files)) {
$this->_isLocalConfigLoaded = true;
}
return $this;
}
/**
* Load cached modules configuration
*
* @return bool
*/
public function loadModulesCache()
{
if (Mage::isInstalled(array('etc_dir' => $this->getOptions()->getEtcDir()))) {
if ($this->_canUseCacheForInit()) {
Varien_Profiler::start('mage::app::init::config::load_cache');
$loaded = $this->loadCache();
Varien_Profiler::stop('mage::app::init::config::load_cache');
if ($loaded) {
$this->_useCache = true;
return true;
}
}
}
return false;
}
/**
* Load modules configuration
*
* @return Mage_Core_Model_Config
*/
public function loadModules()
{
Varien_Profiler::start('config/load-modules');
$this->_loadDeclaredModules();
$resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core'));
$this->loadModulesConfiguration(array('config.xml',$resourceConfig), $this);
/**
* Prevent local.xml directives overwriting
*/
$mergeConfig = clone $this->_prototype;
$this->_isLocalConfigLoaded = $mergeConfig->loadFile($this->getOptions()->getEtcDir().DS.'local.xml');
if ($this->_isLocalConfigLoaded) {
$this->extend($mergeConfig);
}
$this->applyExtends();
Varien_Profiler::stop('config/load-modules');
return $this;
}
/**
* Check if local configuration (DB connection, etc) is loaded
*
* @return bool
*/
public function isLocalConfigLoaded()
{
return $this->_isLocalConfigLoaded;
}
/**
* Load config data from DB
*
* @return Mage_Core_Model_Config
*/
public function loadDb()
{
if ($this->_isLocalConfigLoaded && Mage::isInstalled()) {
Varien_Profiler::start('config/load-db');
$dbConf = $this->getResourceModel();
$dbConf->loadToXml($this);
Varien_Profiler::stop('config/load-db');
}
return $this;
}
/**
* Reinitialize configuration
*
* @param array $options
* @return Mage_Core_Model_Config
*/
public function reinit($options = array())
{
$this->_allowCacheForInit = false;
$this->_useCache = false;
return $this->init($options);
}
/**
* Check local modules enable/disable flag
* If local modules are disbled remove local modules path from include dirs
*
* return true if local modules enabled and false if disabled
*
* @return bool
*/
protected function _canUseLocalModules()
{
if ($this->_canUseLocalModules !== null) {
return $this->_canUseLocalModules;
}
$disableLocalModules = (string)$this->getNode('global/disable_local_modules');
if (!empty($disableLocalModules)) {
$disableLocalModules = (('true' === $disableLocalModules) || ('1' === $disableLocalModules));
} else {
$disableLocalModules = false;
}
if ($disableLocalModules && !defined('COMPILER_INCLUDE_PATH')) {
set_include_path(
// excluded '/app/code/local'
BP . DS . 'app' . DS . 'code' . DS . 'community' . PS .
BP . DS . 'app' . DS . 'code' . DS . 'core' . PS .
BP . DS . 'lib' . PS .
Mage::registry('original_include_path')
);
}
$this->_canUseLocalModules = !$disableLocalModules;
return $this->_canUseLocalModules;
}
/**
* Check if cache can be used for config initialization
*
* @return bool
*/
protected function _canUseCacheForInit()
{
if (Mage::app()->useCache('config') && $this->_allowCacheForInit) {
$retries = 10;
do {
if ($this->_loadCache($this->_getCacheLockId())) {
if ($retries) usleep(500000); // 0.5 seconds
} else {
return TRUE;
}
} while ($retries--);
}
return FALSE;
}
/**
* Retrieve cache object
*
* @return Zend_Cache_Frontend_File
*/
public function getCache()
{
return Mage::app()->getCache();
}
/**
* Get lock flag cache identifier
*
* @return string
*/
protected function _getCacheLockId()
{
return $this->getCacheId().'.lock';
}
/**
* Save configuration cache
*
* @param array $tags cache tags
* @return Mage_Core_Model_Config
*/
public function saveCache($tags=array())
{
if (!Mage::app()->useCache('config')) {
return $this;
}
if (!in_array(self::CACHE_TAG, $tags)) {
$tags[] = self::CACHE_TAG;
}
$cacheLockId = $this->_getCacheLockId();
if ($this->_loadCache($cacheLockId)) {
return $this;
}
$this->_saveCache(time(), $cacheLockId, array(), 60);
if (!empty($this->_cacheSections)) {
$xml = clone $this->_xml;
foreach ($this->_cacheSections as $sectionName => $level) {
$this->_saveSectionCache($this->getCacheId(), $sectionName, $xml, $level, $tags);
unset($xml->$sectionName);
}
$this->_cachePartsForSave[$this->getCacheId()] = $xml->asNiceXml('', false);
} else {
parent::saveCache($tags);
$this->_removeCache($cacheLockId);
return $this;
}
foreach ($this->_cachePartsForSave as $cacheId => $cacheData) {
$this->_saveCache($cacheData, $cacheId, $tags, $this->getCacheLifetime());
}
unset($this->_cachePartsForSave);
$this->_removeCache($cacheLockId);
return $this;
}
/**
* Save cache of specified
*
* @param string $idPrefix cache id prefix
* @param string $sectionName
* @param Varien_Simplexml_Element $source
* @param int $recursionLevel
* @return Mage_Core_Model_Config
*/
protected function _saveSectionCache($idPrefix, $sectionName, $source, $recursionLevel=0, $tags=array())
{
if ($source && $source->$sectionName) {
$cacheId = $idPrefix . '_' . $sectionName;
if ($recursionLevel > 0) {
foreach ($source->$sectionName->children() as $subSectionName => $node) {
$this->_saveSectionCache(
$cacheId, $subSectionName, $source->$sectionName, $recursionLevel-1, $tags
);
}
}
$this->_cachePartsForSave[$cacheId] = $source->$sectionName->asNiceXml('', false);
}
return $this;
}
/**
* Load config section cached data
*
* @param string $sectionName
* @return Varien_Simplexml_Element
*/
protected function _loadSectionCache($sectionName)
{
$cacheId = $this->getCacheId() . '_' . $sectionName;
$xmlString = $this->_loadCache($cacheId);
/**
* If we can't load section cache (problems with cache storage)
*/
if (!$xmlString) {
$this->_useCache = false;
$this->reinit($this->_options);
return false;
} else {
$xml = simplexml_load_string($xmlString, $this->_elementClass);
return $xml;
}
}
/**
* Load cached data by identifier
*
* @param string $id
* @return string
*/
protected function _loadCache($id)
{
return Mage::app()->loadCache($id);
}
/**
* Save cache data
*
* @param string $data
* @param string $id
* @param array $tags
* @param false|int $lifetime
* @return Mage_Core_Model_Config
*/
protected function _saveCache($data, $id, $tags=array(), $lifetime=false)
{
return Mage::app()->saveCache($data, $id, $tags, $lifetime);
}
/**
* Clear cache data by id
*
* @param string $id
* @return Mage_Core_Model_Config
*/
protected function _removeCache($id)
{
return Mage::app()->removeCache($id);
}
/**
* Remove configuration cache
*
* @return Mage_Core_Model_Config
*/
public function removeCache()
{
Mage::app()->cleanCache(array(self::CACHE_TAG));
return parent::removeCache();
}
/**
* Configuration cache clean process
*
* @return Mage_Core_Model_Config
*/
public function cleanCache()
{
return $this->reinit();
}
/**
* Getter for section configuration object
*
* @param array $path
* @return Mage_Core_Model_Config_Element
*/
protected function _getSectionConfig($path)
{
$section = $path[0];
if (!isset($this->_cacheSections[$section])) {
return false;
}
$sectionPath = array_slice($path, 0, $this->_cacheSections[$section]+1);
$sectionKey = implode('_', $sectionPath);
if (!isset($this->_cacheLoadedSections[$sectionKey])) {
Varien_Profiler::start('init_config_section:' . $sectionKey);
$this->_cacheLoadedSections[$sectionKey] = $this->_loadSectionCache($sectionKey);
Varien_Profiler::stop('init_config_section:' . $sectionKey);
}
if ($this->_cacheLoadedSections[$sectionKey] === false) {
return false;
}
return $this->_cacheLoadedSections[$sectionKey];
}
/**
* Get node value from cached section data
*
* @param array $path
* @return Mage_Core_Model_Config
*/
public function getSectionNode($path)
{
$section = $path[0];
$config = $this->_getSectionConfig($path);
$path = array_slice($path, $this->_cacheSections[$section] + 1);
if ($config) {
return $config->descend($path);
}
return false;
}
/**
* Returns node found by the $path and scope info
*
* @param string $path
* @param string $scope
* @param string|int $scopeCode
* @return Mage_Core_Model_Config_Element
*/
public function getNode($path=null, $scope='', $scopeCode=null)
{
if ($scope !== '') {
if (('store' === $scope) || ('website' === $scope)) {
$scope .= 's';
}
if (('default' !== $scope) && is_int($scopeCode)) {
if ('stores' == $scope) {
$scopeCode = Mage::app()->getStore($scopeCode)->getCode();
} elseif ('websites' == $scope) {
$scopeCode = Mage::app()->getWebsite($scopeCode)->getCode();
} else {
Mage::throwException(Mage::helper('core')->__('Unknown scope "%s".', $scope));
}
}
$path = $scope . ($scopeCode ? '/' . $scopeCode : '' ) . (empty($path) ? '' : '/' . $path);
}
/**
* Check path cache loading
*/
if ($this->_useCache && ($path !== null)) {
$path = explode('/', $path);
$section= $path[0];
if (isset($this->_cacheSections[$section])) {
$res = $this->getSectionNode($path);
if ($res !== false) {
return $res;
}
}
}
return parent::getNode($path);
}
/**
* Create node by $path and set its value.
*
* @param string $path separated by slashes
* @param string $value
* @param bool $overwrite
* @return Varien_Simplexml_Config
*/
public function setNode($path, $value, $overwrite = true)
{
if ($this->_useCache && ($path !== null)) {
$sectionPath = explode('/', $path);
$config = $this->_getSectionConfig($sectionPath);
if ($config) {
$sectionPath = array_slice($sectionPath, $this->_cacheSections[$sectionPath[0]]+1);
$sectionPath = implode('/', $sectionPath);
$config->setNode($sectionPath, $value, $overwrite);
}
}
return parent::setNode($path, $value, $overwrite);
}
/**
* Retrive Declared Module file list
*
* @return array
*/
protected function _getDeclaredModuleFiles()
{
$etcDir = $this->getOptions()->getEtcDir();
$moduleFiles = glob($etcDir . DS . 'modules' . DS . '*.xml');
if (!$moduleFiles) {
return false;
}
$collectModuleFiles = array(
'base' => array(),
'mage' => array(),
'custom' => array()
);
foreach ($moduleFiles as $v) {
$name = explode(DIRECTORY_SEPARATOR, $v);
$name = substr($name[count($name) - 1], 0, -4);
if ($name == 'Mage_All') {
$collectModuleFiles['base'][] = $v;
} else if (substr($name, 0, 5) == 'Mage_') {
$collectModuleFiles['mage'][] = $v;
} else {
$collectModuleFiles['custom'][] = $v;
}
}
return array_merge(
$collectModuleFiles['base'],
$collectModuleFiles['mage'],
$collectModuleFiles['custom']
);
}
/**
* Add module(s) to allowed list
*
* @param strung|array $module
* @return Mage_Core_Model_Config
*/
public function addAllowedModules($module)
{
if (is_array($module)) {
foreach ($module as $moduleName) {
$this->addAllowedModules($moduleName);
}
} elseif (!in_array($module, $this->_allowedModules)) {
$this->_allowedModules[] = $module;
}
return $this;
}
/**
* Define if module is allowed
*
* @param string $moduleName
* @return bool
*/
protected function _isAllowedModule($moduleName)
{
if (empty($this->_allowedModules)) {
return true;
} else {
return in_array($moduleName, $this->_allowedModules);
}
}
/**
* Load declared modules configuration
*
* @param null $mergeConfig depricated
* @return Mage_Core_Model_Config
*/
protected function _loadDeclaredModules($mergeConfig = null)
{
$moduleFiles = $this->_getDeclaredModuleFiles();
if (!$moduleFiles) {
return ;
}
Varien_Profiler::start('config/load-modules-declaration');
$unsortedConfig = new Mage_Core_Model_Config_Base();
$unsortedConfig->loadString('<config/>');
$fileConfig = new Mage_Core_Model_Config_Base();
// load modules declarations
foreach ($moduleFiles as $file) {
$fileConfig->loadFile($file);
$unsortedConfig->extend($fileConfig);
}
$moduleDepends = array();
foreach ($unsortedConfig->getNode('modules')->children() as $moduleName => $moduleNode) {
if (!$this->_isAllowedModule($moduleName)) {
continue;
}
$depends = array();
if ($moduleNode->depends) {
foreach ($moduleNode->depends->children() as $depend) {
$depends[$depend->getName()] = true;
}
}
$moduleDepends[$moduleName] = array(
'module' => $moduleName,
'depends' => $depends,
'active' => ('true' === (string)$moduleNode->active ? true : false),
);
}
// check and sort module dependence
$moduleDepends = $this->_sortModuleDepends($moduleDepends);
// create sorted config
$sortedConfig = new Mage_Core_Model_Config_Base();
$sortedConfig->loadString('<config><modules/></config>');
foreach ($unsortedConfig->getNode()->children() as $nodeName => $node) {
if ($nodeName != 'modules') {
$sortedConfig->getNode()->appendChild($node);
}
}
foreach ($moduleDepends as $moduleProp) {
$node = $unsortedConfig->getNode('modules/'.$moduleProp['module']);
$sortedConfig->getNode('modules')->appendChild($node);
}
$this->extend($sortedConfig);
Varien_Profiler::stop('config/load-modules-declaration');
return $this;
}
/**
* Sort modules and check depends
*
* @param array $modules
* @return array
*/
protected function _sortModuleDepends($modules)
{
foreach ($modules as $moduleName => $moduleProps) {
$depends = $moduleProps['depends'];
foreach ($moduleProps['depends'] as $depend => $true) {
if ($moduleProps['active'] && ((!isset($modules[$depend])) || empty($modules[$depend]['active']))) {
Mage::throwException(
Mage::helper('core')->__('Module "%1$s" requires module "%2$s".', $moduleName, $depend)
);
}
$depends = array_merge($depends, $modules[$depend]['depends']);
}
$modules[$moduleName]['depends'] = $depends;
}
$modules = array_values($modules);
$size = count($modules) - 1;
for ($i = $size; $i >= 0; $i--) {
for ($j = $size; $i < $j; $j--) {
if (isset($modules[$i]['depends'][$modules[$j]['module']])) {
$value = $modules[$i];
$modules[$i] = $modules[$j];
$modules[$j] = $value;
}
}
}
$definedModules = array();
foreach ($modules as $moduleProp) {
foreach ($moduleProp['depends'] as $dependModule => $true) {
if (!isset($definedModules[$dependModule])) {
Mage::throwException(
Mage::helper('core')->__('Module "%1$s" cannot depend on "%2$s".', $moduleProp['module'], $dependModule)
);
}
}
$definedModules[$moduleProp['module']] = true;
}
return $modules;
}
/**
* Determine whether provided name begins from any available modules, according to namespaces priority
* If matched, returns as the matched module "factory" name or a fully qualified module name
*
* @param string $name
* @param bool $asFullModuleName
* @return string
*/
public function determineOmittedNamespace($name, $asFullModuleName = false)
{
if (null === $this->_moduleNamespaces) {
$this->_moduleNamespaces = array();
foreach ($this->_xml->xpath('modules/*') as $m) {
if ((string)$m->active == 'true') {
$moduleName = $m->getName();
$module = strtolower($moduleName);
$this->_moduleNamespaces[substr($module, 0, strpos($module, '_'))][$module] = $moduleName;
}
}
}
$name = explode('_', strtolower($name));
$partsNum = count($name);
$defaultNamespaceFlag = false;
foreach ($this->_moduleNamespaces as $namespaceName => $namespace) {
// assume the namespace is omitted (default namespace only, which comes first)
if ($defaultNamespaceFlag === false) {
$defaultNamespaceFlag = true;
$defaultNS = $namespaceName . '_' . $name[0];
if (isset($namespace[$defaultNS])) {
return $asFullModuleName ? $namespace[$defaultNS] : $name[0]; // return omitted as well
}
}
// assume namespace is qualified
if(isset($name[1])) {
$fullNS = $name[0] . '_' . $name[1];
if (2 <= $partsNum && isset($namespace[$fullNS])) {
return $asFullModuleName ? $namespace[$fullNS] : $fullNS;
}
}
}
return '';
}
/**
* Iterate all active modules "etc" folders and combine data from
* specidied xml file name to one object
*
* @param string $fileName
* @param null|Mage_Core_Model_Config_Base $mergeToObject
* @return Mage_Core_Model_Config_Base
*/
public function loadModulesConfiguration($fileName, $mergeToObject = null, $mergeModel=null)
{
$disableLocalModules = !$this->_canUseLocalModules();
if ($mergeToObject === null) {
$mergeToObject = clone $this->_prototype;
$mergeToObject->loadString('<config/>');
}
if ($mergeModel === null) {
$mergeModel = clone $this->_prototype;
}
$modules = $this->getNode('modules')->children();
foreach ($modules as $modName=>$module) {
if ($module->is('active')) {
if ($disableLocalModules && ('local' === (string)$module->codePool)) {
continue;
}
if (!is_array($fileName)) {
$fileName = array($fileName);
}
foreach ($fileName as $configFile) {
$configFile = $this->getModuleDir('etc', $modName).DS.$configFile;
if ($mergeModel->loadFile($configFile)) {
$this->_makeEventsLowerCase(Mage_Core_Model_App_Area::AREA_GLOBAL, $mergeModel);
$this->_makeEventsLowerCase(Mage_Core_Model_App_Area::AREA_FRONTEND, $mergeModel);
$this->_makeEventsLowerCase(Mage_Core_Model_App_Area::AREA_ADMIN, $mergeModel);
$this->_makeEventsLowerCase(Mage_Core_Model_App_Area::AREA_ADMINHTML, $mergeModel);
$mergeToObject->extend($mergeModel, true);
}
}
}
}
return $mergeToObject;
}
/**
* Retrieve temporary directory path
*
* @return string
*/
public function getTempVarDir()
{
return $this->getOptions()->getVarDir();
}
/**
* Get default server variables values
*
* @return array