-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
44 changed files
with
900 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Contracts; | ||
|
||
use Exception; | ||
use Spatie\Regex\Regex; | ||
|
||
abstract class FilamentScout extends ModuleDirectoryScout | ||
{ | ||
public function transform(array $result): array | ||
{ | ||
return collect(parent::transform($result)) | ||
->map(function (array $item) { | ||
$panel = null; | ||
|
||
foreach ($this->asset()->patterns() as $pattern) { | ||
$panel ??= Regex::match( | ||
pattern: str($pattern) | ||
->replace('*', '(.*?)') | ||
->replace('/', '\/') | ||
->prepend('/') | ||
->append('/') | ||
->toString(), | ||
subject: str(realpath($item['path'])) | ||
->replace('\\', '/') | ||
)->groupOr(2, ''); | ||
} | ||
|
||
if (empty($panel)) { | ||
throw new Exception("Panel not found for {$item['path']}"); | ||
} | ||
|
||
return [ | ||
...$item, | ||
'panel' => strtolower($panel), | ||
]; | ||
}) | ||
->toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Scouts; | ||
|
||
use Mozex\Modules\Contracts\FilamentScout; | ||
use Mozex\Modules\Enums\AssetType; | ||
|
||
class FilamentClustersScout extends FilamentScout | ||
{ | ||
public function asset(): AssetType | ||
{ | ||
return AssetType::FilamentClusters; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Scouts; | ||
|
||
use Mozex\Modules\Contracts\FilamentScout; | ||
use Mozex\Modules\Enums\AssetType; | ||
|
||
class FilamentPagesScout extends FilamentScout | ||
{ | ||
public function asset(): AssetType | ||
{ | ||
return AssetType::FilamentPages; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Scouts; | ||
|
||
use Mozex\Modules\Contracts\FilamentScout; | ||
use Mozex\Modules\Enums\AssetType; | ||
|
||
class FilamentResourcesScout extends FilamentScout | ||
{ | ||
public function asset(): AssetType | ||
{ | ||
return AssetType::FilamentResources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Mozex\Modules\Scouts; | ||
|
||
use Mozex\Modules\Contracts\FilamentScout; | ||
use Mozex\Modules\Enums\AssetType; | ||
|
||
class FilamentWidgetsScout extends FilamentScout | ||
{ | ||
public function asset(): AssetType | ||
{ | ||
return AssetType::FilamentWidgets; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
use App\Filament\Dashboard\Clusters\Test; | ||
use Filament\Facades\Filament; | ||
use Modules\First\Filament\Admin\Resources\UserResource; | ||
use Modules\First\Filament\Dashboard\Clusters\Users; | ||
use Modules\First\Filament\Dashboard\Resources\NestedUserResource; | ||
use Mozex\Modules\Enums\AssetType; | ||
use Mozex\Modules\Facades\Modules; | ||
use Mozex\Modules\Scouts\FilamentClustersScout; | ||
|
||
test('scout will not collect when disabled', function () { | ||
config()->set( | ||
'modules.'.AssetType::FilamentClusters->value.'.active', | ||
false | ||
); | ||
|
||
$discoverer = FilamentClustersScout::create(); | ||
|
||
expect($discoverer->get())->toHaveCount(0); | ||
|
||
$discoverer->cache(); | ||
|
||
expect($discoverer->get())->toHaveCount(0); | ||
|
||
$discoverer->clear(); | ||
}); | ||
|
||
test('discovering will work', function (bool $cache) { | ||
$discoverer = FilamentClustersScout::create(); | ||
|
||
if ($cache) { | ||
$discoverer->cache(); | ||
} | ||
|
||
$collection = $discoverer->collect(); | ||
|
||
expect($collection) | ||
->each->toHaveKeys(['module', 'path', 'namespace', 'panel']) | ||
->and($collection->pluck('path')) | ||
->not->toContain(realpath(Modules::modulesPath('First/Filament/Admin/Clusters'))) | ||
->toContain(realpath(Modules::modulesPath('First/Filament/Dashboard/Clusters'))) | ||
->toContain(realpath(Modules::modulesPath('Second/Filament/Admin/Clusters'))) | ||
->toContain(realpath(Modules::modulesPath('Second/Filament/Dashboard/Clusters'))) | ||
->and($collection->pluck('panel')->unique()) | ||
->toContain('admin') | ||
->toContain('dashboard'); | ||
|
||
if ($cache) { | ||
$discoverer->clear(); | ||
} | ||
})->with([ | ||
'without cache' => false, | ||
'with cache' => true, | ||
]); | ||
|
||
it('can register filament resources', function (bool $cache) { | ||
$discoverer = FilamentClustersScout::create(); | ||
|
||
if ($cache) { | ||
$discoverer->cache(); | ||
} | ||
|
||
expect(Filament::getPanel('admin')->getClusterDirectories()) | ||
->toHaveCount(2) | ||
->toContain(Modules::basePath('app/Filament/Admin/Clusters')) | ||
->toContain(realpath(Modules::modulesPath('Second/Filament/Admin/Clusters'))) | ||
->and(Filament::getPanel('admin')->getClusteredComponents()) | ||
->toHaveCount(1) | ||
->toHaveKey(Test::class) | ||
->and(array_values(Filament::getPanel('admin')->getClusteredComponents())[0]) | ||
->toContain(UserResource::class) | ||
->and(Filament::getPanel('admin')->getClusterNamespaces()) | ||
->toHaveCount(2) | ||
->toContain('App\\Filament\\Admin\\Clusters') | ||
->toContain('Modules\\Second\\Filament\\Admin\\Clusters') | ||
->and(Filament::getPanel('dashboard')->getClusterDirectories()) | ||
->toHaveCount(3) | ||
->toContain(Modules::basePath('app/Filament/Dashboard/Clusters')) | ||
->toContain(realpath(Modules::modulesPath('Second/Filament/Dashboard/Clusters'))) | ||
->toContain(realpath(Modules::modulesPath('First/Filament/Dashboard/Clusters'))) | ||
->and(Filament::getPanel('dashboard')->getClusteredComponents()) | ||
->toHaveCount(1) | ||
->toHaveKey(Users::class) | ||
->and(array_values(Filament::getPanel('dashboard')->getClusteredComponents())[0]) | ||
->toContain(NestedUserResource::class) | ||
->and(Filament::getPanel('dashboard')->getClusterNamespaces()) | ||
->toHaveCount(3) | ||
->toContain('App\\Filament\\Dashboard\\Clusters') | ||
->toContain('Modules\\Second\\Filament\\Dashboard\\Clusters') | ||
->toContain('Modules\\First\\Filament\\Dashboard\\Clusters'); | ||
|
||
if ($cache) { | ||
$discoverer->clear(); | ||
} | ||
})->with([ | ||
'without cache' => false, | ||
'with cache' => true, | ||
]); |
Oops, something went wrong.