Skip to content

Commit

Permalink
feat: cluster support (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Quadrubo committed Mar 17, 2024
1 parent 8ba0dbb commit 8c15b61
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 305 deletions.
17 changes: 17 additions & 0 deletions src/Commands/MakeModelSettingsPageCommand.php
Expand Up @@ -2,8 +2,10 @@

namespace Quadrubo\FilamentModelSettings\Commands;

use Filament\Clusters\Cluster;
use Filament\Facades\Filament;
use Filament\Panel;
use Filament\Support\Commands\Concerns\CanIndentStrings;
use Filament\Support\Commands\Concerns\CanManipulateFiles;
use Illuminate\Console\Command;
use Illuminate\Support\Arr;
Expand All @@ -13,6 +15,7 @@

class MakeModelSettingsPageCommand extends Command
{
use CanIndentStrings;
use CanManipulateFiles;

protected $description = 'Create a new Filament model settings page class';
Expand Down Expand Up @@ -80,8 +83,22 @@ public function handle(): int
return static::INVALID;
}

$potentialCluster = (string) str($namespace)->beforeLast('\Pages');
$clusterAssignment = null;
$clusterImport = null;

if (
class_exists($potentialCluster) &&
is_subclass_of($potentialCluster, Cluster::class)
) {
$clusterAssignment = $this->indentString(PHP_EOL . PHP_EOL . 'protected static ?string $cluster = ' . class_basename($potentialCluster) . '::class;');
$clusterImport = "use {$potentialCluster};" . PHP_EOL;
}

$this->copyStubToApp('ModelSettingsPage', $path, [
'class' => $pageClass,
'clusterAssignment' => $clusterAssignment,
'clusterImport' => $clusterImport,
/** @phpstan-ignore-next-line */
'namespace' => str($namespace ?? '') . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
]);
Expand Down
300 changes: 0 additions & 300 deletions src/Commands/Page.php

This file was deleted.

4 changes: 2 additions & 2 deletions stubs/ModelSettingsPage.stub
Expand Up @@ -2,14 +2,14 @@

namespace {{ namespace }};

use Filament\Forms;
{{ clusterImport }}use Filament\Forms;
use Filament\Forms\Form;
use Quadrubo\FilamentModelSettings\Pages\ModelSettingsPage;
use Quadrubo\FilamentModelSettings\Pages\Contracts\HasModelSettings;

class {{ class }} extends ModelSettingsPage implements HasModelSettings
{
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';
protected static ?string $navigationIcon = 'heroicon-o-cog-6-tooth';{{ clusterAssignment }}

public static function getSettingRecord()
{
Expand Down
7 changes: 4 additions & 3 deletions tests/ArchTest.php
@@ -1,5 +1,6 @@
<?php

it('will not use debugging functions')
->expect(['dd', 'dump', 'ray'])
->each->not->toBeUsed();
it('will not use debugging functions', function () {
expect(['dd', 'dump', 'ray'])
->each->not->toBeUsed();
});

0 comments on commit 8c15b61

Please sign in to comment.