function DrupalFinder::findAndValidateRoots
Determine if a valid Drupal root exists.
In addition, set any valid path properties if they are found.
Parameters
$path: The starting path to search from.
Return value
bool True if all roots were discovered and validated. False otherwise.
1 call to DrupalFinder::findAndValidateRoots()
- DrupalFinder::discoverRoots in vendor/
webflo/ drupal-finder/ src/ DrupalFinder.php - Discover all valid paths.
File
-
vendor/
webflo/ drupal-finder/ src/ DrupalFinder.php, line 185
Class
Namespace
DrupalFinderCode
protected function findAndValidateRoots($path) {
if (!empty($path) && is_dir($path) && file_exists($path . '/autoload.php') && file_exists($path . '/' . $this->getComposerFileName())) {
// Additional check for the presence of core/composer.json to
// grant it is not a Drupal 7 site with a base folder named "core".
$candidate = 'core/includes/common.inc';
if (file_exists($path . '/' . $candidate) && file_exists($path . '/core/core.services.yml')) {
if (file_exists($path . '/core/misc/drupal.js') || file_exists($path . '/core/assets/js/drupal.js')) {
$this->composerRoot = $path;
$this->drupalRoot = $path;
$this->vendorDir = $this->composerRoot . '/vendor';
}
}
}
if (!empty($path) && is_dir($path) && file_exists($path . '/' . $this->getComposerFileName())) {
$json = json_decode(file_get_contents($path . '/' . $this->getComposerFileName()), true);
if (is_null($json)) {
throw new \Exception('Unable to decode ' . $path . '/' . $this->getComposerFileName());
}
if (is_array($json)) {
if (isset($json['extra']['installer-paths']) && is_array($json['extra']['installer-paths'])) {
foreach ($json['extra']['installer-paths'] as $install_path => $items) {
if (in_array('type:drupal-core', $items) || in_array('drupal/core', $items) || in_array('drupal/drupal', $items)) {
$this->composerRoot = $path;
// @todo: Remove this magic and detect the major version instead.
if ($install_path == 'core' || isset($json['name']) && $json['name'] == 'drupal/drupal') {
$install_path = '';
}
elseif (substr($install_path, -5) == '/core') {
$install_path = substr($install_path, 0, -5);
}
$this->drupalRoot = rtrim($path . '/' . $install_path, '/');
$this->vendorDir = $this->composerRoot . '/vendor';
}
}
}
}
}
if ($this->composerRoot && file_exists($this->composerRoot . '/' . $this->getComposerFileName())) {
$json = json_decode(file_get_contents($path . '/' . $this->getComposerFileName()), true);
if (is_array($json) && isset($json['config']['vendor-dir'])) {
$this->vendorDir = $this->composerRoot . '/' . $json['config']['vendor-dir'];
}
}
return $this->allPathsDiscovered();
}