Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Filefabrik opened this issue Mar 29, 2024 · 3 comments

Comments

@Filefabrik
Copy link

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.

use Illuminate\Filesystem\Filesystem;

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
Copy link
Author

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
Copy link
Author

@Filefabrik
Copy link
Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant