This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 40
/
loader.php
1480 lines (1220 loc) · 50 KB
/
loader.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
/**
* Copyright (c) 2009, Yahoo! Inc. All rights reserved.
* Code licensed under the BSD License:
* http://developer.yahoo.net/yui/license.html
* version: 1.0.0b1
*/
/**
* Used to specify JavaScript and CSS module requirements. It maintains a dependency
* tree for these modules so when a module is requested, all of the other modules it
* depends on are included as well. By default, the YUI Library is configured, and
* other modules and their dependencies can be added via PHP.
* @module phploader
*/
define('YUI_AFTER', 'after');
define('YUI_BASE', 'base');
define('YUI_CSS', 'css');
define('YUI_DATA', 'DATA');
define('YUI_DEPCACHE', 'depCache');
define('YUI_DEBUG', 'DEBUG');
define('YUI_EMBED', 'EMBED');
define('YUI_FILTERS', 'filters');
define('YUI_FULLPATH', 'fullpath');
define('YUI_FULLJSON', 'FULLJSON');
define('YUI_GLOBAL', 'global');
define('YUI_JS', 'js');
define('YUI_JSON', 'JSON');
define('YUI_MODULES', 'modules');
define('YUI_NAME', 'name');
define('YUI_OPTIONAL', 'optional');
define('YUI_OVERRIDES', 'overrides');
define('YUI_PATH', 'path');
define('YUI_PKG', 'pkg');
define('YUI_PREFIX', 'prefix');
define('YUI_PROVIDES', 'provides');
define('YUI_RAW', 'RAW');
define('YUI_REPLACE', 'replace');
define('YUI_REQUIRES', 'requires');
define('YUI_ROLLUP', 'rollup');
define('YUI_SATISFIES', 'satisfies');
define('YUI_SEARCH', 'search');
define('YUI_SKIN', 'skin');
define('YUI_SKINNABLE', 'skinnable');
define('YUI_SUPERSEDES', 'supersedes');
define('YUI_TAGS', 'TAGS');
define('YUI_TYPE', 'type');
define('YUI_URL', 'url');
/**
* The YUI PHP loader base class which provides dynamic server-side loading for YUI
* @class YAHOO_util_Loader
* @namespace PHP
*/
class YAHOO_util_Loader {
/**
* The base directory
* @property base
* @type string
* @default http://yui.yahooapis.com/[YUI VERSION]/build/
*/
var $base = "";
var $filter = "";
// current target not used
var $target = "";
/**
* Combined into a single request using the combo service to pontentially reduce the number of http requests required.
* @property combine
* @type boolean
* @default false
*/
var $combine = false;
/**
* Should we allow rollups
* @property allowRollups
* @type boolean
* @default true
*/
var $allowRollups = true;
/**
* Whether or not to load optional dependencies for the requested modules
* @property loadOptional
* @type boolean
* @default false
*/
var $loadOptional = false;
/**
* Force rollup modules to be sorted as moved to the top of
* the stack when performing an automatic rollup. This has a very small performance consequence.
* @property rollupsToTop
* @type boolean
* @default false
*/
var $rollupsToTop = false;
// first pass through we will check for meta-modules and remove
// dependencies where a supercedes is found.
// var $firstPass = true;
// the first time we output a module type we allow automatic rollups, this
// array keeps track of module types we have processed
var $processedModuleTypes = array();
// all required modules
var $requests = array();
// modules that have been been outputted via getLink()
var $loaded = array();
// list of all modules superceded by the list of required modules
var $superceded = array();
// module load count to catch circular dependencies
// var $loadCount = array();
// keeps track of modules that were requested that are not defined
var $undefined = array();
var $dirty=true;
var $sorted=null;
var $accountedFor = array();
/**
* A list of modules to apply the filter to. If not supplied, all
* modules will have any defined filters applied. Tip: Useful for debugging.
* @property filterList
* @type array
* @default null
*/
var $filterList = null;
// the list of required skins
var $skins = array();
var $modules = array();
var $fullCacheKey = null;
var $baseOverrides = array();
var $cacheFound = false;
var $delayCache = false;
/* If the version is set, a querystring parameter is appended to the
* end of all generated URLs. This is a cache busting hack for environments
* that always use the same path for the current version of the library.
* @property version
* @type string
* @default null
*/
var $version = null;
var $versionKey = "_yuiversion";
// the skin definition
var $skin = array();
var $rollupModules = array();
var $globalModules = array();
var $satisfactionMap = array();
var $depCache = array();
var $filters = array();
/**
* The base path to the combo service. Uses the Yahoo! CDN service by default.
* You do not have to set this property to use the combine option. YUI PHP Loader ships
* with an intrinsic, lightweight combo-handler as well (see combo.php).
* @property comboBase
* @type string
* @default http://yui.yahooapis.com/combo?
*/
var $comboBase = "http://yui.yahooapis.com/combo?";
// additional vars used to assist with combo handling
var $cssComboLocation = null;
var $jsComboLocation = null;
/**
* The YAHOO_util_Loader class constructor
* @constructor
* @param {string} yuiVersion Defines which version of YUI metadata to load
* @param {string} cacheKey Unique APC cache key. This is combined with the YUI base
* so that updates to YUI will force a new cache entry. However, if your custom config
* changes, this key should be changed (otherwise the old values will be used until the cache expires).
* @param {array} modules A list of custom modules
* @param {boolean} noYUI Pass true if you do not want the YUI metadata
*/
function YAHOO_util_Loader($yuiVersion, $cacheKey=null, $modules=null, $noYUI=false) {
if (!isset($yuiVersion)) {
die("Error: The first parameter of YAHOO_util_Loader must specify which version of YUI to use!");
}
/*
* Include the metadata config file that corresponds to the requested YUI version
* Note: we attempt to find a prebuilt config_{version}.php file which contains an associative array,
* but if not available we'll attempt to find and parse the YUI json dependency file.
*/
$parentDir = dirname(dirname(__FILE__));
$phpConfigFile = $parentDir . '/lib/meta/config_' . $yuiVersion . '.php';
$jsonConfigFile = $parentDir . '/lib/meta/json_' . $yuiVersion . '.txt';
if (file_exists($phpConfigFile) && is_readable($phpConfigFile)) {
require($phpConfigFile);
} else if (file_exists($jsonConfigFile) && is_readable($jsonConfigFile) && function_exists('json_encode')) {
$jsonConfigString = file_get_contents($jsonConfigFile);
$inf = json_decode($jsonConfigString, true);
$GLOBALS['yui_current'] = $inf;
} else {
die("Unable to find a suitable YUI metadata file!");
}
global $yui_current;
$this->apcttl = 0;
$this->curlAvail = function_exists('curl_exec');
$this->apcAvail = function_exists('apc_fetch');
$this->jsonAvail = function_exists('json_encode');
$this->embedAvail = ($this->curlAvail && $this->apcAvail);
$this->base = $yui_current[YUI_BASE];
$this->comboDefaultVersion = $yuiVersion; //(ex) 2.7.0
$this->fullCacheKey = null;
$cache = null;
if ($cacheKey && $this->apcAvail) {
$this->fullCacheKey = $this->base . $cacheKey;
$cache = apc_fetch($this->fullCacheKey);
}
if ($cache) {
$this->cacheFound = true;
// $this->log("using cache -------------------------------------------------------");
// $this->log(var_export($cache[YUI_DEPCACHE], true));
// $this->log("----------------------------------------------------------");
$this->modules = $cache[YUI_MODULES];
$this->skin = $cache[YUI_SKIN];
$this->rollupModules = $cache[YUI_ROLLUP];
$this->globalModules = $cache[YUI_GLOBAL];
$this->satisfactionMap = $cache[YUI_SATISFIES];
$this->depCache = $cache[YUI_DEPCACHE];
$this->filters = $cache[YUI_FILTERS];
} else {
// $this->log("initializing metadata-------------------------------------------------------");
// set up the YUI info for the current version of the lib
if ($noYUI) {
$this->modules = array();
} else {
$this->modules = $yui_current['moduleInfo'];
}
if ($modules) {
$this->modules = array_merge_recursive($this->modules, $modules);
}
$this->skin = $yui_current[YUI_SKIN];
$this->skin['overrides'] = array();
$this->skin[YUI_PREFIX] = "skin-";
$this->filters = array(
YUI_RAW => array(
YUI_SEARCH => "-min\.js",
YUI_REPLACE => ".js"
),
YUI_DEBUG => array(
YUI_SEARCH => "-min\.js",
YUI_REPLACE => "-debug.js"
)
);
foreach ($this->modules as $name=>$m) {
if (isset($m[YUI_GLOBAL])) {
$this->globalModules[$name] = true;
}
if (isset($m[YUI_SUPERSEDES])) {
$this->rollupModules[$name] = $m;
foreach ($m[YUI_SUPERSEDES] as $sup) {
$this->mapSatisfyingModule($sup, $name);
}
}
}
}
}
function updateCache() {
if ($this->fullCacheKey) {
$cache = array();
$cache[YUI_MODULES] = $this->modules;
$cache[YUI_SKIN] = $this->skin;
$cache[YUI_ROLLUP] = $this->rollupModules;
$cache[YUI_GLOBAL] = $this->globalModules;
$cache[YUI_DEPCACHE] = $this->depCache;
$cache[YUI_SATISFIES] = $this->satisfactionMap;
$cache[YUI_FILTERS] = $this->filters;
apc_store($this->fullCacheKey, $cache, $this->apcttl);
}
}
/**
* Used to load YUI and/or custom components
* @method load
* @param string $varname [, string $... ] List of component names
*/
function load() {
//Expects N-number of named components to load
$args = func_get_args();
foreach ($args as $arg) {
$this->loadSingle($arg);
}
}
function setProcessedModuleType($moduleType='ALL') {
$this->processedModuleTypes[$moduleType] = true;
}
function hasProcessedModuleType($moduleType='ALL') {
return isset($this->processedModuleTypes[$moduleType]);
}
/**
* Used to specify modules that are already on the page that should not be loaded again
* @method setLoaded
* @param string $varname [, string $... ] List of module names
*/
function setLoaded() {
$args = func_get_args();
// prevent rollups when no module type is specified
//$this->setProcessedModuleType(null);
foreach ($args as $arg) {
if (isset($this->modules[$arg])) {
$this->loaded[$arg] = $arg;
$mod = $this->modules[$arg];
$sups = $this->getSuperceded($arg);
foreach ($sups as $supname=>$val) {
//$this->log("accounting for by way of supersede: " . $supname);
$this->loaded[$supname] = $supname;
}
// prevent rollups for this module type
$this->setProcessedModuleType($mod[YUI_TYPE]);
} else {
$msg = "YUI_LOADER: undefined module name provided to setLoaded(): " . $arg;
error_log($msg, 0);
}
}
//var_export($this->loaded);
}
function parseSkin($moduleName) {
if (strpos( $moduleName, $this->skin[YUI_PREFIX] ) === 0) {
return split('-', $moduleName);
}
return null;
}
function formatSkin($skin, $moduleName) {
$prefix = $this->skin[YUI_PREFIX];
//$prefix = (isset($this->skin[YUI_PREFIX])) ? $this->skin[YUI_PREFIX] : 'skin-';
$s = $prefix . $skin;
if ($moduleName) {
$s = $s . '-' . $moduleName;
}
return $s;
}
function addSkin($skin) {
}
function loadSingle($name) {
$skin = $this->parseSkin($name);
if ($skin) {
$this->skins[] = $name;
$this->dirty = true;
return true;
}
if (!isset($this->modules[$name])) {
$this -> undefined[$name] = $name;
return false;
}
if (isset($this->loaded[$name]) || isset($this->accountedFor[$name])) {
// skip
//print_r($name);
//var_export($this->loaded);
//var_export($this->accountedFor);
} else {
$this->requests[$name] = $name;
$this->dirty = true;
}
return true;
}
/**
* Used to output each of the required script tags
* @method script
* @return {string}
*/
function script() {
return $this->tags(YUI_JS);
}
/**
* Used to output each of the required link tags
* @method css
* @return {string} (e.g.)
*/
function css() {
return $this->tags(YUI_CSS);
}
/**
* Used to output each of the required html tags (i.e.) script or link
* @method tags
* @param {string} moduleType Type of html tag to return (i.e.) js or css. Default is both.
* @param {boolean} skipSort
* @return {string}
*/
function tags($moduleType=null, $skipSort=false) {
return $this->processDependencies(YUI_TAGS, $moduleType, $skipSort);
}
/**
* Used to embed the raw JavaScript inline
* @method script_embed
* @return {string} Returns the script tag(s) with the JavaScript inline
*/
function script_embed() {
return $this->embed(YUI_JS);
}
/**
* Used to embed the raw CSS
* @method css_embed
* @return {string} (e.g.) Returns the style tag(s) with the CSS inline
*/
function css_embed() {
return $this->embed(YUI_CSS);
}
/**
* Used to output each of the required html tags inline (i.e.) script and/or style
* @method embed
* @param {string} moduleType Type of html tag to return (i.e.) js or css. Default is both.
* @param {boolean} skipSort
* @return {string} Returns the style tag(s) with the CSS inline and/or the script tag(s) with the JavaScript inline
*/
function embed($moduleType=null, $skipSort=false) {
return $this->processDependencies(YUI_EMBED, $moduleType, $skipSort);
}
/**
* Used to fetch an array of the required JavaScript components
* @method script_data
* @return {array} Returns an array of data about each of the identified JavaScript components
*/
function script_data() {
return $this->data(YUI_JS);
}
/**
* Used to fetch an array of the required CSS components
* @method css_data
* @return {array} Returns an array of data about each of the identified JavaScript components
*/
function css_data() {
return $this->data(YUI_CSS);
}
/**
* Used to output an Array which contains data about the required JavaScript & CSS components
* @method data
* @param {string} moduleType Type of html tag to return (i.e.) js or css. Default is both.
* @param {boolean} allowRollups
* @param {boolean} skipSort
* @return {string}
*/
function data($moduleType=null, $allowRollups=false, $skipSort=false) {
if (!$allowRollups) {
$this->setProcessedModuleType($moduleType);
}
$type = YUI_DATA;
return $this->processDependencies($type, $moduleType, $skipSort);
}
/**
* Used to fetch a JSON object with the required JavaScript components
* @method script_json
* @return {string} Returns a JSON object containing urls for each JavaScript component
*/
function script_json() {
return $this->json(YUI_JS);
}
/**
* Used to fetch a JSON object with the required CSS components
* @method css_json
* @return {string} Returns a JSON object containing urls for each CSS component
*/
function css_json() {
return $this->json(YUI_CSS);
}
/**
* Used to fetch a JSON object with the required JavaScript and CSS components
* @method json
* @param {string} moduleType
* @param {boolean} allowRollups
* @param {boolean} skipSort
* @param {boolean} full
* @return {string} Returns a JSON object with the required JavaScript and CSS components
*/
function json($moduleType=null, $allowRollups=false, $skipSort=false, $full=false) {
//$this->firstPass = $allowRollups; // TODO: Seems like an awkward way to force it to not use rollups
if (!$allowRollups) {
$this->setProcessedModuleType($moduleType);
}
// the original JSON output only sent the provides data, not the requires
$type = YUI_JSON;
if ($full) {
$type = YUI_FULLJSON;
}
return $this->processDependencies($type, $moduleType, $skipSort);
}
/**
* Used to produce the raw JavaScript code inline without the actual script tags
* @method script_raw
* @return {string} Returns the raw JavaScript code inline without the actual script tags
*/
function script_raw() {
return $this->raw(YUI_JS);
}
/**
* Used to produce the raw CSS code inline without the actual style tags
* @method css_raw
* @return {string} Returns the raw CSS code inline without the actual style tags
*/
function css_raw() {
return $this->raw(YUI_CSS);
}
/**
* Used to produce the raw Javacript and CSS code inline without the actual script or style tags
* @method raw
* @param {string} moduleType
* @param {boolean} allowRollups
* @param {boolean} skipSort
* @return {string} Returns the raw JavaScript and/or CSS code inline without the actual style tags
*/
function raw($moduleType=null, $allowRollups=false, $skipSort=false) {
return $this->processDependencies(YUI_RAW, $moduleType, $skipSort);
}
function log($msg) {
//error_log($msg, 3, "yui_loader_log.txt");
error_log($msg, 0);
//print_r("<p>" . $msg . "</p>");
}
function accountFor($name) {
//$this->log("accountFor: " . $name);
$this->accountedFor[$name] = $name;
if (isset($this->modules[$name])) {
$dep = $this->modules[$name];
$sups = $this->getSuperceded($name);
foreach ($sups as $supname=>$val) {
// $this->log("accounting for by way of supersede: " . $supname);
$this->accountedFor[$supname] = true;
}
}
}
function prune($deps, $moduleType) {
if ($moduleType) {
$newdeps = array();
foreach ($deps as $name=>$val) {
$dep = $this->modules[$name];
if ($dep[YUI_TYPE] == $moduleType) {
$newdeps[$name] = true;
}
}
return $newdeps;
} else {
return $deps;
}
}
function getSuperceded($name) {
$key = YUI_SUPERSEDES . $name;
if (isset($this->depCache[$key])) {
return $this->depCache[$key];
}
$sups = array();
if (isset($this->modules[$name])) {
$m = $this->modules[$name];
if (isset($m[YUI_SUPERSEDES])) {
foreach ($m[YUI_SUPERSEDES] as $supName) {
$sups[$supName] = true;
if (isset($this->modules[$supName])) {
$supsups = $this->getSuperceded($supName);
if (count($supsups) > 0) {
$sups = array_merge($sups, $supsups);
}
}
}
}
}
$this->depCache[$key] = $sups;
return $sups;
}
function skinSetup($name) {
$skinName = null;
$dep = $this->modules[$name];
// $this->log("Checking skin for " . $name);
if ($dep && isset($dep[YUI_SKINNABLE])) {
$s = $this->skin;
//print_r($s);
if (isset($s[YUI_OVERRIDES][$name])) {
foreach ($s[YUI_OVERRIDES][$name] as $name2 => $over2) {
$skinName = $this->formatSkin($over2, $name);
}
} else {
$skinName = $this->formatSkin($s["defaultSkin"], $name);
}
// $this->log("Adding new skin module " . $name . ": " . $skinName);
$this->skins[] = $skinName;
$skin = $this->parseSkin($skinName);
// module-specific
if (isset($skin[2])) {
$dep = $this->modules[$skin[2]];
$package = (isset($dep[YUI_PKG])) ? $dep[YUI_PKG] : $skin[2];
$path = $package . '/' . $s[YUI_BASE] . $skin[1] . '/' . $skin[2] . '.css';
$this->modules[$skinName] = array(
"name" => $skinName,
"type" => YUI_CSS,
"path" => $path,
"after" => $s[YUI_AFTER]
);
// rollup skin
} else {
$path = $s[YUI_BASE] . $skin[1] . '/' . $s[YUI_PATH];
$newmod = array(
"name" => $skinName,
"type" => YUI_CSS,
"path" => $path,
"rollup" => 3,
"after" => $s[YUI_AFTER]
);
$this->modules[$skinName] = $newmod;
$this->rollupModules[$skinName] = $newmod;
}
}
return $skinName;
}
function getAllDependencies($mname, $loadOptional=false, $completed=array()) {
// $this->log("Building deps list for " . $mname);
$key = YUI_REQUIRES . $mname;
if ($loadOptional) {
$key .= YUI_OPTIONAL;
}
if (isset($this->depCache[$key])) {
// $this->log("Using cache " . $mname);
return $this->depCache[$key];
}
$m = $this->modules[$mname];
$reqs = array();
if (isset($m[YUI_REQUIRES])) {
$origreqs = $m[YUI_REQUIRES];
foreach($origreqs as $r) {
$reqs[$r] = true;
}
}
if ($loadOptional && isset($m[YUI_OPTIONAL])) {
$o = $m[YUI_OPTIONAL];
foreach($o as $opt) {
$reqs[$opt] = true;
}
}
foreach ($reqs as $name=>$val) {
$skinName = $this->skinSetup($name);
if ($skinName) {
// $this->log("Adding skin req for " . $name . ": " . $skinName);
$reqs[$skinName] = true;
}
//$this->log("recursing deps for " . $name);
if (!isset($completed[$name]) && isset($this->modules[$name])) {
$dep = $this->modules[$name];
$newreqs = $this->getAllDependencies($name, $loadOptional, $completed);
$reqs = array_merge($reqs, $newreqs);
//foreach ($newreqs as $newname=>$newval) {
//if (!isset($reqs[$newname])) {
//$reqs[$newname] = true;
//}
//}
} else {
//$this->log("ERROR " . $name . " not defined");
//print_r(array_keys($this->modules));
}
}
$this->depCache[$key] = $reqs;
return $reqs;
}
// @todo restore global dependency support
function getGlobalDependencies() {
return $this->globalModules;
}
/**
* Returns true if the supplied $satisfied module is satisfied by the
* supplied $satisfier module
*/
function moduleSatisfies($satisfied, $satisfier) {
//$this->log("moduleSatisfies: " . $satisfied . ", " . $satisfier);
if($satisfied == $satisfier) {
//$this->log("true");
return true;
}
if (isset($this->satisfactionMap[$satisfied])) {
$satisfiers = $this->satisfactionMap[$satisfied];
return isset($satisfiers[$satisfier]);
}
//$this->log("false");
return false;
}
/**
* Used to override the base dir for specific set of modules (Note: not supported when using the combo service)
* @method overrideBase
* @param {string} base Base path (e.g.) 2.6.0/build
* @param {array} modules Module names of which to override base
*/
function overrideBase($base, $modules) {
foreach ($modules as $name) {
$this->baseOverrides[$name] = $base;
}
}
function listSatisfies($satisfied, $moduleList) {
//$this->log("listSatisfies: " . $satisfied . ", " . count($moduleList));
if (isset($moduleList[$satisfied])) {
// $this->log("***satisfied by list " . $satisfied);
$this->log("***satisfied by list " . var_export($moduleList[$satisfied], true) );
return true;
} else {
if (isset($this->satisfactionMap[$satisfied])) {
$satisfiers = $this->satisfactionMap[$satisfied];
foreach ($satisfiers as $name=>$val) {
if (isset($moduleList[$name])) {
return true;
}
}
}
}
return false;
}
function checkThreshold($module, $moduleList) {
if (count($moduleList) > 0 && isset($module[YUI_ROLLUP])) {
$matched = 0;
//$thresh = (isset($module[YUI_ROLLUP])) ? $module[YUI_ROLLUP] : count($module[YUI_SUPERSEDES]);
$thresh = $module[YUI_ROLLUP];
foreach ($moduleList as $moduleName=>$moddef) {
if (in_array($moduleName, $module[YUI_SUPERSEDES])) {
$matched++;
}
}
//$this->log("Module: " . var_export($module, true));
//$this->log("threshold number " . $matched . " of " . $thresh);
return ($matched >= $thresh);
}
return false;
}
function sortDependencies($moduleType, $skipSort=false) {
// only call this if the loader is dirty
$reqs = array();
$top = array();
$bot = array();
$notdone = array();
$sorted = array();
$found = array();
// add global dependenices so they are included when calculating rollups
$globals = $this->getGlobalDependencies($moduleType);
foreach ($globals as $name=>$dep) {
$reqs[$name] = true;
}
//print_r($this->requests);
//return;
// get and store the full list of dependencies.
foreach ($this->requests as $name=>$val) {
$reqs[$name] = true;
$dep = $this->modules[$name];
$newreqs = $this->getAllDependencies($name, $this->loadOptional);
foreach ($newreqs as $newname=>$newval) {
if (!isset($reqs[$newname])) {
$reqs[$newname] = true;
}
}
}
// if we skip the sort, we just return the list that includes everything that
// was requested, all of their requirements, and global modules. This is
// filtered by module type if supplied
if ($skipSort) {
return $this->prune($reqs, $moduleType);
}
// $this->log("------------------------------------------------------------------");
// $this->log(var_export($reqs, true));
// $this->log("rollups------------------------------------------------------------------");
//$t1 = split(" ", microtime());
//$this->log("accountedFor: " . var_export($this->accountedFor, true));
// if we are sorting again after new modules have been requested, we
// do not rollup, and we can remove the accounted for modules
if (count($this->accountedFor) > 0 || count($this->loaded) > 0) {
foreach ($this->accountedFor as $name=>$val) {
if (isset($reqs[$name])) {
// $this->log( "removing satisfied req (accountedFor) " . $name . "\n");
unset($reqs[$name]);
}
}
foreach ($this->loaded as $name=>$val) {
if (isset($reqs[$name])) {
// $this->log( "removing satisfied req (loaded) " . $name . "\n");
unset($reqs[$name]);
}
}
// otherwise, check for rollups
// } else if (!$this->hasProcessedModuleType($moduleType)) {
} else if ($this->allowRollups) {
// First we go through the meta-modules we know about to
// see if the replacement threshold has been met.
$rollups = $this->rollupModules;
//$this->log( "testing rollups " . count($rollups) . "\n");
if (count($rollups > 0)) {
foreach ($rollups as $name => $rollup) {
//$this->log( "checking rollup " . $name . "\n");
if (!isset($reqs[$name]) && $this->checkThreshold($rollup, $reqs) ) {
// $this->log( "rollup " . $name . "\n");
$reqs[$name] = true;
$dep = $this->modules[$name];
$newreqs = $this->getAllDependencies($name, $this->loadOptional, $reqs);
foreach ($newreqs as $newname=>$newval) {
if (!isset($reqs[$newname])) {
$reqs[$newname] = true;
}
}
}
}
}
}
//var_export($reqs);
//exit;
//$t2 = split(" ", microtime());
//$total = (($t2[1] - $t1[1]) + ($t2[0] - $t1[0]));
//$this->log("<----rollups: " . $total . "----------------------------");
// clear out superceded packages
foreach ($reqs as $name => $val) {
$dep = $this->modules[$name];
if (isset($dep[YUI_SUPERSEDES])) {
$override = $dep[YUI_SUPERSEDES];
//$this->log("override " . $name . ", val: " . $val . "\n");
foreach ($override as $i=>$val) {
if (isset($reqs[$val])) {
unset($reqs[$val]);
// $this->log( "Removing (superceded by val) " . $val . "\n");
}
// debugging
if (isset($reqs[$i])) {
unset($reqs[$i]);
// $this->log( "Removing (superceded by i) " . $i . "\n");
}
}
}
}
//$this->log("------------------------------------------------------------------");
//$this->log(var_export($reqs, true));
//$this->log("------------------------------------------------------------------");
//$this->log("globals to top------------------------------------------------------------------");
//$t1 = split(" ", microtime());
// move globals to the top
foreach ($reqs as $name => $val) {
$dep = $this->modules[$name];
if (isset($dep[YUI_GLOBAL]) && $dep[YUI_GLOBAL]) {
$top[$name] = $name;
} else {
$notdone[$name] = $name;
}
}
//$t2 = split(" ", microtime());
//$total = (($t2[1] - $t1[1]) + ($t2[0] - $t1[0]));
//$this->log("<----globals to top: " . $total . "-----------------------------" );
// merge new order if we have globals
if (count($top > 0)) {
$notdone = array_merge($top, $notdone);
}
//$this->log("Not done: " . var_export($notdone, true) . ", loaded: " . var_export($this->loaded, true));
//$this->log("Not done: " . var_export($notdone, true));