-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPath.php
More file actions
203 lines (186 loc) · 6.11 KB
/
Path.php
File metadata and controls
203 lines (186 loc) · 6.11 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* Arikaim
*
* @link http://www.arikaim.com
* @copyright Copyright (c) Konstantin Atanasov <info@arikaim.com>
* @license http://www.arikaim.com/license
*
*/
namespace Arikaim\Core\Utils;
/**
* All path constants and helpers
*/
class Path
{
const VIEW_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR;
const BIN_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR;
const EXTENSIONS_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR;
const MODULES_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;
const SERVICES_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'services' . DIRECTORY_SEPARATOR;
const CONFIG_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
const CACHE_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
const LOGS_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR;
const STORAGE_PATH = APP_PATH . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR;
const LIBRARY_PATH = Self::VIEW_PATH . 'library' . DIRECTORY_SEPARATOR;
const TEMPLATES_PATH = Self::VIEW_PATH . 'templates' . DIRECTORY_SEPARATOR;
const COMPONENTS_PATH = Self::VIEW_PATH . 'components' . DIRECTORY_SEPARATOR;
const VIEW_CACHE_PATH = Self::CACHE_PATH . 'views' . DIRECTORY_SEPARATOR;
const STORAGE_TEMP_PATH = Self::STORAGE_PATH . 'temp' . DIRECTORY_SEPARATOR;
const STORAGE_BACKUP_PATH = Self::STORAGE_PATH . 'backup' . DIRECTORY_SEPARATOR;
const STORAGE_REPOSITORY_PATH = Self::STORAGE_PATH . 'repository' . DIRECTORY_SEPARATOR;
const STORAGE_PUBLIC_PATH = Self::STORAGE_PATH . 'public' . DIRECTORY_SEPARATOR;
const COMPOSER_VENDOR_PATH = ROOT_PATH . BASE_PATH . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR;
/**
* Get template theme path
*
* @param string $templateName
* @return string
*/
public static function getTemplateThemePath(string $templateName): string
{
return Path::TEMPLATES_PATH . $templateName . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR;
}
/**
* Get macro path
*
* @param string $macroName
* @param string $template
* @return string
*/
public static function getMacroPath(string $macroName, string $template): string
{
return DIRECTORY_SEPARATOR . $template . DIRECTORY_SEPARATOR . 'macros' . DIRECTORY_SEPARATOR . $macroName;
}
/**
* Get extension config path
*
* @param string $name
* @return string
*/
public static function getExtensionConfigPath(string $name): string
{
return Path::EXTENSIONS_PATH . $name . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
}
/**
* Get extension path
*
* @param string $name
* @return string
*/
public static function getExtensionPath(string $name): string
{
return Path::EXTENSIONS_PATH . $name . DIRECTORY_SEPARATOR;
}
/**
* Get module config path
*
* @param string $name
* @return string
*/
public static function getModuleConfigPath(string $name): string
{
return Path::MODULES_PATH . $name . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
}
/**
* Get storage relative path
*
* @param string $path
* @return string
*/
public static function getStorageRelativePath(string $path): string
{
return \str_replace(Self::STORAGE_PATH,'',$path);
}
/**
* Return relative path from full path
*
* @param string $path
* @param bool $appPath
* @return string
*/
public static function getRelativePath(string $path, bool $appPath = true): string
{
if (\defined('APP_PATH') == false) {
return $path;
}
$rootPath = ($appPath == true) ? APP_PATH : ROOT_PATH . BASE_PATH;
return \str_replace($rootPath,'',$path);
}
/**
* Set app path
*
* @param string $path
* @return void
*/
public static function setAppPath(string $path): void
{
if (\defined('APP_PATH') == false) {
\define('APP_PATH',ROOT_PATH . BASE_PATH . DIRECTORY_SEPARATOR . $path);
}
}
/**
* Get module path
*
* @param string $name
* @return string
*/
public static function getModulePath(string $name): string
{
return Self::MODULES_PATH . $name . DIRECTORY_SEPARATOR;
}
/**
* Get library file path
*
* @param string $library
* @param string $fileName
* @return string
*/
public static function getLibraryFilePath(string $library, string $fileName): string
{
return Self::getLibraryPath($library) . $fileName;
}
/**
* Get library path
*
* @param string $library
* @return string
*/
public static function getLibraryPath(string $library): string
{
return Self::LIBRARY_PATH . $library . DIRECTORY_SEPARATOR;
}
/**
* Get extension macros relative path
*
* @param string $extension
* @return string
*/
public static function getExtensionMacrosRelativePath(string $extension): string
{
return $extension . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR . 'macros' . DIRECTORY_SEPARATOR;
}
/**
* Return current script path
*
* @return string
*/
public static function getScriptPath(): string
{
return \realpath(\dirname(__FILE__));
}
/**
* Add path
*
* @param string $path
* @param string $add
* @return string
*/
public static function addPath(string $path, string $add): string
{
if (\substr($path,-1) == DIRECTORY_SEPARATOR) {
return ($add == DIRECTORY_SEPARATOR) ? $path : $path . $add;
}
return ($add == DIRECTORY_SEPARATOR) ? $path . $add : $path . DIRECTORY_SEPARATOR . $add;
}
}