$paths */ protected function checkForCollision(array $paths): bool { foreach ($paths as $path) { if ($this->fileExists($path)) { $this->components->error("{$path} already exists, aborting."); return true; } } return false; } /** * @param array $replacements */ protected function copyStubToApp(string $stub, string $targetPath, array $replacements = []): void { $filesystem = app(Filesystem::class); if (! $this->fileExists($stubPath = base_path("stubs/filament/{$stub}.stub"))) { $stubPath = $this->getDefaultStubPath() . "/{$stub}.stub"; } $stub = str($filesystem->get($stubPath)); foreach ($replacements as $key => $replacement) { $stub = $stub->replace("{{ {$key} }}", $replacement); } $stub = (string) $stub; $this->writeFile($targetPath, $stub); } protected function fileExists(string $path): bool { $filesystem = app(Filesystem::class); return $filesystem->exists($path); } protected function writeFile(string $path, string $contents): void { $filesystem = app(Filesystem::class); $filesystem->ensureDirectoryExists( pathinfo($path, PATHINFO_DIRNAME), ); $filesystem->put($path, $contents); } protected function getDefaultStubPath(): string { $reflectionClass = new ReflectionClass($this); return (string) str($reflectionClass->getFileName()) ->beforeLast('Commands') ->append('../stubs'); } }