InterNACHI / modular

Modularize your Laravel application
MIT License
764 stars 64 forks source link

Livewire Class create in Http, does not match with Laravel-11 / config of livewire #84

Open Filefabrik opened 6 months ago

Filefabrik commented 6 months ago

php artisan make:livewire MyDemoLivewireModule --module=[module name] create the Livewire File into '/app-modules/my-demo-livewire-module/Http/Livewire/MyDemoLivewireModule' regardless what is configured in config('livewire.class_namespace')

File should be during creation stored into '/app-modules/my-demo-livewire-module/Livewire/MyDemoLivewireModule' or whatever the str_contains(config('livewire.class_namespace') is.

https://github.com/InterNACHI/modular/blob/148cfedda25202f086a8fe58014250f860583af2/src/Console/Commands/Make/MakeLivewire.php#L5

protected function createClass($force = false, $inline = false)
        {
            if ($module = $this->module()) {
                $name = Str::of($this->argument('name'))
                    ->split('/[.\/(\\\\)]+/')
                    ->map([Str::class, 'studly'])
                    ->join(DIRECTORY_SEPARATOR);

// Bugnotice: Http can be wrong
                $classPath = $module->path('src/Http/Livewire/'.$name.'.php');

                if (File::exists($classPath) && ! $force) {
                    $this->line("<options=bold,reverse;fg=red> WHOOPS-IE-TOOTLES </> 😳 \n");
                    $this->line("<fg=red;options=bold>Class already exists:</> {$this->parser->relativeClassPath()}");

                    return false;
                }

                $this->ensureDirectoryExists($classPath);

                File::put($classPath, $this->parser->classContents($inline));

                $component_name = Str::of($name)
                    ->explode('/')
                    ->filter()
                    ->map([Str::class, 'kebab'])
                    ->implode('.');

                $fully_qualified_component = Str::of($this->argument('name'))
// Bugnotice: Http can be wrong
                    ->prepend('Http/Livewire/')
                    ->split('/[.\/(\\\\)]+/')
                    ->map([Str::class, 'studly'])
                    ->join('\\');

                Livewire::component("{$module->name}::{$component_name}", $module->qualify($fully_qualified_component));

                return $classPath;
            }

            return parent::createClass($force, $inline);
        }
#/internachi/modular/src/Support/AutoDiscoveryHelper.php
public function livewireComponentFileFinder(): FinderCollection
    {
        $directory = $this->base_path.'/*/src';

        if (str_contains(config('livewire.class_namespace'), '\\Http\\')) {
            $directory .= '/Http';
        }

        $directory .= '/Livewire';

        return FinderCollection::forFiles()
            ->name('*.php')
            ->inOrEmpty($directory);
    }
Filefabrik commented 6 months ago

I think config('livewire.class_namespace') with livewire default value 'class_namespace' => 'App\\Livewire', does not make sense in InterNACHI-Module.

may be it smarter to create in /confg/app-modules.php a 'livewire_location' => './' // in your modules src root.

good or bad way?

Filefabrik commented 6 months ago

fixed in https://github.com/Filefabrik/modular/tree/3.0.4

Filefabrik commented 6 months ago

@inxilpro At the Moment i am on refactoring(local) your module-package with a lot of enhancements

My question: is there a way or do you wish my refactoring in module@next or something like that or is it better, that i make my own fork completly by myself as an own fork?