view src/Generator/Model/ModelGenerator.php @ 17:f21baea33d0b main-dev

Added hgignore
author Luka Sitas <sitas.luka.97@gmail.com>
date Wed, 26 Feb 2025 19:12:23 -0500
parents c969ed13c570
children 19b7a8de0019
line wrap: on
line source

<?php

namespace Wizzard\MagicForger\Generator\Model;

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

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

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

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

    /**
     * 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/model.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->model_name($name);
    }

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