Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from abr4xas/feature-laravel-11
Browse files Browse the repository at this point in the history
Prepare for laravel 11
  • Loading branch information
martin-ro authored Apr 19, 2024
2 parents e3b832b + a435f50 commit 05ccc6a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": "^8.2",
"filament/filament": "^3.0-stable",
"illuminate/contracts": "^10.0",
"illuminate/contracts": "^10.0 | ^11.0",
"spatie/laravel-package-tools": "^1.13.5"
},
"require-dev": {
Expand All @@ -28,8 +28,7 @@
},
"autoload": {
"psr-4": {
"MartinRo\\FilamentPageBlocks\\": "src/",
"MartinRo\\FilamentPageBlocks\\Database\\Factories\\": "database/factories"
"MartinRo\\FilamentPageBlocks\\": "src/"
}
},
"autoload-dev": {
Expand Down
12 changes: 3 additions & 9 deletions src/Commands/MakePageBlockCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Filament\Support\Commands\Concerns\CanManipulateFiles;
use Illuminate\Console\Command;
use Illuminate\Support\Str;

use function Laravel\Prompts\text;

class MakePageBlockCommand extends Command
Expand All @@ -19,12 +20,6 @@ class MakePageBlockCommand extends Command

public function handle(): int
{
// $pageBlock = (string) Str::of($this->argument('name') ?? $this->askRequired('Name (e.g. `HeroBlock`)', 'name'))
// ->trim('/')
// ->trim('\\')
// ->trim(' ')
// ->replace('/', '\\');

$pageBlock = (string) Str::of($this->argument('name') ?? text(label: 'Name (e.g. `HeroBlock`)', required: true))
->trim('/')
->trim('\\')
Expand All @@ -34,8 +29,7 @@ public function handle(): int
$pageBlockClass = (string) Str::of($pageBlock)->afterLast('\\');

$pageBlockNamespace = Str::of($pageBlock)->contains('\\') ?
(string) Str::of($pageBlock)->beforeLast('\\') :
'';
(string) Str::of($pageBlock)->beforeLast('\\') : '';

$label = Str::of($pageBlock)
->beforeLast('Block')
Expand Down Expand Up @@ -78,7 +72,7 @@ public function handle(): int

$this->copyStubToApp('PageBlock', $path, [
'class' => $pageBlockClass,
'namespace' => 'App\\Filament\\PageBlocks'.($pageBlockNamespace !== '' ? "\\{$pageBlockNamespace}" : ''),
'namespace' => 'App\\Filament\\PageBlocks' . ($pageBlockNamespace !== '' ? "\\{$pageBlockNamespace}" : ''),
'label' => $label,
'shortName' => $shortName,
]);
Expand Down
3 changes: 1 addition & 2 deletions src/Facades/FilamentPageBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace MartinRo\FilamentPageBlocks\Facades;

use Illuminate\Support\Facades\Facade;
use MartinRo\FilamentPageBlocks\Models\Contracts\Page as PageContract;

/**
* @method static void register(string $class, string $baseClass)
Expand Down Expand Up @@ -33,7 +32,7 @@
*/
class FilamentPageBlocks extends Facade
{
protected static function getFacadeAccessor()
protected static function getFacadeAccessor(): string
{
return 'filament-page-blocks';
}
Expand Down
14 changes: 9 additions & 5 deletions src/FilamentPageBlocksManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace MartinRo\FilamentPageBlocks;

use Exception;
use Illuminate\Support\Collection;
use InvalidArgumentException;

class FilamentPageBlocksManager
{
Expand All @@ -11,29 +13,31 @@ class FilamentPageBlocksManager

public function __construct()
{
/** @var Collection<string,string> */
/** @var Collection<string,string> $pageBlocks */
$pageBlocks = collect([]);

$this->pageBlocks = $pageBlocks;
}

/**
* @param class-string $class
* @param class-string $baseClass
* @param class-string $class
* @param class-string $baseClass
*
* @throws Exception
*/
public function register(string $class, string $baseClass): void
{
match ($baseClass) {
PageBlock::class => static::registerPageBlock($class),
default => throw new \Exception('Invalid class type'),
default => throw new Exception('Invalid class type'),
};
}

/** @param class-string $pageBlock */
public function registerPageBlock(string $pageBlock): void
{
if (! is_subclass_of($pageBlock, PageBlock::class)) {
throw new \InvalidArgumentException("{$pageBlock} must extend ".PageBlock::class);
throw new InvalidArgumentException("{$pageBlock} must extend " . PageBlock::class);
}

$this->pageBlocks->put($pageBlock::getName(), $pageBlock);
Expand Down
4 changes: 2 additions & 2 deletions src/FilamentPageBlocksServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ protected function registerComponentsFromDirectory(string $baseClass, array $reg

$namespace = Str::of($namespace);

$register = array_merge(
array_merge(
$register,
collect($filesystem->allFiles($directory))
->map(function (SplFileInfo $file) use ($namespace): string {
$variableNamespace = $namespace->contains('*') ? str_ireplace(
['\\'.$namespace->before('*'), $namespace->after('*')],
['\\' . $namespace->before('*'), $namespace->after('*')],
['', ''],
Str::of($file->getPath())
->after(base_path())
Expand Down
2 changes: 1 addition & 1 deletion src/PageBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function getComponent(): string
return static::$component;
}

return 'page-blocks.'.static::getName();
return 'page-blocks.' . static::getName();
}

public static function getName(): string
Expand Down

0 comments on commit 05ccc6a

Please sign in to comment.