-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDir.php
executable file
·81 lines (70 loc) · 1.88 KB
/
Dir.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
namespace MaplePHP\Http;
use MaplePHP\Http\Interfaces\DirInterface;
use MaplePHP\Http\Interfaces\DirHandlerInterface;
class Dir implements DirInterface
{
private $dir;
private $getRootDir;
private $handler;
public function __construct($dir, ?string $getRootDir = null)
{
$this->dir = $dir;
$this->getRootDir = $getRootDir;
}
/**
* Not required but recommended. You can pass on Directory shortcuts to the class
* E.g. getPublic, getCss
* @param DirHandlerInterface $handler
*/
public function setHandler(DirHandlerInterface $handler): void
{
$this->handler = $handler;
}
/**
* Get root dir
* @param string $path
* @return string
*/
public function getDir(string $path = ""): string
{
return $this->dir . $path;
}
/**
* Get root dir
* @param string $path
* @return string
*/
public function getRoot(string $path = ""): string
{
return $this->getRootDir.$path;
}
/**
* Get log dir
* @param string $path
* @return string
*/
public function getLogs(string $path = ""): string
{
if(!is_null($this->handler)) {
return $this->handler->getLogs($path);
}
return $this->getRoot("storage/logs/" . $path);
}
/**
* Access handler
* @param string $method
* @param array $args
* @return mixed
* @psalm-taint-sink
*/
public function __call($method, $args): mixed
{
if (!is_null($this->handler) && method_exists($this->handler, $method)) {
return call_user_func_array([$this->handler, $method], $args);
} else {
throw new \BadMethodCallException("The method ({$method}) does not exist in \"".__CLASS__."\" (DirInterface or DirHandlerInterface).", 1);
}
}
}