1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BFW\Core; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class to define options for BFW Core |
7
|
|
|
*/ |
8
|
|
|
class Options extends \BFW\Options |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Search the root and vendor paths if they are not declared. |
12
|
|
|
* |
13
|
|
|
* @return $this |
14
|
|
|
*/ |
15
|
|
|
public function searchPaths(): self |
16
|
|
|
{ |
17
|
|
|
//Search root directory if is not declared |
18
|
|
|
if ($this->options['rootDir'] === null) { |
19
|
|
|
$this->options['rootDir'] = $this->searchRootDir(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
//Search the vendor directory if is not declared |
23
|
|
|
if ($this->options['vendorDir'] === null) { |
24
|
|
|
$this->options['vendorDir'] = $this->searchVendorDir(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
return $this; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Check root and vendor path declared or found. |
32
|
|
|
* |
33
|
|
|
* @return $this |
34
|
|
|
*/ |
35
|
|
|
public function checkPaths(): self |
36
|
|
|
{ |
37
|
|
|
if (empty($this->options['rootDir'])) { |
38
|
|
|
$this->options['rootDir'] .= '/'; |
39
|
|
|
} else { |
40
|
|
|
$rootDirPosLastChar = strlen($this->options['rootDir']) - 1; |
41
|
|
|
|
42
|
|
|
if ($this->options['rootDir'][$rootDirPosLastChar] !== '/') { |
43
|
|
|
$this->options['rootDir'] .= '/'; |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if (empty($this->options['vendorDir'])) { |
48
|
|
|
$this->options['vendorDir'] .= '/'; |
49
|
|
|
} else { |
50
|
|
|
$vendorDirPosLastChar = strlen($this->options['vendorDir']) - 1; |
51
|
|
|
|
52
|
|
|
if ($this->options['vendorDir'][$vendorDirPosLastChar] !== '/') { |
53
|
|
|
$this->options['vendorDir'] .= '/'; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Find the vendor directory from the path of this file |
62
|
|
|
* (In theory we are into) |
63
|
|
|
* |
64
|
|
|
* @return string |
65
|
|
|
*/ |
66
|
|
|
protected function searchVendorDir(): string |
67
|
|
|
{ |
68
|
|
|
return dirname(__FILE__, 4).'/'; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Find the root directory from the vendor directory |
73
|
|
|
* In theory of the vendor directory is on the root directory. |
74
|
|
|
* If not, the user can define path for vendor and root directory. |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function searchRootDir(): string |
79
|
|
|
{ |
80
|
|
|
return dirname($this->searchVendorDir()).'/'; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|