Skip to content

Commit ce6ffaf

Browse files
committed
Fix default source
1 parent 610b95e commit ce6ffaf

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/class-dependency-manager.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ class dependency_manager
1212
public const DEPXML = "dependencies.xml";
1313

1414
public static $log_dump = false;
15-
static function trace(...$msgs) { if (class_exists("php_logger")) php_logger::trace(...$msgs); else if (self::$log_dump) print_r($msgs); }
16-
static function debug(...$msgs) { if (class_exists("php_logger")) php_logger::debug(...$msgs); else if (self::$log_dump) print_r($msgs); }
15+
private static function dump_log(...$msgs) { if (!self::$log_dump) return; foreach($msgs as $m) if (is_string($m)) print($m); else print_r($m);}
16+
static function trace(...$msgs) { if (class_exists("php_logger")) php_logger::trace(...$msgs); else self::dump_log(...$msgs); }
17+
static function debug(...$msgs) { if (class_exists("php_logger")) php_logger::debug(...$msgs); else self::dump_log(...$msgs); }
1718

1819
public function __construct($fnames = null, $wdir = null)
1920
{
@@ -53,7 +54,11 @@ protected function ensure_config()
5354
@mkdir($this->workingDir, 0777);
5455
if (!file_exists($this->workingDir)) throw new Exception("Cannot secure working folder: $this->workingDir");
5556

56-
if ($this->sources == null) array($this->default_source());
57+
self::trace("Sources: ", gettype($this->sources));
58+
if ($this->sources == null) $this->sources =
59+
array($this->default_source());
60+
self::trace("Sources: ", gettype($this->sources));
61+
self::trace("Sources: ", $this->sources);
5762

5863
if (is_array($this->sources))
5964
foreach($this->sources as $source)
@@ -69,10 +74,27 @@ protected function load_internal_resources()
6974

7075
public function default_source()
7176
{
72-
if (file_exists($v = ($this->workingDir . "/" . self::DEPXML))) return $v;
73-
if (file_exists($v = (__DIR__ . "/" . self::DEPXML))) return $v;
77+
$phar = strpos(__FILE__, ".phar") !== false;
78+
self::debug("dependency_manager::default_source, phar=$phar");
79+
80+
if (!$phar) {
81+
if (file_exists($v = (__DIR__ . "/" . self::DEPXML))) return $v;
82+
if (file_exists($v = ($this->workingDir . "/" . self::DEPXML))) return $v;
83+
}
84+
85+
$d = $this->workingDir;;
86+
while (strlen($d) >= strlen($_SERVER["DOCUMENT_ROOT"])) {
87+
self::trace("default_source, d=$d");
88+
if ($d == ".") break;
89+
$dd = dirname($d);
90+
if ($dd == $d) break;
91+
$d = $dd;
92+
if (file_exists($v = ("$d/" . self::DEPXML))) return $v;
93+
}
94+
7495
$d = realpath(__DIR__);
7596
while (strlen($d) >= strlen($_SERVER["DOCUMENT_ROOT"])) {
97+
self::trace("default_source, d=$d");
7698
if ($d == ".") break;
7799
$dd = dirname($d);
78100
if ($dd == $d) break;

0 commit comments

Comments
 (0)