|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Buttress\Concrete\Locator; |
|
4
|
|
|
|
|
5
|
|
|
use Buttress\Concrete\Locator\Detector\Detector; |
|
6
|
|
|
use Buttress\Concrete\Locator\Detector\LegacyDetector; |
|
7
|
|
|
use Buttress\Concrete\Locator\Detector\ModernDetector; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* concrete5 installation locator |
|
11
|
|
|
*/ |
|
12
|
|
|
class Locator |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** @var \Buttress\Concrete\Locator\Site */ |
|
16
|
|
|
protected $location; |
|
17
|
|
|
|
|
18
|
|
|
/** @var Detector[] */ |
|
19
|
|
|
protected $detectors = []; |
|
20
|
|
|
|
|
21
|
|
|
/** @var \Buttress\Concrete\Locator\WebrootLocator */ |
|
22
|
|
|
protected $locator; |
|
23
|
|
|
|
|
24
|
12 |
|
public function __construct(WebrootLocator $locator, ModernDetector $modern, LegacyDetector $legacy) |
|
25
|
|
|
{ |
|
26
|
12 |
|
$this->locator = $locator; |
|
27
|
12 |
|
$this->addDetector($modern); |
|
28
|
12 |
|
$this->addDetector($legacy); |
|
29
|
12 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Add a detector to detect with |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Buttress\Concrete\Locator\Detector\Detector $detector |
|
35
|
|
|
*/ |
|
36
|
12 |
|
public function addDetector(Detector $detector) |
|
37
|
|
|
{ |
|
38
|
12 |
|
$this->detectors[] = $detector; |
|
39
|
12 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Locate the concrete5 core we're wanting |
|
43
|
|
|
* |
|
44
|
|
|
* @param string|null $currentPath If null is passed, getcwd will be used. |
|
45
|
|
|
* @param bool $recursive |
|
46
|
|
|
* @return \Buttress\Concrete\Locator\Site|null |
|
47
|
9 |
|
*/ |
|
48
|
|
|
public function getLocation($currentPath = null, $recursive = true) |
|
49
|
|
|
{ |
|
50
|
9 |
|
// If we weren't given a currentpath, just use the cwd |
|
51
|
|
|
if (!$currentPath) { |
|
|
|
|
|
|
52
|
|
|
$currentPath = getcwd(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
9 |
|
// If we have found a webroot |
|
56
|
|
|
if ($path = $this->locator->searchWorkingDirectory($currentPath, $recursive)) { |
|
57
|
9 |
|
// Check each of the detectors to see if we've found a concrete5 site |
|
58
|
9 |
|
foreach ($this->detectors as $detector) { |
|
59
|
6 |
|
if ($result = $detector->detect($path)) { |
|
|
|
|
|
|
60
|
|
|
return $result; |
|
61
|
4 |
|
} |
|
62
|
2 |
|
} |
|
63
|
|
|
} |
|
64
|
3 |
|
|
|
65
|
|
|
return null; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: