view src/Generator/Requests/StoreRequestGenerator.php @ 30:21439512ba69 codex

Fixing issue with conflict of input variables on the request generator.
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 18 Jun 2025 09:04:59 -0400
parents 827efbf4d73c
children
line wrap: on
line source

<?php

namespace Wizard\MagicForger\Generator\Requests;

use Symfony\Component\Console\Attribute\AsCommand;
use Wizard\MagicForger\Generator\BaseGenerator;

#[AsCommand(name: 'mf:store_request')]
class StoreRequestGenerator extends BaseGenerator
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $name = 'mf:store_request';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Generates the StoreRequest File for a table.';

    /**
     * The type of class being generated.
     *
     * @var string
     */
    protected $type = 'StoreRequest';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        parent::handle();
    }

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getStub()
    {
        return $this->resolveStubPath('/stubs/request.stub');
    }

    /**
     * Resolve the fully-qualified path to the stub.
     *
     * @param  string  $stub
     * @return string
     */
    protected function resolveStubPath($stub)
    {
        return is_file($customPath = $this->laravel->basePath(trim($stub, '/')))
            ? $customPath
            : __DIR__.$stub;
    }

    protected function getClassName($name)
    {
        return $this->store_request_name($name);
    }

    /**
     * Get the stub file for the generator.
     *
     * @return string
     */
    protected function getPath($name = null)
    {
        return str_replace(['App\\', '\\'], ['app/', '/'], $this->getRequestNamespace($this->getTableInput()).'/'.$this->store_request_name($this->getTableInput()).'.php');
    }
}