bumble2020/domainwizard.net/vendor/filament/support/src/Commands/Concerns/CanManipulateFiles.php000064400000003373150031557130027601 0ustar00homefileExists($path)) { $this->error("{$path} already exists, aborting."); return true; } } return false; } 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::of($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( (string) Str::of($path) ->beforeLast('/'), ); $filesystem->put($path, $contents); } protected function getDefaultStubPath(): string { $reflectionClass = new ReflectionClass($this); return (string) Str::of($reflectionClass->getFileName()) ->beforeLast('Commands') ->append('../stubs'); } }