Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changes to support expound property. Adding logic to scan module roll…

…ups, supersedes, and submodules packages for additional module requirements.
  • Loading branch information...
commit 21121beeb2afd2897605858f552c9008d48dbe9b 1 parent 9655a13
Chad Auld authored

Showing 1 changed file with 86 additions and 65 deletions. Show diff stats Hide diff stats

  1. 151  phploader/loader.php
151  phploader/loader.php
@@ -28,6 +28,8 @@
28 28
 define('YUI_JS',         'js');
29 29
 define('YUI_JSON',       'JSON');
30 30
 define('YUI_MODULES',    'modules');
  31
+define('YUI_SUBMODULES', 'submodules');
  32
+define('YUI_EXPOUND',    'expound');
31 33
 define('YUI_NAME',       'name');
32 34
 define('YUI_OPTIONAL',   'optional');
33 35
 define('YUI_OVERRIDES',  'overrides');
@@ -48,6 +50,7 @@
48 50
 define('YUI_TYPE',       'type');
49 51
 define('YUI_URL',        'url');
50 52
 
  53
+
51 54
 /**
52 55
  * The YUI PHP loader base class which provides dynamic server-side loading for YUI
53 56
  * @class YAHOO_util_Loader
@@ -707,25 +710,87 @@ function skinSetup($name) {
707 710
     * @return {array}
708 711
     */
709 712
     function getAllDependencies($mname, $loadOptional=false, $completed=array()) {
710  
-
711  
-        // $this->log("Building deps list for " . $mname);
  713
+        //$this->log("Building deps list for " . $mname);
712 714
 
713 715
         $key = YUI_REQUIRES . $mname;
714 716
         if ($loadOptional) {
715 717
             $key .= YUI_OPTIONAL;
716 718
         }
  719
+        
717 720
         if (isset($this->depCache[$key])) {
718 721
             // $this->log("Using cache " . $mname);
719 722
             return $this->depCache[$key];
720 723
         }
721  
-
  724
+        
722 725
         $m = $this->modules[$mname];
  726
+        $mProvides = $this->getProvides($mname);
723 727
         $reqs = array();
  728
+    
  729
+	    //Some modules pretend to be others (override if this is the case)
  730
+        if (isset($this->modules[$mname][YUI_EXPOUND])) {
  731
+			if (!isset($completed[$mname])) {
  732
+				$reqs = array_merge($completed, $this->getAllDependencies($this->modules[$mname][YUI_EXPOUND], $loadOptional, array($mname => true)));
  733
+			}
  734
+        }
724 735
 
  736
+        //Add any requirements defined on the module itself
725 737
         if (isset($m[YUI_REQUIRES])) {
726 738
             $origreqs = $m[YUI_REQUIRES];
727 739
             foreach($origreqs as $r) {
728  
-                $reqs[$r] = true;
  740
+            	if (!isset($reqs[$r])) {
  741
+            		$reqs[$r] = true;
  742
+                	$reqs = array_merge($reqs, $this->getAllDependencies($r, $loadOptional, $reqs));
  743
+            	}
  744
+            }
  745
+        }
  746
+         
  747
+        //Add any submodule requirements not provided by the rollups
  748
+        if (isset($m[YUI_SUBMODULES])) {
  749
+            foreach($m[YUI_SUBMODULES] as $submodule) {
  750
+                $subreqs = $submodule[YUI_REQUIRES];
  751
+                foreach($subreqs as $sr) {     
  752
+                    if (!in_array($sr, $mProvides) && !in_array($sr, $this->accountedFor)) {
  753
+		            	if (!isset($reqs[$sr])) {
  754
+	                    	$reqs[$sr] = true; 
  755
+	                        $reqs = array_merge($reqs, $this->getAllDependencies($sr, $loadOptional, $reqs));
  756
+		            	}
  757
+                    }
  758
+                }
  759
+            }
  760
+        }
  761
+        
  762
+        //Add any superseded requirements not provided by the rollup and/or rollup submodules
  763
+        if (isset($m[YUI_SUPERSEDES])) {
  764
+            foreach($m[YUI_SUPERSEDES] as $supersededModule) {
  765
+                if (isset($this->modules[$supersededModule][YUI_REQUIRES])) {
  766
+                    foreach($this->modules[$supersededModule][YUI_REQUIRES] as $supersededModuleReq) {
  767
+                        if (!in_array($supersededModuleReq, $mProvides)) {
  768
+			            	if (!isset($reqs[$supersededModuleReq]))
  769
+			            	{
  770
+	                            $reqs[$supersededModuleReq] = true;
  771
+	                            $reqs = array_merge($reqs, $this->getAllDependencies($supersededModuleReq, $loadOptional, $reqs));
  772
+			            	}
  773
+                        }
  774
+                    }
  775
+                }
  776
+                
  777
+                //Add any submodule requirements not provided by the rollup or originally requested module
  778
+                if (isset($this->modules[$supersededModule][YUI_SUBMODULES])) {
  779
+                    foreach($this->modules[$supersededModule][YUI_SUBMODULES] as $supersededSubmodule) {
  780
+                        $ssmProvides = $this->getProvides($supersededModule);
  781
+                        $supersededSubreqs = $supersededSubmodule[YUI_REQUIRES];
  782
+                        foreach($supersededSubreqs as $ssr) {     
  783
+                            if (!in_array($ssr, $ssmProvides)) {
  784
+				            	if (!isset($reqs[$ssr]))
  785
+				            	{
  786
+                           	
  787
+	                                $reqs[$ssr] = true;
  788
+	                                $reqs = array_merge($reqs, $this->getAllDependencies($ssr, $loadOptional, $reqs));
  789
+				            	}
  790
+                            }
  791
+                        }
  792
+                    }
  793
+                }
729 794
             }
730 795
         }
731 796
 
@@ -734,41 +799,10 @@ function getAllDependencies($mname, $loadOptional=false, $completed=array()) {
734 799
             foreach($o as $opt) {
735 800
                 $reqs[$opt] = true;
736 801
             }
737  
-
738  
-        }
739  
-
740  
-        foreach ($reqs as $name=>$val) {
741  
-
742  
-            $skinName = $this->skinSetup($name);
743  
-
744  
-            if ($skinName) {
745  
-                // $this->log("Adding skin req for " . $name . ": " . $skinName);
746  
-                $reqs[$skinName] = true;
747  
-            }
748  
-    
749  
-            //$this->log("recursing deps for " . $name);
750  
-            if (!isset($completed[$name]) && isset($this->modules[$name])) {
751  
-                $dep = $this->modules[$name];
752  
-
753  
-                $newreqs = $this->getAllDependencies($name, $loadOptional, $completed);
754  
-                $reqs = array_merge($reqs, $newreqs);
755  
-
756  
-                //foreach ($newreqs as $newname=>$newval) {
757  
-                    //if (!isset($reqs[$newname])) {
758  
-                        //$reqs[$newname] = true;
759  
-                    //}
760  
-                //}
761  
-
762  
-            } else {
763  
-
764  
-                //$this->log("ERROR " . $name . " not defined");
765  
-                //print_r(array_keys($this->modules));
766  
-            }
767  
-
768 802
         }
769 803
 
770 804
         $this->depCache[$key] = $reqs;
771  
-
  805
+        
772 806
         return $reqs;
773 807
     }
774 808
 
@@ -871,7 +905,7 @@ function sortDependencies($moduleType, $skipSort=false) {
871 905
 
872 906
         // add global dependenices so they are included when calculating rollups
873 907
         $globals = $this->getGlobalDependencies($moduleType);
874  
-
  908
+        
875 909
         foreach ($globals as $name=>$dep) {
876 910
             $reqs[$name] = true;
877 911
         }
@@ -881,6 +915,7 @@ function sortDependencies($moduleType, $skipSort=false) {
881 915
             $reqs[$name] = true;
882 916
             $dep = $this->modules[$name];
883 917
             $newreqs = $this->getAllDependencies($name, $this->loadOptional);
  918
+            
884 919
             foreach ($newreqs as $newname=>$newval) {
885 920
                 if (!isset($reqs[$newname])) {
886 921
                     $reqs[$newname] = true;
@@ -888,7 +923,6 @@ function sortDependencies($moduleType, $skipSort=false) {
888 923
             }
889 924
         }
890 925
 
891  
-
892 926
         // if we skip the sort, we just return the list that includes everything that
893 927
         // was requested, all of their requirements, and global modules.  This is
894 928
         // filtered by module type if supplied
@@ -945,8 +979,8 @@ function sortDependencies($moduleType, $skipSort=false) {
945 979
             }
946 980
         }
947 981
 
948  
-    //var_export($reqs);
949  
-    //exit;
  982
+        //var_export($reqs);
  983
+        //exit;
950 984
 
951 985
         //$t2 = split(" ", microtime());
952 986
         //$total = (($t2[1] - $t1[1]) + ($t2[0] - $t1[0]));
@@ -1014,7 +1048,7 @@ function sortDependencies($moduleType, $skipSort=false) {
1014 1048
 
1015 1049
         // keep going until everything is sorted
1016 1050
         $count = 0;
1017  
-        while (count($notdone) > 0) {
  1051
+        while (count($notdone) > 0) {            
1018 1052
             //$this->log("processing loop " . $count);
1019 1053
             if ($count++ > 200) {
1020 1054
                 $msg = "YUI_LOADER ERROR: sorting could not be completed, there may be a circular dependency";
@@ -1031,9 +1065,10 @@ function sortDependencies($moduleType, $skipSort=false) {
1031 1065
                 //$this->log("done: ");
1032 1066
                 //$this->log(var_export($this->loaded, true));
1033 1067
                 //$this->log("----------------------------------------------------");
1034  
-
1035  
-                $dep = $this->modules[$name];
  1068
+                
  1069
+                $dep = $this->modules[$name];                
1036 1070
                 $newreqs = $this->getAllDependencies($name, $this->loadOptional);
  1071
+                $this->accountFor($name);    
1037 1072
                 
1038 1073
                 // $this->log($name . ": checking after " . var_export($newreqs, true));
1039 1074
                 // $this->log($name . ": checking after " . var_export($dep, true));
@@ -1051,25 +1086,15 @@ function sortDependencies($moduleType, $skipSort=false) {
1051 1086
                     }
1052 1087
                 }
1053 1088
 
1054  
-                $failed = false;
1055  
-
1056  
-                if (count($newreqs) == 0) {
1057  
-                    //$this->log("-----No requirements: "  . $name);
1058  
-                    $sorted[$name] = $name;
1059  
-                    $this->accountFor($name);
1060  
-                    unset($notdone[$name]);
1061  
-                } else {
1062  
-                    foreach ($newreqs as $depname=>$depval) {
  1089
+                if (!empty($newreqs)) {
  1090
+                    foreach ($newreqs as $depname=>$depval) {     
1063 1091
                         //$this->log("accountedFor: " . var_export($this->accountedFor, true));
1064 1092
                         //$this->log("checking " . $depname . " newreqs: " . var_export($newreqs, true));
1065 1093
                         // check if the item is accounted for in the $done list
1066  
-                        if (isset($this->accountedFor[$depname])) {
  1094
+                        if (isset($this->accountedFor[$depname]) || $this->listSatisfies($depname, $sorted)) {
  1095
+                        	//unset($notdone[$depname]);
1067 1096
                             //$this->log("----Satisfied by 'accountedfor' list: " . $depname);
1068  
-                        } else if ($this->listSatisfies($depname, $sorted)) {
1069  
-                            //$this->log("----Satisfied by 'done' list: " . $depname);
1070 1097
                         } else {
1071  
-                            $failed = true;
1072  
-
1073 1098
                             $tmp = array();
1074 1099
                             $found = false;
1075 1100
                             foreach ($notdone as $newname => $newval) {
@@ -1082,6 +1107,7 @@ function sortDependencies($moduleType, $skipSort=false) {
1082 1107
                                     break; // found something that takes care of the dependency, so jump out
1083 1108
                                 }
1084 1109
                             }
  1110
+                            
1085 1111
                             if ($found) {
1086 1112
                                 //$this->log("found merge: "  . var_export($tmp, true).  ", " . var_export($notdone, true));
1087 1113
                                 // this should put the module that handles the dependency on top, immediately
@@ -1097,17 +1123,12 @@ function sortDependencies($moduleType, $skipSort=false) {
1097 1123
                             
1098 1124
                             //$this->log("bouncing out of loops");
1099 1125
                             break(2); // break out of this iteration so we can get the missed dependency
1100  
-
1101 1126
                         }
1102 1127
                     }
1103  
-                    // if so, add to the the sorted array, removed from notdone and add to done
1104  
-                    if (!$failed) {
1105  
-                        //$this->log("----All requirements satisfied: " . $name);
1106  
-                        $sorted[$name] = $name;
1107  
-                        $this->accountFor($name);
1108  
-                        unset($notdone[$name]);
1109  
-                    }
1110 1128
                 }
  1129
+            
  1130
+                $sorted[$name] = $name;
  1131
+                unset($notdone[$name]);
1111 1132
             }
1112 1133
         }
1113 1134
 

0 notes on commit 21121be

Please sign in to comment.
Something went wrong with that request. Please try again.