forked from pwarelis/ScriptCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathManager.php
More file actions
38 lines (32 loc) · 944 Bytes
/
PathManager.php
File metadata and controls
38 lines (32 loc) · 944 Bytes
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
<?php
namespace ScriptCompiler;
class PathManager {
protected $aliases = array();
protected $docRoot;
public function __construct($aliasMap = array(), $documentRoot = null) {
$this->addAliasMap($aliasMap);
$this->setDocumentRoot($documentRoot);
}
public function addAliasMap($map) {
foreach ($map as $alias => $path) {
$check = realpath($path);
if (!$check) throw new \Exception("Alias path does not exist: {$path}");
$this->aliases[$alias] = $check;
}
}
public function setDocumentRoot($path) {
if (!$path) $path = $_SERVER["DOCUMENT_ROOT"];
// $this->docRoot = realpath($path);
$this->docRoot = $path;
if (!$this->docRoot) {
throw new \Exception("Document root is not a valid path: {$path}");
}
}
public function getPath($url) {
foreach ($this->aliases as $alias => $path) {
if (strpos($url, $alias) !== 0) continue;
return $path . basename($url);
}
return $this->docRoot . $url;
}
}