/
Base.php
72 lines (61 loc) · 2.1 KB
/
Base.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
<?php
namespace mcanan\framework;
/**
* Abstract base class for all classes
*/
abstract class Base
{
protected function loadHelper($helperName)
{
if (is_array($helperName)) {
foreach ($helperName as $h) {
$this->loadHelper($h);
}
return $this;
}
if (file_exists($this->getDocumentRoot().'/app/helpers/'.strtolower($helperName).'.php')) {
require_once $this->getDocumentRoot().'/app/helpers/'.strtolower($helperName).'.php';
} elseif (file_exists(__DIR__.'/helpers/'.strtolower($helperName).'.php')) {
require_once __DIR__.'/helpers/'.strtolower($helperName).'.php';
}
return $this;
}
protected function loadLibrary($libraryName, $name = '')
{
if (is_array($libraryName)) {
foreach ($libraryName as $l) {
$this->loadLibrary($l);
}
return $this;
}
if (empty($name)) {
$name = $libraryName;
}
if (file_exists($this->getDocumentRoot().'/app/libraries/'.strtolower($libraryName).'.php')) {
require_once $this->getDocumentRoot().'/app/libraries/'.strtolower($libraryName).'.php';
$libraryName = "\\mcanan\\app\\libraries\\".$libraryName;
$this->$name = new $libraryName();
} elseif (file_exists(__DIR__.'/libraries/'.strtolower($libraryName).'.php')) {
require_once __DIR__.'/libraries/'.strtolower($libraryName).'.php';
$libraryName = "\\mcanan\\framework\\libraries\\".$libraryName;
$this->$name = new $libraryName();
}
return $this;
}
protected function getDocumentRoot()
{
if (defined("CONF_DOCUMENT_ROOT")) {
return CONF_DOCUMENT_ROOT;
} else {
if (defined("CONF_URL_BASE")) {
return $_SERVER["DOCUMENT_ROOT"].'/'.CONF_URL_BASE;
} else {
return $_SERVER["DOCUMENT_ROOT"];
}
}
}
protected function getFullPath($url)
{
return getDocumentRoot().$url;
}
}