Skip to content

Commit c55ec9c

Browse files
committed
Fix default source
1 parent 6662e5f commit c55ec9c

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/autoload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
<?php
22

3+
require_once(__DIR__ . "/class-dependency-manager.php");

src/class-dependency-manager.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@ public function __construct($fnames = null, $wdir = null)
2525
// print "\n<br/>Loading sources..";
2626
$this->load_sources();
2727
// print "\n<br/>Loaded sources..";
28-
}
28+
$this->include_autoloads();
29+
// print "\n<br/>Loaded autoloads..";
30+
}
2931

3032
public function default_source() {
3133
if (file_exists( $v = ($this->workingDir . "/" . dependency_manager::DEPXML))) return $v;
3234
if (file_exists( $v = (__DIR__ . "/" . dependency_manager::DEPXML))) return $v;
33-
$d = __DIR__;
35+
$d = realpath(__DIR__);
3436
while (strlen($d) >= strlen($_SERVER["DOCUMENT_ROOT"])) {
35-
$d = dirname($d);
36-
print ("\nd=$d");
37+
if ($d == ".") break;
38+
$dd = dirname($d);
39+
if ($dd == $d) break;
40+
$d = $dd;
41+
//print ("\nd=$d");
3742
if (file_exists( $v = ("$d/" . dependency_manager::DEPXML))) return $v;
3843
}
3944
return __DIR__ . "/" . dependency_manager::DEPXML;
@@ -43,9 +48,10 @@ public function default_source() {
4348
public function load_sources() {
4449
require_once("phar://" . __DIR__ . "/xml-file.phar/src/class-xml-file.php");
4550
$this->dependencies = array();
46-
foreach($this->sources as $source) {
47-
$this->dependencies[] = new xml_file($source);
48-
}
51+
if (is_array($this->sources))
52+
foreach($this->sources as $source) {
53+
$this->dependencies[] = new xml_file($source);
54+
}
4955
$this->ensure_dependencies();
5056
}
5157

@@ -164,6 +170,8 @@ public function include($fname)
164170
public function include_once($fname) { return $this->include($fname); }
165171
public function require($fname) { return $this->include($fname); }
166172
public function require_once($fname) { return $this->include($fname); }
173+
174+
public function include_autoloads() { $this->include("autoload.php"); }
167175
}
168176

169177
if (!function_exists("dependency_manager")) {

tests/class-dependency-manager-test.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ public function testLoadDependencyManager(): void
3232
$this->assertEquals(1, sizeof($obj->dependencies));
3333
$this->assertEquals(4, sizeof($obj->resources));
3434
}
35+
36+
public function testDefaultSource()
37+
{
38+
$result = dependency_manager() -> default_source();
39+
40+
$this->assertTrue(strpos($result, "dependencies.xml") !== false);
41+
}
3542
}

0 commit comments

Comments
 (0)