Files
ABSDEV/Modules/Developer/Support/Generator.php
T
2026-07-24 11:52:58 +01:00

44 lines
1.1 KiB
PHP

<?php
namespace Modules\Developer\Support;
use Illuminate\Filesystem\Filesystem;
use RuntimeException;
abstract class Generator
{
public function __construct(protected readonly Filesystem $files) {}
protected function createDirectory(string $path): void
{
if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0755, true);
}
}
protected function write(string $path, string $contents, bool $force = false): void
{
if ($this->files->exists($path) && ! $force) {
throw new RuntimeException("File already exists: {$path}");
}
$this->createDirectory(dirname($path));
$this->files->put($path, $contents);
}
protected function studly(string $value): string
{
return str($value)->studly()->toString();
}
protected function snake(string $value): string
{
return str($value)->snake()->toString();
}
protected function kebab(string $value): string
{
return str($value)->kebab()->toString();
}
}