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
|
|
|
* Constructor |
12
|
|
|
* |
13
|
|
|
* @param array $defaultOption : The default options from BFW Application |
14
|
|
|
* @param array $options : The options declared by user |
15
|
|
|
*/ |
16
|
|
|
public function __construct($defaultOption, $options) |
17
|
|
|
{ |
18
|
|
|
parent::__construct($defaultOption, $options); |
19
|
|
|
|
20
|
|
|
//Search root directory if is not declared |
21
|
|
|
if ($this->options['rootDir'] === null) { |
22
|
|
|
$this->options['rootDir'] = $this->searchRootDir(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
//Search the vendor directory if is not declared |
26
|
|
|
if ($this->options['vendorDir'] === null) { |
27
|
|
|
$this->options['vendorDir'] = $this->searchVendorDir(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
//Get the length of paths to get the last character position |
31
|
|
|
$rootDirPosLastLetter = strlen($this->options['rootDir']) - 1; |
32
|
|
|
$vendorDirPosLastLetter = strlen($this->options['vendorDir']) - 1; |
33
|
|
|
|
34
|
|
|
//If the last caracter is not a "/", add "/" at the end of the path |
35
|
|
|
|
36
|
|
|
if ($this->options['rootDir'][$rootDirPosLastLetter] !== '/') { |
37
|
|
|
$this->options['rootDir'] .= '/'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
if ($this->options['vendorDir'][$vendorDirPosLastLetter] !== '/') { |
41
|
|
|
$this->options['vendorDir'] .= '/'; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Find the vendor directory from the path of this file |
47
|
|
|
* (In theory we are into) |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
|
|
protected function searchVendorDir() |
52
|
|
|
{ |
53
|
|
|
if (PHP_VERSION_ID >= 70000) { |
54
|
|
|
return dirname(__FILE__, 5).'/'; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$rootDir = __FILE__; |
58
|
|
|
for ($i = 1; $i <= 5; $i++) { |
59
|
|
|
$rootDir = dirname($rootDir); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $rootDir.'/'; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Find the root directory from the vendor directory |
67
|
|
|
* In theory of the vendor directory is on the root directory. |
68
|
|
|
* If not, the user can define path for vendor and root directory. |
69
|
|
|
* |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function searchRootDir() |
73
|
|
|
{ |
74
|
|
|
return dirname($this->searchVendorDir()).'/'; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|