Skip to content

Commit

Permalink
Allow for alternate name for composer.json. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman authored and webflo committed Oct 24, 2017
1 parent 3216448 commit 8a7886c
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/DrupalFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function shiftPathUp($path)
*/
protected function isValidRoot($path)
{
if (!empty($path) && is_dir($path) && file_exists($path . '/autoload.php') && file_exists($path . '/composer.json')) {
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';
Expand All @@ -97,9 +97,9 @@ protected function isValidRoot($path)
}
}
}
if (!empty($path) && is_dir($path) && file_exists($path . '/composer.json')) {
if (!empty($path) && is_dir($path) && file_exists($path . '/' . $this->getComposerFileName())) {
$json = json_decode(
file_get_contents($path . '/composer.json'),
file_get_contents($path . '/' . $this->getComposerFileName()),
true
);
if (is_array($json)) {
Expand All @@ -122,9 +122,9 @@ protected function isValidRoot($path)
}
}
}
if ($this->composerRoot && file_exists($this->composerRoot . '/composer.json')) {
if ($this->composerRoot && file_exists($this->composerRoot . '/' . $this->getComposerFileName())) {
$json = json_decode(
file_get_contents($path . '/composer.json'),
file_get_contents($path . '/' . $this->getComposerFileName()),
true
);
if (is_array($json) && isset($json['config']['vendor-dir'])) {
Expand All @@ -151,6 +151,14 @@ public function getComposerRoot()
return $this->composerRoot;
}

/**
* @return string
*/
protected function getComposerFileName()
{
return trim(getenv('COMPOSER')) ?: 'composer.json';
}

/**
* @return string
*/
Expand Down

0 comments on commit 8a7886c

Please sign in to comment.