move into sonardesk
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user