@@ -24,7 +24,7 @@ public function __construct($fnames = null, $wdir = null)
24
24
// print "\n<br/>Initializing..";
25
25
$ this ->ensure_config ();
26
26
$ this ->load_internal_resources ();
27
- $ this ->include_autoloads ();
27
+ $ this ->include_autoloads (); // for the internal resources, if needed. Others will follow.
28
28
// print "\n<br/>Loading sources..";
29
29
$ this ->load_sources ();
30
30
// print "\n<br/>Loaded sources..";
@@ -49,7 +49,7 @@ protected function ensure_config()
49
49
50
50
protected function internal_resource_list () {
51
51
$ d = (strpos (__FILE__ , ".phar " ) === false ? __DIR__ : "phar:// " . __FILE__ . "/src " );
52
- $ f = $ d . "/ " . $ this ::DEPXML ;
52
+ $ f = $ d . "/ " . self ::DEPXML ;
53
53
// print "\n<br/>source::internal_resource_list - f=$f";
54
54
$ src = file_get_contents ($ f );
55
55
$ src = str_replace ('<?xml version="1.0" ?> ' , "" , $ src );
@@ -76,7 +76,6 @@ protected function internal_resource_list() {
76
76
$ internal_resources [] = $ ref ;
77
77
}
78
78
79
-
80
79
// print_r($internal_resources);die();
81
80
return $ internal_resources ;
82
81
}
@@ -90,31 +89,36 @@ protected function load_internal_resources()
90
89
public function default_source ()
91
90
{
92
91
if (file_exists ($ v = ($ this ->workingDir . "/ " . dependency_manager::DEPXML ))) return $ v ;
93
- if (file_exists ($ v = (__DIR__ . "/ " . dependency_manager ::DEPXML ))) return $ v ;
92
+ if (file_exists ($ v = (__DIR__ . "/ " . self ::DEPXML ))) return $ v ;
94
93
$ d = realpath (__DIR__ );
95
94
while (strlen ($ d ) >= strlen ($ _SERVER ["DOCUMENT_ROOT " ])) {
96
95
if ($ d == ". " ) break ;
97
96
$ dd = dirname ($ d );
98
97
if ($ dd == $ d ) break ;
99
98
$ d = $ dd ;
100
99
//print ("\nd=$d");
101
- if (file_exists ($ v = ("$ d/ " . dependency_manager ::DEPXML ))) return $ v ;
100
+ if (file_exists ($ v = ("$ d/ " . self ::DEPXML ))) return $ v ;
102
101
}
103
- return __DIR__ . "/ " . dependency_manager ::DEPXML ;
102
+ return __DIR__ . "/ " . self ::DEPXML ;
104
103
}
105
104
106
105
public function load_sources ()
107
106
{
107
+ $ sources_loaded = array ();
108
108
$ this ->dependencies = array ();
109
- // print "\n<br/>load_sources()";
110
- if (is_array ($ this ->sources ))
111
- foreach ($ this ->sources as $ source )
112
- {
113
- // print "\n<br/>load_sources(), loading source=$source";
114
- $ this ->dependencies [] = new xml_file ($ source );
109
+ // print "\n<br/>load_sources()";
110
+ if (is_array ($ this ->sources )) {
111
+ $ this ->sources = array_unique ($ this ->sources );
112
+ while (count ($ to_load = array_diff ($ this ->sources , $ sources_loaded )) > 0 ) {
113
+ foreach ($ to_load as $ source ) {
114
+ // print "\n<br/>load_sources(), loading source=$source";
115
+ $ sources_loaded [] = $ source ;
116
+ $ this ->dependencies [] = new xml_file ($ source );
117
+ }
115
118
}
116
- // print "\n<br/>load_sources(), ensuring dependencies...";
117
- $ this ->ensure_dependencies ();
119
+ }
120
+ // print "\n<br/>load_sources(), ensuring dependencies...";
121
+ $ this ->ensure_dependencies ();
118
122
}
119
123
120
124
public function ensure_dependencies ()
@@ -218,7 +222,7 @@ public function fetch_dependency($url, $local_file)
218
222
// print("\n$result");
219
223
// print("\n================");
220
224
if ($ result === false || $ result == "" ) {
221
- throw new Excpetion ("Error requiring dependency: $ url - $ err " );
225
+ throw new Exception ("Error requiring dependency: $ url - $ err " );
222
226
// print("<br/>ERROR REQURING DEPENDENCY: $url - $err");
223
227
// die();
224
228
}
@@ -233,12 +237,12 @@ public function process_dependency($resourceFile, $type, $name) {
233
237
switch ($ type )
234
238
{
235
239
case "phar " :
236
- $ this ->scan_phar_files ($ resourceFile , $ name );
240
+ $ this ->scan_phar_file ($ resourceFile , $ name );
237
241
break ;
238
242
}
239
243
}
240
244
241
- public function scan_phar_files ($ phar_file , $ name )
245
+ public function scan_phar_file ($ phar_file , $ name )
242
246
{
243
247
// print("\n<br/>Reading PHAR: $phar_file\n");
244
248
$ phar = new Phar ($ phar_file , FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME , $ name );
@@ -247,9 +251,14 @@ public function scan_phar_files($phar_file, $name)
247
251
$ basepath = "phar:// " . $ phar ->getPath () . "/ " ;
248
252
foreach (new RecursiveIteratorIterator ($ phar ) as $ file ) {
249
253
$ filename = str_replace ($ basepath , "" , $ file ->getPath () . '/ ' . $ file ->getFilename ());
250
- // print_r ("\n$basepath");
251
- // print_r ("\nfilename=$filename");
254
+ // print ("\n$basepath");
255
+ // print ("\nfilename=$filename");
252
256
$ this ->resources [$ filename ] = $ name ;
257
+
258
+ if ($ filename == self ::DEPXML ) {
259
+ // print "\n<br/>Found module dependencies: " . $file->getPath() . '/' . $file->getFilename();
260
+ $ this ->sources [] = $ file ->getPath () . '/ ' . $ file ->getFilename ();
261
+ }
253
262
}
254
263
}
255
264
0 commit comments