Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
francoism90 committed Jul 29, 2024
1 parent 1c8ca5b commit 440e92f
Showing 1 changed file with 1 addition and 74 deletions.
75 changes: 1 addition & 74 deletions src/WireUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,80 +2,7 @@

namespace Foxws\WireUse;

use Foxws\WireUse\Support\Discover\ComponentScout;
use Foxws\WireUse\Support\Discover\LivewireScout;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Stringable;
use Livewire\LivewireManager;
use Spatie\StructureDiscoverer\Data\DiscoveredStructure;

class WireUse
{
public static function registerComponents(
string $path,
string $namespace = 'App\\',
string $prefix = '',
): void {
$scout = ComponentScout::create()
->path($path)
->prefix("laravel-components-{$prefix}")
->get();

collect($scout)
->each(function (DiscoveredStructure $class) use ($namespace, $prefix) {
$name = static::componentName($class, $namespace, $prefix);

Blade::component($class->getFcqn(), $name->value());
});
}

public static function registerLivewireComponents(
string $path,
string $namespace = 'App\\',
string $prefix = '',
): void {
$scout = LivewireScout::create()
->path($path)
->prefix("livewire-components-{$prefix}")
->get();

$manager = app(LivewireManager::class);

collect($scout)
->each(function (DiscoveredStructure $class) use ($manager, $namespace, $prefix) {
$name = static::componentName($class, $namespace, $prefix);

$fcqn = $class->getFcqn();

if ($manager->isDiscoverable($fcqn)) {
$manager->component($name->value(), $fcqn);
}
});
}

public static function componentName(DiscoveredStructure $class, string $namespace, string $prefix): Stringable
{
return str($class->name)
->kebab()
->prepend(
static::componentPrefix($prefix),
static::componentNamespace($class, $namespace)
);
}

public static function componentPrefix(string $prefix): string
{
return str($prefix)
->kebab()
->finish('::');
}

public static function componentNamespace(DiscoveredStructure $class, string $namespace): Stringable
{
return str($class->namespace)
->after($namespace)
->match('/(.*)\\\\/')
->kebab()
->finish('-');
}
//
}

0 comments on commit 440e92f

Please sign in to comment.