true, 'index.php' => true, 'install.php' => false, ]; /** * @param InputInterface $input * @param OutputInterface $output * @param $basePath */ public function __invoke(InputInterface $input, OutputInterface $output, $basePath) { $publicPath = file_exists("{$basePath}/public") ? "{$basePath}/public" : $basePath; // Fail if destination isn't writable $this->ensureWritable($publicPath); // Check source $source = $basePath . '/vendor/silverstripe/recipe-core/public'; if (!is_dir($source)) { throw new BadMethodCallException("silverstripe/recipe-core is not installed."); } // Copy scaffolded files from recipe-core $output->writeln("Upgrading project bootstrapping files:"); foreach ($this->files as $file => $canCreate) { $fileSource = $source . '/' . $file; $fileDest = $publicPath . '/' . $file; // Skip if we should only upgrade existing files if (!$canCreate && !file_exists($fileDest)) { continue; } $output->writeln(" - Upgrading {$file}"); $this->copyFile( $fileSource, $fileDest ); } } /** * Ensure path is writable * * @param string $path */ protected function ensureWritable($path) { if (!is_writable($path)) { throw new BadMethodCallException("Path $path is not writable"); } } /** * Copy file * * @param string $source * @param string $dest */ protected function copyFile($source, $dest) { // Ensure existing file can be overwritten if (file_exists($dest)) { $this->ensureWritable($dest); } file_put_contents($dest, file_get_contents($source)); } }