Files
lucent-laravel/src/Commands/GenerateImageFilter.php
T
2026-05-18 18:38:43 +03:00

65 lines
1.6 KiB
PHP

<?php
namespace Lucent\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class GenerateImageFilter extends Command
{
protected $signature = "lucent:generate:image_filter {name}";
protected $description = "Generate an image filter";
public function handle()
{
$name = $this->argument("name");
$relativePath = config("lucent.image_filter_path");
$dir = base_path($relativePath);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
$className = Str::of($name)->camel()->ucfirst() . "ImageFilter";
$pathName = Str::of($name)->snake()->lower();
$filePath = "{$dir}/{$className}.php";
if (file_exists($filePath)) {
$this->error("Filter {$name} already exists at {$filePath}");
return Command::FAILURE;
}
$namespace = str_replace("/", "\\", ucwords($relativePath, "/"));
$stub = <<<PHP
<?php namespace {$namespace};
use Lucent\ImageFilterInterface;
use Intervention\Image\Interfaces\ImageInterface;
class {$className} implements ImageFilterInterface
{
public function apply(ImageInterface \$image): ImageInterface
{
return \$image;
}
public function getName(): string {
return "{$name}";
}
public function getPath(): string {
return "{$pathName}";
}
}
PHP;
file_put_contents($filePath, $stub);
$this->info("Created {$filePath}");
return Command::SUCCESS;
}
}