1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace VersionTool\Inspectors; |
4
|
|
|
|
5
|
|
|
use VersionTool\Info\VersionInfo; |
6
|
|
|
use VersionTool\Util\ComposerInfo; |
7
|
|
|
|
8
|
|
|
class Drupal8Inspector implements InspectorInterface |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @inheritdoc |
12
|
|
|
*/ |
13
|
|
|
public function valid(ComposerInfo $composer_info) |
14
|
|
|
{ |
15
|
|
|
// This cannot be a Drupal 8 site unless there is a composer.json |
16
|
|
|
// file at the specified path |
17
|
|
|
if (!$composer_info->valid()) { |
18
|
|
|
return false; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
$candidates = []; |
22
|
|
|
$project_root = $composer_info->projectRoot(); |
23
|
|
|
|
24
|
|
|
// Determine if there is a relocated drupal root. |
25
|
|
|
$core = $composer_info->pathForType('type:drupal-core'); |
26
|
|
|
if ($core) { |
27
|
|
|
$candidates[] = dirname("$project_root/$core"); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
$candidates[] = $project_root; |
31
|
|
|
|
32
|
|
|
foreach ($candidates as $drupal_root) { |
33
|
|
|
$info = $this->isDrupalRoot($composer_info, $drupal_root); |
34
|
|
|
if ($info) { |
35
|
|
|
return $info; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Create an info object if there is a valid drupal root at the |
43
|
|
|
* specified path. |
44
|
|
|
*/ |
45
|
|
|
protected function isDrupalRoot(ComposerInfo $composer_info, $drupal_root) |
46
|
|
|
{ |
47
|
|
|
if (file_exists("$drupal_root/autoload.php")) { |
48
|
|
|
// Additional check for the presence of core/core.services.yml to |
49
|
|
|
// grant it is not a Drupal 7 site with a base folder named "core". |
50
|
|
|
$candidate = 'core/includes/common.inc'; |
51
|
|
|
if (file_exists($drupal_root . '/' . $candidate) && file_exists($drupal_root . '/core/core.services.yml')) { |
52
|
|
|
if (file_exists($drupal_root . '/core/misc/drupal.js') || file_exists($drupal_root . '/core/assets/js/drupal.js')) { |
53
|
|
|
return new VersionInfo('Drupal', $composer_info, $drupal_root, '/core/lib/Drupal.php', "#const VERSION = '([0-9.a-z-]*)';#m"); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
return false; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|