芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/kwesioben.com/paymoney/vendor/laravel/breeze/src/Console/InstallCommand.php
*/ protected $stacks = ['blade', 'react', 'vue', 'api']; /** * Execute the console command. * * @return int|null */ public function handle() { if ($this->argument('stack') === 'vue') { return $this->installInertiaVueStack(); } elseif ($this->argument('stack') === 'react') { return $this->installInertiaReactStack(); } elseif ($this->argument('stack') === 'api') { return $this->installApiStack(); } elseif ($this->argument('stack') === 'blade') { return $this->installBladeStack(); } $this->components->error('Invalid stack. Supported stacks are [blade], [react], [vue], and [api].'); return 1; } /** * Interact with the user to prompt them when the stack argument is missing. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return void */ protected function interact(InputInterface $input, OutputInterface $output) { if ($this->argument('stack') === null && $this->option('inertia')) { $input->setArgument('stack', 'vue'); } if ($this->argument('stack')) { return; } $input->setArgument('stack', $this->components->choice('Which stack would you like to install?', $this->stacks)); $input->setOption('dark', $this->components->confirm('Would you like to install dark mode support?')); if (in_array($input->getArgument('stack'), ['vue', 'react'])) { $input->setOption('ssr', $this->components->confirm('Would you like to install Inertia SSR support?')); } $input->setOption('pest', $this->components->confirm('Would you prefer Pest tests instead of PHPUnit?')); } /** * Install Breeze's tests. * * @return bool */ protected function installTests() { (new Filesystem)->ensureDirectoryExists(base_path('tests/Feature')); $stubStack = $this->argument('stack') === 'api' ? 'api' : 'default'; if ($this->option('pest')) { $this->removeComposerPackages(['nunomaduro/collision', 'phpunit/phpunit'], true); if (! $this->requireComposerPackages(['nunomaduro/collision:^6.4', 'pestphp/pest:^1.22', 'pestphp/pest-plugin-laravel:^1.2'], true)) { return false; } (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/'.$stubStack.'/pest-tests/Feature', base_path('tests/Feature')); (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/'.$stubStack.'/pest-tests/Unit', base_path('tests/Unit')); (new Filesystem)->copy(__DIR__.'/../../stubs/'.$stubStack.'/pest-tests/Pest.php', base_path('tests/Pest.php')); } else { (new Filesystem)->copyDirectory(__DIR__.'/../../stubs/'.$stubStack.'/tests/Feature', base_path('tests/Feature')); } return true; } /** * Install the middleware to a group in the application Http Kernel. * * @param string $after * @param string $name * @param string $group * @return void */ protected function installMiddlewareAfter($after, $name, $group = 'web') { $httpKernel = file_get_contents(app_path('Http/Kernel.php')); $middlewareGroups = Str::before(Str::after($httpKernel, '$middlewareGroups = ['), '];'); $middlewareGroup = Str::before(Str::after($middlewareGroups, "'$group' => ["), '],'); if (! Str::contains($middlewareGroup, $name)) { $modifiedMiddlewareGroup = str_replace( $after.',', $after.','.PHP_EOL.' '.$name.',', $middlewareGroup, ); file_put_contents(app_path('Http/Kernel.php'), str_replace( $middlewareGroups, str_replace($middlewareGroup, $modifiedMiddlewareGroup, $middlewareGroups), $httpKernel )); } } /** * Installs the given Composer Packages into the application. * * @param array $packages * @param bool $asDev * @return bool */ protected function requireComposerPackages(array $packages, $asDev = false) { $composer = $this->option('composer'); if ($composer !== 'global') { $command = ['php', $composer, 'require']; } $command = array_merge( $command ?? ['composer', 'require'], $packages, $asDev ? ['--dev'] : [], ); return (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1'])) ->setTimeout(null) ->run(function ($type, $output) { $this->output->write($output); }) === 0; } /** * Removes the given Composer Packages from the application. * * @param array $packages * @param bool $asDev * @return bool */ protected function removeComposerPackages(array $packages, $asDev = false) { $composer = $this->option('composer'); if ($composer !== 'global') { $command = ['php', $composer, 'remove']; } $command = array_merge( $command ?? ['composer', 'remove'], $packages, $asDev ? ['--dev'] : [], ); return (new Process($command, base_path(), ['COMPOSER_MEMORY_LIMIT' => '-1'])) ->setTimeout(null) ->run(function ($type, $output) { $this->output->write($output); }) === 0; } /** * Update the "package.json" file. * * @param callable $callback * @param bool $dev * @return void */ protected static function updateNodePackages(callable $callback, $dev = true) { if (! file_exists(base_path('package.json'))) { return; } $configurationKey = $dev ? 'devDependencies' : 'dependencies'; $packages = json_decode(file_get_contents(base_path('package.json')), true); $packages[$configurationKey] = $callback( array_key_exists($configurationKey, $packages) ? $packages[$configurationKey] : [], $configurationKey ); ksort($packages[$configurationKey]); file_put_contents( base_path('package.json'), json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT).PHP_EOL ); } /** * Delete the "node_modules" directory and remove the associated lock files. * * @return void */ protected static function flushNodeModules() { tap(new Filesystem, function ($files) { $files->deleteDirectory(base_path('node_modules')); $files->delete(base_path('yarn.lock')); $files->delete(base_path('package-lock.json')); }); } /** * Replace a given string within a given file. * * @param string $search * @param string $replace * @param string $path * @return void */ protected function replaceInFile($search, $replace, $path) { file_put_contents($path, str_replace($search, $replace, file_get_contents($path))); } /** * Get the path to the appropriate PHP binary. * * @return string */ protected function phpBinary() { return (new PhpExecutableFinder())->find(false) ?: 'php'; } /** * Run the given commands. * * @param array $commands * @return void */ protected function runCommands($commands) { $process = Process::fromShellCommandline(implode(' && ', $commands), null, null, null, null); if ('\\' !== DIRECTORY_SEPARATOR && file_exists('/dev/tty') && is_readable('/dev/tty')) { try { $process->setTty(true); } catch (RuntimeException $e) { $this->output->writeln('
WARN > '.$e->getMessage().PHP_EOL); } } $process->run(function ($type, $line) { $this->output->write(' '.$line); }); } /** * Remove Tailwind dark classes from the given files. * * @param \Symfony\Component\Finder\Finder $finder * @return void */ protected function removeDarkClasses(Finder $finder) { foreach ($finder as $file) { file_put_contents($file->getPathname(), preg_replace('/\sdark:[^\s"\']+/', '', $file->getContents())); } } }