Open kunalsahu-git opened 1 month ago
`<?php
/**
/**
Use \DrupalFinder\DrupalFinderComposerRuntime instead. */ class DrupalFinder { /**
/**
/**
/**
/**
/**
/**
/**
@todo Make $start_path mandatory in v2. */ public function __construct($start_path_string = null) { // Initialize path variables to false, indicating their locations are // not yet known. $this->start_path_string = $start_path_string; $this->drupalRoot = false; $this->composerRoot = false; $this->vendorDir = false;
// If a starting path was provided, attempt to locate and set path // variables. if (!empty($start_path)) { $this->discoverRoots($start_path); } }
/**
/**
The path to the Drupal root, if it was discovered. False otherwise. */ public function getDrupalRoot() { $environment_path = $this->getValidEnvironmentVariablePath(self::ENV_DRUPAL_ROOT);
return !empty($environment_path) ? $environment_path : $this->drupalRoot; }
/**
/**
/**
@throws \Exception */ protected function discoverRoots($start_path) { // Since we are discovering, reset all path variables. $this->drupalRoot = false; $this->composerRoot = false; $this->vendorDir = false;
foreach (array(true, false) as $follow_symlinks) { $path = $start_path; if ($follow_symlinks && is_string($path) && is_link((string) $path)) { $path = realpath($path); }
// Check the start path.
if ($this->findAndValidateRoots($path)) {
return;
} else {
// Move up dir by dir and check each.
while ($path = $this->shiftPathUp($path)) {
if ($follow_symlinks && is_link($path)) {
$path = realpath($path);
}
if ($this->findAndValidateRoots($path)) {
return;
}
}
}
} }
/**
True if all roots were discovered and validated. False otherwise. */ protected function findAndValidateRoots($path) { $pathString = $path; if (!empty($pathString) && is_dir($pathString) && file_exists($pathString . '/autoload.php') && file_exists($pathString . '/' . $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(); }
/**
/**
/**
/**
/**
Parent path of given path or false when $path is filesystem root */ private function shiftPathUp($path) { $parent = dirname($path);
return in_array($parent, ['.', $path]) ? false : $parent; }
} `
Changing the code to this lets it work.
PR has been raised to fix this issue. https://github.com/webflo/drupal-finder/pull/71
ddev drush cr PHP Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php:153 Stack trace:
0 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(153): is_link(Object(Drush\Config\Environment))
1 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(75): DrupalFinder\DrupalFinder->discoverRoots(Object(Drush\Config\Environment))
2 /var/www/html/vendor/drush/drush/src/Preflight/Preflight.php(311): DrupalFinder\DrupalFinder->__construct(Object(Drush\Config\Environment))
3 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->preflight(Array)
4 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
5 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
6 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
7 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
8 {main}
thrown in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php on line 153
Fatal error: Uncaught TypeError: is_link(): Argument #1 ($filename) must be of type string, Drush\Config\Environment given in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php:153 Stack trace:
0 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(153): is_link(Object(Drush\Config\Environment))
1 /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php(75): DrupalFinder\DrupalFinder->discoverRoots(Object(Drush\Config\Environment))
2 /var/www/html/vendor/drush/drush/src/Preflight/Preflight.php(311): DrupalFinder\DrupalFinder->__construct(Object(Drush\Config\Environment))
3 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(58): Drush\Preflight\Preflight->preflight(Array)
4 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
5 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
6 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
7 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
8 {main}
thrown in /var/www/html/vendor/webflo/drupal-finder/src/DrupalFinder.php on line 153