2026-05-14 21:15:33 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Lucent\Commands;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Console\Command;
|
2026-05-18 18:38:43 +03:00
|
|
|
use Illuminate\Support\Str;
|
2026-05-14 21:15:33 +03:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-18 18:38:43 +03:00
|
|
|
$className = Str::of($name)->camel()->ucfirst() . "ImageFilter";
|
|
|
|
|
$pathName = Str::of($name)->snake()->lower();
|
|
|
|
|
|
|
|
|
|
$filePath = "{$dir}/{$className}.php";
|
2026-05-14 21:15:33 +03:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
2026-05-18 18:38:43 +03:00
|
|
|
class {$className} implements ImageFilterInterface
|
2026-05-14 21:15:33 +03:00
|
|
|
{
|
|
|
|
|
public function apply(ImageInterface \$image): ImageInterface
|
|
|
|
|
{
|
|
|
|
|
return \$image;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getName(): string {
|
|
|
|
|
return "{$name}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getPath(): string {
|
2026-05-18 18:38:43 +03:00
|
|
|
return "{$pathName}";
|
2026-05-14 21:15:33 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
PHP;
|
|
|
|
|
|
|
|
|
|
file_put_contents($filePath, $stub);
|
|
|
|
|
|
|
|
|
|
$this->info("Created {$filePath}");
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
}
|