protected function ensureProjectRoot()
{
if (!($this->rootDir = $this->input->getOption('project-root'))) {
$this->rootDir = getcwd();
}
$this->rootDir = realpath($this->rootDir);
$this->fs->mkdir($this->rootDir);
$finder = new Finder();
$finder->in($this->rootDir);
$finder->depth(0);
$finder->ignoreVCS(false);
$rootFiles = [];
/** @var SplFileInfo $splInfo */
foreach ($finder as $splInfo) {
$rootFiles[] = $splInfo->getFilename();
}
$requiredFiles = ['composer.json', 'composer.lock'];
$requiredDirs = ['vendor'];
foreach (array_merge($requiredFiles, $requiredDirs) as $file) {
if (!in_array($file, $rootFiles)) {
// possibly not root
$this->output->writeln("<error>You should either run this script under your project root directory, or provide the '--project-root' option.</error>");
$this->output->writeln("The project root directory should contain at least the following files and directories:");
foreach ($requiredFiles as $requiredFile) {
$this->output->writeln("\t- <comment>{$requiredFile}</comment>");
}
foreach ($requiredDirs as $requiredDir) {
$this->output->writeln("\t- <comment>{$requiredDir}/</comment>");
}
exit(1);
}
}
}