Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
21
vendor/filament/support/src/Commands/AboutCommand.php
vendored
Normal file
21
vendor/filament/support/src/Commands/AboutCommand.php
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'filament:about')]
|
||||
class AboutCommand extends Command
|
||||
{
|
||||
protected $description = 'Display basic information about Filament packages that are installed';
|
||||
|
||||
protected $name = 'filament:about';
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$this->call('about', [
|
||||
'--only' => 'filament',
|
||||
]);
|
||||
}
|
||||
}
|
||||
91
vendor/filament/support/src/Commands/AssetsCommand.php
vendored
Normal file
91
vendor/filament/support/src/Commands/AssetsCommand.php
vendored
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Facades\FilamentAsset;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'filament:assets')]
|
||||
class AssetsCommand extends Command
|
||||
{
|
||||
use CanManipulateFiles;
|
||||
|
||||
protected $description = 'Set up Filament assets';
|
||||
|
||||
protected $name = 'filament:assets';
|
||||
|
||||
/** @var array<string> */
|
||||
protected array $publishedAssets = [];
|
||||
|
||||
public function handle(Filesystem $filesystem): int
|
||||
{
|
||||
foreach (FilamentAsset::getAlpineComponents() as $asset) {
|
||||
if ($asset->isRemote()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->copyAsset($asset->getPath(), $asset->getPublicPath());
|
||||
}
|
||||
|
||||
foreach (FilamentAsset::getFonts() as $asset) {
|
||||
$assetPublicPath = $asset->getPublicPath();
|
||||
|
||||
foreach ($filesystem->allFiles($asset->getPath()) as $file) {
|
||||
if ($file->getExtension() === 'js') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->copyAsset($file->getPathname(), $assetPublicPath . DIRECTORY_SEPARATOR . $file->getFilename());
|
||||
}
|
||||
}
|
||||
|
||||
foreach (FilamentAsset::getScripts() as $asset) {
|
||||
if ($asset->isRemote()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->copyAsset($asset->getPath(), $asset->getPublicPath());
|
||||
}
|
||||
|
||||
foreach (FilamentAsset::getStyles() as $asset) {
|
||||
if ($asset->isRemote()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->copyAsset($asset->getPath(), $asset->getPublicPath());
|
||||
}
|
||||
|
||||
foreach (FilamentAsset::getThemes() as $asset) {
|
||||
if ($asset->isRemote()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->copyAsset($asset->getPath(), $asset->getPublicPath());
|
||||
}
|
||||
|
||||
$this->components->bulletList($this->publishedAssets);
|
||||
|
||||
$this->components->info('Successfully published assets!');
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function copyAsset(string $from, string $to): void
|
||||
{
|
||||
$filesystem = app(Filesystem::class);
|
||||
|
||||
[$from, $to] = str_replace('/', DIRECTORY_SEPARATOR, [$from, $to]);
|
||||
|
||||
$filesystem->ensureDirectoryExists(
|
||||
(string) str($to)
|
||||
->beforeLast(DIRECTORY_SEPARATOR),
|
||||
);
|
||||
|
||||
$filesystem->replace($to, $filesystem->get($from));
|
||||
|
||||
$this->publishedAssets[] = $to;
|
||||
}
|
||||
}
|
||||
179
vendor/filament/support/src/Commands/CheckTranslationsCommand.php
vendored
Normal file
179
vendor/filament/support/src/Commands/CheckTranslationsCommand.php
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Console\PromptsForMissingInput;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Exception\InvalidOptionException;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Finder\SplFileInfo;
|
||||
|
||||
use function Laravel\Prompts\info;
|
||||
use function Laravel\Prompts\table;
|
||||
use function Laravel\Prompts\warning;
|
||||
|
||||
#[AsCommand(name: 'filament:check-translations')]
|
||||
class CheckTranslationsCommand extends Command implements PromptsForMissingInput
|
||||
{
|
||||
protected $description = 'Check for missing and removed translations';
|
||||
|
||||
protected $name = 'filament:check-translations';
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'locales',
|
||||
mode: InputArgument::IS_ARRAY,
|
||||
description: 'The locales to check',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'source',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_REQUIRED,
|
||||
description: 'The directory containing the translations to check - either \'vendor\' or \'app\'',
|
||||
default: 'vendor',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->scan('filament');
|
||||
$this->scan('actions');
|
||||
$this->scan('forms');
|
||||
$this->scan('infolists');
|
||||
$this->scan('notifications');
|
||||
$this->scan('query-builder');
|
||||
$this->scan('schemas');
|
||||
$this->scan('spark-billing-provider');
|
||||
$this->scan('spatie-laravel-google-fonts-plugin');
|
||||
$this->scan('spatie-laravel-media-library-plugin');
|
||||
$this->scan('spatie-laravel-settings-plugin');
|
||||
$this->scan('spatie-laravel-tags-plugin');
|
||||
$this->scan('support');
|
||||
$this->scan('tables');
|
||||
$this->scan('widgets');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
protected function scan(string $package): void
|
||||
{
|
||||
$localeRootDirectory = match ($source = $this->option('source')) {
|
||||
'app' => lang_path("vendor/{$package}"),
|
||||
'vendor' => InstalledVersions::isInstalled("filament/{$package}")
|
||||
? InstalledVersions::getInstallPath("filament/{$package}") . '/resources/lang'
|
||||
: null,
|
||||
default => throw new InvalidOptionException("{$source} is not a valid translation source. Must be `vendor` or `app`.")
|
||||
};
|
||||
|
||||
$filesystem = app(Filesystem::class);
|
||||
|
||||
if (($localeRootDirectory === null) || (! $filesystem->exists($localeRootDirectory))) {
|
||||
return;
|
||||
}
|
||||
|
||||
collect($filesystem->directories($localeRootDirectory))
|
||||
->mapWithKeys(static fn (string $directory): array => [$directory => (string) str($directory)->afterLast(DIRECTORY_SEPARATOR)])
|
||||
->when(
|
||||
$locales = $this->argument('locales'),
|
||||
fn (Collection $availableLocales): Collection => $availableLocales->filter(fn (string $locale): bool => in_array($locale, $locales))
|
||||
)
|
||||
->each(function (string $locale, string $localeDir) use ($filesystem, $localeRootDirectory, $package): void {
|
||||
$files = $filesystem->allFiles($localeDir);
|
||||
$baseFiles = $filesystem->allFiles(implode(DIRECTORY_SEPARATOR, [$localeRootDirectory, 'en']));
|
||||
|
||||
$localeFiles = collect($files)->map(fn ($file) => (string) str($file->getPathname())->after(DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR));
|
||||
$englishFiles = collect($baseFiles)->map(fn ($file) => (string) str($file->getPathname())->after(DIRECTORY_SEPARATOR . 'en' . DIRECTORY_SEPARATOR));
|
||||
$missingFiles = $englishFiles->diff($localeFiles);
|
||||
$removedFiles = $localeFiles->diff($englishFiles);
|
||||
$path = implode(DIRECTORY_SEPARATOR, [$localeRootDirectory, $locale]);
|
||||
|
||||
if ($missingFiles->count() > 0 && $removedFiles->count() > 0) {
|
||||
warning("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . " and {$removedFiles->count()} removed translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
|
||||
} elseif ($missingFiles->count() > 0) {
|
||||
warning("[!] Package filament/{$package} has {$missingFiles->count()} missing translation " . Str::plural('file', $missingFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
|
||||
} elseif ($removedFiles->count() > 0) {
|
||||
warning("[!] Package filament/{$package} has {$removedFiles->count()} removed translation " . Str::plural('file', $removedFiles->count()) . ' for ' . locale_get_display_name($locale, 'en') . ".\n");
|
||||
}
|
||||
|
||||
if ($missingFiles->count() > 0 || $removedFiles->count() > 0) {
|
||||
table(
|
||||
[$path, ''],
|
||||
array_merge(
|
||||
array_map(fn (string $file): array => [$file, 'Missing'], $missingFiles->toArray()),
|
||||
array_map(fn (string $file): array => [$file, 'Removed'], $removedFiles->toArray()),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
collect($files)
|
||||
->reject(function ($file) use ($localeRootDirectory) {
|
||||
return ! file_exists(implode(DIRECTORY_SEPARATOR, [$localeRootDirectory, 'en', $file->getRelativePathname()]));
|
||||
})
|
||||
->mapWithKeys(function (SplFileInfo $file) use ($localeDir, $localeRootDirectory) {
|
||||
$expectedKeys = require implode(DIRECTORY_SEPARATOR, [$localeRootDirectory, 'en', $file->getRelativePathname()]);
|
||||
$actualKeys = require $file->getPathname();
|
||||
|
||||
return [
|
||||
(string) str($file->getPathname())->after("{$localeDir}/") => [
|
||||
'missing' => array_keys(array_diff_key(
|
||||
Arr::dot($expectedKeys),
|
||||
Arr::dot($actualKeys)
|
||||
)),
|
||||
'removed' => array_keys(array_diff_key(
|
||||
Arr::dot($actualKeys),
|
||||
Arr::dot($expectedKeys)
|
||||
)),
|
||||
],
|
||||
];
|
||||
})
|
||||
->tap(function (Collection $files) use ($locale, $package): void {
|
||||
$missingKeysCount = $files->sum(fn ($file): int => count($file['missing']));
|
||||
$removedKeysCount = $files->sum(fn ($file): int => count($file['removed']));
|
||||
|
||||
$locale = locale_get_display_name($locale, 'en');
|
||||
|
||||
if ((! $missingKeysCount) && (! $removedKeysCount)) {
|
||||
info("[✓] Package filament/{$package} has no missing or removed translation keys for {$locale}!\n");
|
||||
} elseif ($missingKeysCount && $removedKeysCount) {
|
||||
warning("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " and {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
|
||||
} elseif ($missingKeysCount) {
|
||||
warning("[!] Package filament/{$package} has {$missingKeysCount} missing translation " . Str::plural('key', $missingKeysCount) . " for {$locale}.\n");
|
||||
} else {
|
||||
warning("[!] Package filament/{$package} has {$removedKeysCount} removed translation " . Str::plural('key', $removedKeysCount) . " for {$locale}.\n");
|
||||
}
|
||||
})
|
||||
->filter(static fn ($keys): bool => count($keys['missing']) || count($keys['removed']))
|
||||
->each(function ($keys, string $file): void {
|
||||
table(
|
||||
[$file, ''],
|
||||
[
|
||||
...array_map(fn (string $key): array => [$key, 'Missing'], $keys['missing']),
|
||||
...array_map(fn (string $key): array => [$key, 'Removed'], $keys['removed']),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
63
vendor/filament/support/src/Commands/Concerns/CanAskForComponentLocation.php
vendored
Normal file
63
vendor/filament/support/src/Commands/Concerns/CanAskForComponentLocation.php
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Support\Facades\FilamentCli;
|
||||
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
trait CanAskForComponentLocation
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string,
|
||||
* 2: ?string,
|
||||
* }
|
||||
*/
|
||||
protected function askForComponentLocation(string $path, string $question = 'Where would you like to create the component?'): array
|
||||
{
|
||||
$pathNamespace = (string) str($path)->replace('/', '\\');
|
||||
|
||||
$locations = FilamentCli::getComponentLocations();
|
||||
|
||||
if (blank($locations)) {
|
||||
return [
|
||||
app()->getNamespace() . "Filament\\{$pathNamespace}",
|
||||
app_path('Filament' . DIRECTORY_SEPARATOR . $path),
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
$options = [
|
||||
'' => app()->getNamespace() . "Filament\\{$pathNamespace}",
|
||||
...array_map(
|
||||
fn (string $namespace): string => "{$namespace}\\{$pathNamespace}",
|
||||
array_combine(
|
||||
array_keys($locations),
|
||||
array_keys($locations),
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
$namespace = select(
|
||||
label: $question,
|
||||
options: $options,
|
||||
default: $this->input->isInteractive() ? null : '',
|
||||
);
|
||||
|
||||
if (blank($namespace)) {
|
||||
return [
|
||||
app()->getNamespace() . "Filament\\{$pathNamespace}",
|
||||
app_path('Filament' . DIRECTORY_SEPARATOR . $path),
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"{$namespace}\\{$pathNamespace}",
|
||||
$locations[$namespace]['path'] . '/' . $path,
|
||||
$locations[$namespace]['viewNamespace'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
58
vendor/filament/support/src/Commands/Concerns/CanAskForLivewireComponentLocation.php
vendored
Normal file
58
vendor/filament/support/src/Commands/Concerns/CanAskForLivewireComponentLocation.php
vendored
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Support\Facades\FilamentCli;
|
||||
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
trait CanAskForLivewireComponentLocation
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string,
|
||||
* 2: ?string,
|
||||
* }
|
||||
*/
|
||||
protected function askForLivewireComponentLocation(string $question = 'Where would you like to create the Livewire component?'): array
|
||||
{
|
||||
$locations = FilamentCli::getLivewireComponentLocations();
|
||||
|
||||
if (blank($locations)) {
|
||||
return [
|
||||
app()->getNamespace() . 'Livewire',
|
||||
app_path('Livewire'),
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
$options = [
|
||||
'' => app()->getNamespace() . 'Livewire',
|
||||
...array_combine(
|
||||
array_keys($locations),
|
||||
array_keys($locations),
|
||||
),
|
||||
];
|
||||
|
||||
$namespace = select(
|
||||
label: $question,
|
||||
options: $options,
|
||||
default: $this->input->isInteractive() ? null : '',
|
||||
);
|
||||
|
||||
if (blank($namespace)) {
|
||||
return [
|
||||
app()->getNamespace() . 'Livewire',
|
||||
app_path('Livewire'),
|
||||
'',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
$namespace,
|
||||
$locations[$namespace]['path'],
|
||||
$locations[$namespace]['viewNamespace'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
42
vendor/filament/support/src/Commands/Concerns/CanAskForRelatedModel.php
vendored
Normal file
42
vendor/filament/support/src/Commands/Concerns/CanAskForRelatedModel.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use function Filament\Support\discover_app_classes;
|
||||
use function Laravel\Prompts\info;
|
||||
use function Laravel\Prompts\suggest;
|
||||
|
||||
trait CanAskForRelatedModel
|
||||
{
|
||||
/**
|
||||
* @return ?class-string
|
||||
*/
|
||||
protected function askForRelatedModel(string $relationship): ?string
|
||||
{
|
||||
$modelFqns = discover_app_classes(parentClass: Model::class);
|
||||
|
||||
$modelFqns = array_combine(
|
||||
$modelFqns,
|
||||
$modelFqns,
|
||||
);
|
||||
|
||||
info("Filament couldn't automatically find the related model for the [{$relationship}] relationship.");
|
||||
|
||||
return suggest(
|
||||
label: 'What is the related model?',
|
||||
options: function (?string $search) use ($modelFqns): array {
|
||||
if (blank($search)) {
|
||||
return $modelFqns;
|
||||
}
|
||||
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return array_filter($modelFqns, fn (string $modelFqn): bool => str($modelFqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
|
||||
},
|
||||
placeholder: app()->getNamespace() . 'Models\\User',
|
||||
hint: 'Please provide the fully-qualified class name.',
|
||||
);
|
||||
}
|
||||
}
|
||||
42
vendor/filament/support/src/Commands/Concerns/CanAskForRelatedResource.php
vendored
Normal file
42
vendor/filament/support/src/Commands/Concerns/CanAskForRelatedResource.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\info;
|
||||
|
||||
trait CanAskForRelatedResource
|
||||
{
|
||||
/**
|
||||
* @return ?class-string
|
||||
*/
|
||||
protected function askForRelatedResource(): ?string
|
||||
{
|
||||
info('Linking to an existing resource will open the resource\'s pages instead of modals when links are clicked. It will also inherit the resource\'s configuration.');
|
||||
|
||||
if (! confirm(
|
||||
label: 'Do you want to link this to an existing resource?',
|
||||
default: false,
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$clusterFqn = $this->askForCluster(
|
||||
initialQuestion: 'Is the resource in a cluster?',
|
||||
question: 'Which cluster is the resource in?',
|
||||
);
|
||||
|
||||
if (filled($clusterFqn)) {
|
||||
[$resourcesNamespace] = $this->getClusterResourcesLocation($clusterFqn);
|
||||
} else {
|
||||
[$resourcesNamespace] = $this->getResourcesLocation(
|
||||
question: 'Which namespace would you like to search for resources in?',
|
||||
);
|
||||
}
|
||||
|
||||
return $this->askForResource(
|
||||
question: 'Which resource do you want to use?',
|
||||
resourcesNamespace: $resourcesNamespace,
|
||||
);
|
||||
}
|
||||
}
|
||||
125
vendor/filament/support/src/Commands/Concerns/CanAskForResource.php
vendored
Normal file
125
vendor/filament/support/src/Commands/Concerns/CanAskForResource.php
vendored
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Resources\Resource;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use function Laravel\Prompts\search;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
trait CanAskForResource
|
||||
{
|
||||
/**
|
||||
* @return class-string
|
||||
*/
|
||||
protected function askForResource(string $question, ?string $initialResource = null, ?string $resourcesNamespace = null): string
|
||||
{
|
||||
$resourcesNamespace ??= $this->resourcesNamespace;
|
||||
|
||||
if (is_string($initialResource)) {
|
||||
$initialResource = (string) str($initialResource)
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
|
||||
if (class_exists($initialResource)) {
|
||||
return $initialResource;
|
||||
}
|
||||
|
||||
$resourceNamespace = (string) str($initialResource)
|
||||
->beforeLast('Resource')
|
||||
->pluralStudly()
|
||||
->replace('/', '\\')
|
||||
->prepend("{$resourcesNamespace}\\");
|
||||
|
||||
$resourceBasename = (string) str($initialResource)
|
||||
->classBasename()
|
||||
->beforeLast('Resource')
|
||||
->singular()
|
||||
->append('Resource');
|
||||
|
||||
if (class_exists("{$resourceNamespace}\\{$resourceBasename}")) {
|
||||
return "{$resourceNamespace}\\{$resourceBasename}";
|
||||
}
|
||||
|
||||
$resourceNamespace = (string) str($resourceNamespace)
|
||||
->beforeLast('\\');
|
||||
|
||||
if (class_exists("{$resourceNamespace}\\{$resourceBasename}")) {
|
||||
return "{$resourceNamespace}\\{$resourceBasename}";
|
||||
}
|
||||
}
|
||||
|
||||
$resourceFqns = array_filter(
|
||||
array_values($this->panel->getResources()),
|
||||
fn (string $resource): bool => str($resource)->startsWith("{$resourcesNamespace}\\"),
|
||||
);
|
||||
|
||||
if (! $resourceFqns) {
|
||||
return (string) str(text(
|
||||
label: "No resources were found within [{$resourcesNamespace}]. {$question}",
|
||||
placeholder: app()->getNamespace() . 'Filament\\Resources\\Posts\\PostResource',
|
||||
required: true,
|
||||
validate: function (string $value): ?string {
|
||||
$value = (string) str($value)
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
|
||||
return match (true) {
|
||||
! class_exists($value) => 'The resource class doesn\'t exist, please use the fully-qualified class name.',
|
||||
! is_subclass_of($value, Resource::class) => 'The resource class or one of its parents must extend [' . Resource::class . '].',
|
||||
default => null,
|
||||
};
|
||||
},
|
||||
hint: 'Please provide the fully-qualified class name of the resource.',
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
return search(
|
||||
label: $question,
|
||||
options: function (?string $search) use ($resourceFqns, $resourcesNamespace): array {
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return collect($resourceFqns)
|
||||
->when(
|
||||
filled($search = (string) str($search)->trim()->replace(['\\', '/'], '')),
|
||||
fn (Collection $resourceFqns) => $resourceFqns->filter(fn (string $fqn): bool => str($fqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true)),
|
||||
)
|
||||
->mapWithKeys(function (string $fqn) use ($resourcesNamespace): array {
|
||||
$label = (string) str($fqn)->after("{$resourcesNamespace}\\");
|
||||
|
||||
if (str($label)->contains('\\')) {
|
||||
$finalSegment = (string) str($label)->afterLast('\\');
|
||||
|
||||
$penultimateSegment = (string) str($label)->beforeLast('\\');
|
||||
|
||||
if (str($penultimateSegment)->contains('\\')) {
|
||||
$penultimateSegment = (string) str($penultimateSegment)->afterLast('\\');
|
||||
}
|
||||
|
||||
if (str($finalSegment)->endsWith('Resource') && ($finalSegment !== 'Resource')) {
|
||||
$expectedPenultimateSegment = (string) str($finalSegment)
|
||||
->beforeLast('Resource')
|
||||
->pluralStudly();
|
||||
}
|
||||
|
||||
if ($penultimateSegment === ($expectedPenultimateSegment ?? null)) {
|
||||
$label = (string) str($label)->beforeLast('\\');
|
||||
}
|
||||
}
|
||||
|
||||
return [$fqn => $label];
|
||||
})
|
||||
->all();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
43
vendor/filament/support/src/Commands/Concerns/CanAskForSchema.php
vendored
Normal file
43
vendor/filament/support/src/Commands/Concerns/CanAskForSchema.php
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use function Filament\Support\discover_app_classes;
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\suggest;
|
||||
|
||||
trait CanAskForSchema
|
||||
{
|
||||
/**
|
||||
* @return ?class-string
|
||||
*/
|
||||
protected function askForSchema(string $intialQuestion, string $question, string $questionPlaceholder): ?string
|
||||
{
|
||||
if (! confirm(
|
||||
label: $intialQuestion,
|
||||
default: false,
|
||||
)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$schemaFqns = array_filter(
|
||||
discover_app_classes(),
|
||||
fn (string $schemaFqn): bool => method_exists($schemaFqn, 'configure'),
|
||||
);
|
||||
|
||||
return suggest(
|
||||
label: $question,
|
||||
options: function (?string $search) use ($schemaFqns): array {
|
||||
if (blank($search)) {
|
||||
return $schemaFqns;
|
||||
}
|
||||
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return array_filter($schemaFqns, fn (string $schemaFqn): bool => str($schemaFqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
|
||||
},
|
||||
placeholder: $questionPlaceholder,
|
||||
hint: 'Please provide the fully-qualified class name.',
|
||||
);
|
||||
}
|
||||
}
|
||||
111
vendor/filament/support/src/Commands/Concerns/CanAskForViewLocation.php
vendored
Normal file
111
vendor/filament/support/src/Commands/Concerns/CanAskForViewLocation.php
vendored
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\FileViewFinder;
|
||||
|
||||
use function Filament\Support\get_composer_vendor_directory;
|
||||
use function Filament\Support\is_path_within_directory;
|
||||
use function Filament\Support\is_path_within_vendor_directory;
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
trait CanAskForViewLocation
|
||||
{
|
||||
/**
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string,
|
||||
* }
|
||||
*/
|
||||
protected function askForViewLocation(string $view, string $question = 'Where would you like to create the Blade view?', ?string $defaultNamespace = null): array
|
||||
{
|
||||
$viewFactory = app(Factory::class);
|
||||
|
||||
$paths = [];
|
||||
|
||||
/** @var array<string> $viewPaths */
|
||||
$viewPaths = config('view.paths') ?? [];
|
||||
$defaultViewPath = Arr::first($viewPaths);
|
||||
$publishedVendorViewPath = resource_path('views/vendor');
|
||||
|
||||
if (
|
||||
($defaultViewPath !== null) &&
|
||||
is_path_within_directory($defaultViewPath, base_path()) &&
|
||||
(! is_path_within_directory($defaultViewPath, get_composer_vendor_directory())) &&
|
||||
(
|
||||
(! is_path_within_vendor_directory($defaultViewPath, base_path())) ||
|
||||
is_path_within_directory($defaultViewPath, $publishedVendorViewPath)
|
||||
)
|
||||
) {
|
||||
$paths[''] = $defaultViewPath;
|
||||
}
|
||||
|
||||
/** @var FileViewFinder $viewFinder */
|
||||
$viewFinder = $viewFactory->getFinder();
|
||||
|
||||
foreach ($viewFinder->getHints() as $namespace => $hintPaths) {
|
||||
foreach ($hintPaths as $path) {
|
||||
if (! is_path_within_directory($path, base_path())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_path_within_directory($path, get_composer_vendor_directory())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_path_within_vendor_directory($path, base_path()) && (! is_path_within_directory($path, $publishedVendorViewPath))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($path === resource_path('views/vendor/livewire')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (filled($paths[''] ?? null) && str($path)->startsWith($paths[''])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$paths[$namespace] = $path;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$options = array_map(
|
||||
fn (string $path): string => (string) str($path)->after(base_path()),
|
||||
$paths,
|
||||
);
|
||||
|
||||
$namespace = ($defaultNamespace !== null) && array_key_exists($defaultNamespace, $paths)
|
||||
? $defaultNamespace
|
||||
: (count($options) > 1
|
||||
? select(
|
||||
label: $question,
|
||||
options: $options,
|
||||
default: $this->input->isInteractive() ? null : array_key_first($options),
|
||||
)
|
||||
: array_key_first($options));
|
||||
|
||||
if (blank($namespace)) {
|
||||
return [
|
||||
$view,
|
||||
resource_path(
|
||||
(string) str($view)
|
||||
->replace('.', '/')
|
||||
->prepend('views/')
|
||||
->append('.blade.php'),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"{$namespace}::{$view}",
|
||||
(string) str($view)
|
||||
->replace('.', '/')
|
||||
->prepend("{$paths[$namespace]}/")
|
||||
->append('.blade.php'),
|
||||
];
|
||||
}
|
||||
}
|
||||
13
vendor/filament/support/src/Commands/Concerns/CanCachePanelComponents.php
vendored
Normal file
13
vendor/filament/support/src/Commands/Concerns/CanCachePanelComponents.php
vendored
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Commands\CacheComponentsCommand;
|
||||
|
||||
trait CanCachePanelComponents
|
||||
{
|
||||
protected function canCachePanelComponents(): bool
|
||||
{
|
||||
return class_exists(CacheComponentsCommand::class);
|
||||
}
|
||||
}
|
||||
89
vendor/filament/support/src/Commands/Concerns/CanGeneratePanels.php
vendored
Normal file
89
vendor/filament/support/src/Commands/Concerns/CanGeneratePanels.php
vendored
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Commands\FileGenerators\PanelProviderClassGenerator;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
trait CanGeneratePanels
|
||||
{
|
||||
use CanManipulateFiles;
|
||||
|
||||
public function generatePanel(?string $id = null, string $defaultId = '', string $placeholderId = '', bool $isForced = false): void
|
||||
{
|
||||
$id = Str::lcfirst($id ?? text(
|
||||
label: 'What is the panel\'s ID?',
|
||||
placeholder: $placeholderId,
|
||||
default: $defaultId,
|
||||
required: true,
|
||||
validate: fn (string $value) => match (true) {
|
||||
preg_match('/^[a-zA-Z].*/', $value) !== false => null,
|
||||
default => 'The ID must start with a letter, and not a number or special character.',
|
||||
},
|
||||
hint: 'It must be unique to any others you have, and is used to reference the panel in your code.',
|
||||
));
|
||||
|
||||
$basename = (string) str($id)
|
||||
->studly()
|
||||
->append('PanelProvider');
|
||||
|
||||
$path = app_path(
|
||||
(string) str($basename)
|
||||
->prepend('Providers/Filament/')
|
||||
->replace('\\', '/')
|
||||
->append('.php'),
|
||||
);
|
||||
|
||||
if (! $isForced && $this->checkForCollision([$path])) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$fqn = app()->getNamespace() . "Providers\\Filament\\{$basename}";
|
||||
|
||||
if (empty(Filament::getPanels())) {
|
||||
$this->writeFile($path, app(PanelProviderClassGenerator::class, [
|
||||
'fqn' => $fqn,
|
||||
'id' => $id,
|
||||
'isDefault' => true,
|
||||
]));
|
||||
} else {
|
||||
$this->writeFile($path, app(PanelProviderClassGenerator::class, [
|
||||
'fqn' => $fqn,
|
||||
'id' => $id,
|
||||
]));
|
||||
}
|
||||
|
||||
$hasBootstrapProvidersFile = file_exists($bootstrapProvidersPath = App::getBootstrapProvidersPath());
|
||||
|
||||
if ($hasBootstrapProvidersFile) {
|
||||
ServiceProvider::addProviderToBootstrapFile(
|
||||
$fqn,
|
||||
$bootstrapProvidersPath,
|
||||
);
|
||||
} else {
|
||||
$appConfig = file_get_contents(config_path('app.php'));
|
||||
|
||||
if (! Str::contains($appConfig, "{$fqn}::class")) {
|
||||
file_put_contents(config_path('app.php'), str_replace(
|
||||
app()->getNamespace() . 'Providers\\RouteServiceProvider::class,',
|
||||
"{$fqn}::class," . PHP_EOL . ' ' . app()->getNamespace() . 'Providers\\RouteServiceProvider::class,',
|
||||
$appConfig,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
$this->components->info("Filament panel [{$path}] created successfully.");
|
||||
|
||||
if ($hasBootstrapProvidersFile) {
|
||||
$this->components->warn("We've attempted to register the {$basename} in your [bootstrap/providers.php] file. If you get an error while trying to access your panel then this process has probably failed. You can manually register the service provider by adding it to the array.");
|
||||
} else {
|
||||
$this->components->warn("We've attempted to register the {$basename} in your [config/app.php] file as a service provider. If you get an error while trying to access your panel then this process has probably failed. You can manually register the service provider by adding it to the [providers] array.");
|
||||
}
|
||||
}
|
||||
}
|
||||
17
vendor/filament/support/src/Commands/Concerns/CanIndentStrings.php
vendored
Normal file
17
vendor/filament/support/src/Commands/Concerns/CanIndentStrings.php
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
trait CanIndentStrings /** @phpstan-ignore trait.unused */
|
||||
{
|
||||
protected function indentString(string $string, int $level = 1): string
|
||||
{
|
||||
return implode(
|
||||
PHP_EOL,
|
||||
array_map(
|
||||
fn (string $line) => ($line !== '') ? (str_repeat(' ', $level) . "{$line}") : '',
|
||||
explode(PHP_EOL, $string),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
212
vendor/filament/support/src/Commands/Concerns/CanManipulateFiles.php
vendored
Normal file
212
vendor/filament/support/src/Commands/Concerns/CanManipulateFiles.php
vendored
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\FileGenerator;
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Arr;
|
||||
use ReflectionClass;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
|
||||
trait CanManipulateFiles
|
||||
{
|
||||
/**
|
||||
* Columns already reported to the user as skipped, to avoid warning about the same column more than once per command.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $reportedSkippedColumns = [];
|
||||
|
||||
/**
|
||||
* @param string | array<string> $paths
|
||||
*/
|
||||
protected function checkForCollision(string | array $paths): bool
|
||||
{
|
||||
foreach (Arr::wrap($paths) as $path) {
|
||||
if (! $this->fileExists($path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
(! app()->runningUnitTests()) &&
|
||||
(! confirm(basename($path) . ' already exists, do you want to overwrite it?'))
|
||||
) {
|
||||
$this->components->error("{$path} already exists, aborting.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $replacements
|
||||
*/
|
||||
protected function copyStubToApp(string $stub, string $targetPath, array $replacements = []): void
|
||||
{
|
||||
$filesystem = app(Filesystem::class);
|
||||
|
||||
if (! $this->fileExists($stubPath = base_path("stubs/filament/{$stub}.stub"))) {
|
||||
$stubPath = $this->getDefaultStubPath() . "/{$stub}.stub";
|
||||
}
|
||||
|
||||
$stub = str($filesystem->get($stubPath));
|
||||
|
||||
foreach ($replacements as $key => $replacement) {
|
||||
$stub = $stub->replace("{{ {$key} }}", $replacement);
|
||||
}
|
||||
|
||||
$stub = (string) $stub;
|
||||
|
||||
$this->writeFile($targetPath, $stub);
|
||||
}
|
||||
|
||||
protected function fileExists(string $path): bool
|
||||
{
|
||||
$filesystem = app(Filesystem::class);
|
||||
|
||||
return $filesystem->exists($path);
|
||||
}
|
||||
|
||||
protected function escapeCssString(string $value): string
|
||||
{
|
||||
return (string) preg_replace_callback(
|
||||
'/[\x00-\x1F\x7F]/',
|
||||
static fn (array $matches): string => '\\' . dechex(ord($matches[0])) . ' ',
|
||||
str_replace(['\\', "'"], ['\\\\', "\\'"], $value),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getRelativePath(string $path, string $from): string
|
||||
{
|
||||
$path = $this->normalizePath($path);
|
||||
$from = $this->normalizePath($from);
|
||||
$pathSegments = explode('/', ltrim($path, '/'));
|
||||
$fromSegments = explode('/', ltrim($from, '/'));
|
||||
$isPathOnWindowsDrive = preg_match('/^[a-z]:\//i', $path) === 1;
|
||||
$isFromOnWindowsDrive = preg_match('/^[a-z]:\//i', $from) === 1;
|
||||
$isPathOnNetworkShare = str_starts_with($path, '//');
|
||||
$isFromOnNetworkShare = str_starts_with($from, '//');
|
||||
|
||||
if (
|
||||
($isPathOnWindowsDrive || $isFromOnWindowsDrive) &&
|
||||
(
|
||||
! ($isPathOnWindowsDrive && $isFromOnWindowsDrive) ||
|
||||
(strcasecmp($pathSegments[0], $fromSegments[0]) !== 0)
|
||||
)
|
||||
) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
if (
|
||||
($isPathOnNetworkShare || $isFromOnNetworkShare) &&
|
||||
(
|
||||
! ($isPathOnNetworkShare && $isFromOnNetworkShare) ||
|
||||
(strcasecmp($pathSegments[0], $fromSegments[0]) !== 0) ||
|
||||
(strcasecmp($pathSegments[1], $fromSegments[1]) !== 0)
|
||||
)
|
||||
) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
if (str_starts_with($path, '/') !== str_starts_with($from, '/')) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
$isCaseInsensitive = $isPathOnWindowsDrive || $isPathOnNetworkShare;
|
||||
|
||||
while (
|
||||
filled($pathSegments) &&
|
||||
filled($fromSegments) &&
|
||||
($isCaseInsensitive
|
||||
? (strcasecmp($pathSegments[0], $fromSegments[0]) === 0)
|
||||
: ($pathSegments[0] === $fromSegments[0]))
|
||||
) {
|
||||
array_shift($pathSegments);
|
||||
array_shift($fromSegments);
|
||||
}
|
||||
|
||||
return str_repeat('../', count($fromSegments)) . implode('/', $pathSegments);
|
||||
}
|
||||
|
||||
protected function normalizePath(string $path): string
|
||||
{
|
||||
$isNetworkPath = str_starts_with($path, '\\\\') || str_starts_with($path, '//');
|
||||
$isAbsolute = str_starts_with($path, '/') || str_starts_with($path, '\\');
|
||||
$normalizedSegments = [];
|
||||
|
||||
foreach (explode('/', str_replace('\\', '/', $path)) as $segment) {
|
||||
if (($segment === '') || ($segment === '.')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (($segment === '..') && filled($normalizedSegments) && (array_last($normalizedSegments) !== '..')) {
|
||||
array_pop($normalizedSegments);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$normalizedSegments[] = $segment;
|
||||
}
|
||||
|
||||
return ($isNetworkPath ? '//' : ($isAbsolute ? '/' : '')) . implode('/', $normalizedSegments);
|
||||
}
|
||||
|
||||
protected function writeFile(string $path, string | FileGenerator $contents): void
|
||||
{
|
||||
$filesystem = app(Filesystem::class);
|
||||
|
||||
$filesystem->ensureDirectoryExists(
|
||||
pathinfo($path, PATHINFO_DIRNAME),
|
||||
);
|
||||
|
||||
if ($contents instanceof FileGenerator) {
|
||||
$filesystem->put($path, $contents->generate());
|
||||
|
||||
if ($contents instanceof HasSkippedColumns) {
|
||||
$this->reportSkippedColumns($contents->getSkippedColumns());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$filesystem->put($path, $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $skippedColumns Column names, keyed by name with their database type as the value.
|
||||
*/
|
||||
protected function reportSkippedColumns(array $skippedColumns): void
|
||||
{
|
||||
$newlySkippedColumns = array_diff_key($skippedColumns, $this->reportedSkippedColumns);
|
||||
|
||||
if (empty($newlySkippedColumns)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->reportedSkippedColumns = [
|
||||
...$this->reportedSkippedColumns,
|
||||
...$newlySkippedColumns,
|
||||
];
|
||||
|
||||
$columnsList = collect($newlySkippedColumns)
|
||||
->map(fn (string $type, string $name): string => "{$name} ({$type})")
|
||||
->join(', ');
|
||||
|
||||
$this->components->warn("Binary columns were skipped, as they cannot be displayed in the browser: {$columnsList}. Add them to your model's `\$hidden` property to prevent errors.");
|
||||
}
|
||||
|
||||
protected function getDefaultStubPath(): string
|
||||
{
|
||||
$reflectionClass = new ReflectionClass($this);
|
||||
|
||||
return (string) str($reflectionClass->getFileName())
|
||||
->beforeLast('Commands')
|
||||
->append('../stubs');
|
||||
}
|
||||
}
|
||||
27
vendor/filament/support/src/Commands/Concerns/CanOpenUrlInBrowser.php
vendored
Normal file
27
vendor/filament/support/src/Commands/Concerns/CanOpenUrlInBrowser.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
trait CanOpenUrlInBrowser
|
||||
{
|
||||
public function openUrlInBrowser(string $url): void
|
||||
{
|
||||
$result = -1;
|
||||
|
||||
if (PHP_OS_FAMILY === 'Darwin') {
|
||||
exec('open "' . $url . '"', result_code: $result);
|
||||
}
|
||||
if (PHP_OS_FAMILY === 'Linux') {
|
||||
exec('xdg-open "' . $url . '"', result_code: $result);
|
||||
}
|
||||
if (PHP_OS_FAMILY === 'Windows') {
|
||||
exec('start "" "' . $url . '"', result_code: $result);
|
||||
}
|
||||
|
||||
if ($result !== 0) {
|
||||
$this->components->error('An error occurred while trying to open the page in your browser.');
|
||||
$this->output->writeln(' <comment>Please open the following URL in your browser:</>');
|
||||
$this->output->writeln(' <href="' . $url . '">' . $url . '</>');
|
||||
}
|
||||
}
|
||||
}
|
||||
287
vendor/filament/support/src/Commands/Concerns/CanReadModelSchemas.php
vendored
Normal file
287
vendor/filament/support/src/Commands/Concerns/CanReadModelSchemas.php
vendored
Normal file
|
|
@ -0,0 +1,287 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Schema\Builder;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Str;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
|
||||
trait CanReadModelSchemas
|
||||
{
|
||||
/**
|
||||
* @return class-string<Model>|null
|
||||
*/
|
||||
protected function parseModel(string $model): ?string
|
||||
{
|
||||
if (! class_exists($model)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
protected function getModelSchema(string $model): Builder
|
||||
{
|
||||
return app($model)
|
||||
->getConnection()
|
||||
->getSchemaBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
protected function getModelTable(string $model): string
|
||||
{
|
||||
return app($model)->getTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
protected function guessBelongsToRelationshipName(string $column, string $model): ?string
|
||||
{
|
||||
/** @var Model $modelInstance */
|
||||
$modelInstance = app($model);
|
||||
$modelInstanceReflection = new ReflectionClass($modelInstance);
|
||||
$guessedRelationshipName = str($column)->beforeLast('_id');
|
||||
$hasRelationship = $modelInstanceReflection->hasMethod($guessedRelationshipName);
|
||||
|
||||
if (! $hasRelationship) {
|
||||
$guessedRelationshipName = $guessedRelationshipName->camel();
|
||||
$hasRelationship = $modelInstanceReflection->hasMethod($guessedRelationshipName);
|
||||
}
|
||||
|
||||
if (! $hasRelationship) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$type = $modelInstanceReflection->getMethod($guessedRelationshipName)->getReturnType();
|
||||
|
||||
if (
|
||||
(! $type) ||
|
||||
(! method_exists($type, 'getName')) ||
|
||||
($type->getName() !== BelongsTo::class)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
} catch (ReflectionException $exception) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $guessedRelationshipName;
|
||||
}
|
||||
|
||||
protected function guessBelongsToRelationshipTableName(string $column): ?string
|
||||
{
|
||||
$tableName = str($column)->beforeLast('_id');
|
||||
|
||||
if (Schema::hasTable(Str::plural($tableName))) {
|
||||
return Str::plural($tableName);
|
||||
}
|
||||
|
||||
if (! Schema::hasTable($tableName)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
protected function guessBelongsToRelationshipTitleColumnName(string $column, string $model): string
|
||||
{
|
||||
$schema = $this->getModelSchema($model);
|
||||
$table = $this->getModelTable($model);
|
||||
|
||||
$columns = collect($schema->getColumnListing($table));
|
||||
|
||||
if ($columns->contains('name')) {
|
||||
return 'name';
|
||||
}
|
||||
|
||||
if ($columns->contains('title')) {
|
||||
return 'title';
|
||||
}
|
||||
|
||||
return collect($schema->getIndexes($table))
|
||||
->firstWhere('primary')['columns'][0] ?? 'id';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $column
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
protected function parseColumnType(array $column): array
|
||||
{
|
||||
$type = match ($column['type']) {
|
||||
'tinyint(1)', 'bit' => 'boolean',
|
||||
'varchar(max)', 'nvarchar(max)' => 'text',
|
||||
default => null,
|
||||
};
|
||||
|
||||
$type ??= match ($column['type_name']) {
|
||||
'boolean', 'bool' => 'boolean',
|
||||
'char', 'bpchar', 'nchar' => 'char',
|
||||
'varchar', 'nvarchar' => 'string',
|
||||
'integer', 'int', 'int4', 'tinyint', 'smallint', 'int2', 'mediumint', 'bigint', 'int8' => 'integer',
|
||||
'decimal', 'numeric' => 'decimal',
|
||||
'float', 'real', 'float4' => 'float',
|
||||
'double', 'float8' => 'double',
|
||||
'money', 'smallmoney' => 'money',
|
||||
'date' => 'date',
|
||||
'time', 'timetz' => 'time',
|
||||
'datetime', 'datetime2', 'smalldatetime', 'datetimeoffset' => 'datetime',
|
||||
'timestamp', 'timestamptz' => 'timestamp',
|
||||
'text', 'tinytext', 'longtext', 'mediumtext', 'ntext' => 'text',
|
||||
'json', 'jsonb' => 'json',
|
||||
'binary', 'varbinary', 'blob', 'tinyblob', 'mediumblob', 'longblob', 'bytea' => 'binary',
|
||||
'geometry', 'geography', 'point', 'linestring', 'polygon', 'multipoint', 'multilinestring', 'multipolygon', 'geometrycollection', 'geomcollection' => 'binary',
|
||||
default => $column['type_name'],
|
||||
};
|
||||
|
||||
$values = str_contains($column['type'], '(')
|
||||
? str_getcsv(Str::between($column['type'], '(', ')'), enclosure: "'", escape: '\\')
|
||||
: null;
|
||||
|
||||
$values = is_null($values) ? [] : match ($type) {
|
||||
'string', 'char', 'binary', 'bit' => ['length' => (int) $values[0]],
|
||||
'enum' => ['values' => array_map(fn (string $value): string => trim($value, '\''), $values)],
|
||||
default => [],
|
||||
};
|
||||
|
||||
return array_merge(['name' => $type], array_filter($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Columns skipped while reading the model schema, keyed by column name with their database type as the value.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected array $skippedColumns = [];
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $type
|
||||
*/
|
||||
protected function canGenerateSchemaComponentForColumnType(array $type): bool
|
||||
{
|
||||
// Binary and spatial columns (`blob`, `geometry`, `point`, etc.) hold data that
|
||||
// is not valid UTF-8, so it cannot be serialized to JavaScript for a schema component.
|
||||
return $type['name'] !== 'binary';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
* @param array<string, mixed> $column
|
||||
*/
|
||||
protected function recordSkippedColumn(string $model, array $column): void
|
||||
{
|
||||
// A column that is already `$hidden` is excluded from the model's array representation, so it cannot cause errors and does not need a warning.
|
||||
if (in_array($column['name'], app($model)->getHidden(), strict: true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->skippedColumns[$column['name']] = $column['type_name'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getSkippedColumns(): array
|
||||
{
|
||||
return $this->skippedColumns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $column
|
||||
* @param class-string<Model> $model
|
||||
*/
|
||||
protected function parseDefaultExpression(array $column, string $model): mixed
|
||||
{
|
||||
$default = $column['default'];
|
||||
|
||||
if (blank($default)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$driver = app($model)->getConnection()->getDriverName();
|
||||
|
||||
if (in_array($driver, ['mysql', 'mariadb'])) {
|
||||
if ($default === 'NULL'
|
||||
|| preg_match("/^\(.*\)$/", $default) === 1
|
||||
|| str_ends_with($default, '()')
|
||||
|| str_starts_with(strtolower($default), 'current_timestamp')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match("/^'(.*)'$/", $default, $matches) === 1) {
|
||||
return str_replace("''", "'", $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($driver === 'pgsql') {
|
||||
if (str_starts_with($default, 'NULL::')) {
|
||||
$default = null;
|
||||
}
|
||||
|
||||
if (preg_match("/^['(](.*)[')]::/", $default, $matches) === 1) {
|
||||
return str_replace("''", "'", $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($driver === 'sqlsrv') {
|
||||
while (preg_match('/^\((.*)\)$/', $default, $matches)) {
|
||||
$default = $matches[1];
|
||||
}
|
||||
|
||||
if ($default === 'NULL'
|
||||
|| str_ends_with($default, '()')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^\'(.*)\'$/', $default, $matches) === 1) {
|
||||
return str_replace("''", "'", $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if ($driver === 'sqlite') {
|
||||
if ($default === 'NULL'
|
||||
|| str_starts_with(strtolower($default), 'current_timestamp')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/^\'(.*)\'$/s', $default, $matches) === 1) {
|
||||
return str_replace("''", "'", $matches[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
public function getRecordTitleAttribute(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string<Model> $model
|
||||
* @return array<string>
|
||||
*/
|
||||
protected function getEnumCasts(string $model): array
|
||||
{
|
||||
$casts = app($model)->getCasts();
|
||||
|
||||
return array_filter(
|
||||
$casts,
|
||||
fn (mixed $cast): bool => is_string($cast) ? enum_exists($cast) : false,
|
||||
);
|
||||
}
|
||||
}
|
||||
175
vendor/filament/support/src/Commands/Concerns/HasCluster.php
vendored
Normal file
175
vendor/filament/support/src/Commands/Concerns/HasCluster.php
vendored
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Clusters\Cluster;
|
||||
use ReflectionClass;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\search;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
trait HasCluster
|
||||
{
|
||||
/**
|
||||
* @var ?class-string<Cluster>
|
||||
*/
|
||||
protected ?string $clusterFqn = null;
|
||||
|
||||
protected function configureClusterFqn(string $initialQuestion, string $question): void
|
||||
{
|
||||
$this->clusterFqn = $this->askForCluster($initialQuestion, $question, $this->option('cluster'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?class-string<Cluster>
|
||||
*/
|
||||
protected function askForCluster(string $initialQuestion, string $question, ?string $initialValue = null): ?string
|
||||
{
|
||||
$clusterFqns = array_values($this->panel->getClusters());
|
||||
|
||||
if (
|
||||
blank($initialValue) &&
|
||||
(empty($clusterFqns) || (! confirm(
|
||||
label: $initialQuestion,
|
||||
default: false,
|
||||
)))
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($initialValue)) {
|
||||
$cluster = (string) str($initialValue)
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
|
||||
if (! class_exists($cluster)) {
|
||||
$this->components->warn('The cluster class provided does not exist.');
|
||||
} elseif (! is_subclass_of($cluster, Cluster::class)) {
|
||||
$this->components->warn('The cluster class or one of its parents must extend [' . Cluster::class . '].');
|
||||
} else {
|
||||
return $cluster;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($clusterFqns)) {
|
||||
$clusterFqn = (string) str(text(
|
||||
label: "No clusters were found within the [{$this->panel->getId()}] panel. {$question}",
|
||||
placeholder: app()->getNamespace() . 'Filament\\Clusters\\Blog',
|
||||
required: true,
|
||||
validate: function (string $value): ?string {
|
||||
$value = (string) str($value)
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
|
||||
if (
|
||||
(! class_exists($value)) &&
|
||||
class_exists("{$value}\\" . class_basename($value) . 'Cluster')
|
||||
) {
|
||||
$value = "{$value}\\" . class_basename($value) . 'Cluster';
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
! class_exists($value) => 'The cluster class doesn\'t exist, please use the fully-qualified class name.',
|
||||
! is_subclass_of($value, Cluster::class) => 'The cluster class or one of its parents must extend [' . Cluster::class . '].',
|
||||
default => null,
|
||||
};
|
||||
},
|
||||
hint: 'Please provide the fully-qualified class name of the cluster.',
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->replace('/', '\\');
|
||||
|
||||
if (
|
||||
(! class_exists($clusterFqn)) &&
|
||||
class_exists("{$clusterFqn}\\" . class_basename($clusterFqn) . 'Cluster')
|
||||
) {
|
||||
return "{$clusterFqn}\\" . class_basename($clusterFqn) . 'Cluster';
|
||||
}
|
||||
|
||||
return $clusterFqn;
|
||||
}
|
||||
|
||||
return search(
|
||||
label: $question,
|
||||
options: function (?string $search) use ($clusterFqns): array {
|
||||
if (blank($search)) {
|
||||
return $clusterFqns;
|
||||
}
|
||||
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return collect($clusterFqns)
|
||||
->filter(fn (string $fqn): bool => str($fqn)->replace(['\\', '/'], '')->contains($search, ignoreCase: true))
|
||||
->mapWithKeys(function (string $fqn): array {
|
||||
$basenameBeforeCluster = (string) str($fqn)
|
||||
->classBasename()
|
||||
->beforeLast('Cluster');
|
||||
|
||||
$namespacePartBeforeBasename = (string) str($fqn)
|
||||
->beforeLast('\\')
|
||||
->classBasename();
|
||||
|
||||
if ($basenameBeforeCluster === $namespacePartBeforeBasename) {
|
||||
return [$fqn => (string) str($fqn)->beforeLast('\\')];
|
||||
}
|
||||
|
||||
return [$fqn => $fqn];
|
||||
})
|
||||
->all();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureClusterResourcesLocation(): void
|
||||
{
|
||||
[
|
||||
$this->resourcesNamespace, /** @phpstan-ignore-line */
|
||||
$this->resourcesDirectory, /** @phpstan-ignore-line */
|
||||
] = $this->getClusterResourcesLocation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?class-string<Cluster> $clusterFqn
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string
|
||||
* }
|
||||
*/
|
||||
public function getClusterResourcesLocation(?string $clusterFqn = null): array
|
||||
{
|
||||
$clusterFqn ??= $this->clusterFqn;
|
||||
|
||||
$clusterBasenameBeforeCluster = (string) str($clusterFqn)
|
||||
->classBasename()
|
||||
->beforeLast('Cluster');
|
||||
|
||||
$clusterNamespacePartBeforeBasename = (string) str($clusterFqn)
|
||||
->beforeLast('\\')
|
||||
->classBasename();
|
||||
|
||||
if ($clusterBasenameBeforeCluster === $clusterNamespacePartBeforeBasename) {
|
||||
return [
|
||||
(string) str($clusterFqn)
|
||||
->beforeLast('\\')
|
||||
->append('\\Resources'),
|
||||
(string) str((new ReflectionClass($clusterFqn))->getFileName())
|
||||
->beforeLast(DIRECTORY_SEPARATOR)
|
||||
->append('/Resources'),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
"{$clusterFqn}\\Resources",
|
||||
(string) str((new ReflectionClass($clusterFqn))->getFileName())
|
||||
->beforeLast('.')
|
||||
->append('/Resources'),
|
||||
];
|
||||
}
|
||||
}
|
||||
35
vendor/filament/support/src/Commands/Concerns/HasClusterPagesLocation.php
vendored
Normal file
35
vendor/filament/support/src/Commands/Concerns/HasClusterPagesLocation.php
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
trait HasClusterPagesLocation
|
||||
{
|
||||
protected function configureClusterPagesLocation(): void
|
||||
{
|
||||
$clusterBasenameBeforeCluster = (string) str($this->clusterFqn)
|
||||
->classBasename()
|
||||
->beforeLast('Cluster');
|
||||
|
||||
$clusterNamespacePartBeforeBasename = (string) str($this->clusterFqn)
|
||||
->beforeLast('\\')
|
||||
->classBasename();
|
||||
|
||||
if ($clusterBasenameBeforeCluster === $clusterNamespacePartBeforeBasename) {
|
||||
$this->pagesNamespace = (string) str($this->clusterFqn)
|
||||
->beforeLast('\\')
|
||||
->append('\\Pages');
|
||||
$this->pagesDirectory = (string) str((new ReflectionClass($this->clusterFqn))->getFileName())
|
||||
->beforeLast(DIRECTORY_SEPARATOR)
|
||||
->append('/Pages');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->pagesNamespace = "{$this->clusterFqn}\\Pages";
|
||||
$this->pagesDirectory = (string) str((new ReflectionClass($this->clusterFqn))->getFileName())
|
||||
->beforeLast('.')
|
||||
->append('/Pages');
|
||||
}
|
||||
}
|
||||
63
vendor/filament/support/src/Commands/Concerns/HasPanel.php
vendored
Normal file
63
vendor/filament/support/src/Commands/Concerns/HasPanel.php
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Filament\Exceptions\NoDefaultPanelSetException;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\select;
|
||||
|
||||
trait HasPanel
|
||||
{
|
||||
protected ?Panel $panel;
|
||||
|
||||
protected function configurePanel(string $question, ?string $initialQuestion = null): void
|
||||
{
|
||||
if (! class_exists(Panel::class)) {
|
||||
$this->panel = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$panelName = ($this->hasArgument('panel') ? $this->argument('panel') : null) ?? $this->option('panel'); /** @phpstan-ignore-line */
|
||||
$this->panel = filled($panelName) ? Filament::getPanel($panelName, isStrict: false) : null;
|
||||
|
||||
if ($this->panel) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filled($initialQuestion) && (! confirm(label: $initialQuestion))) {
|
||||
$this->panel = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$panels = Filament::getPanels();
|
||||
|
||||
if (count($panels) > 1) {
|
||||
try {
|
||||
$defaultPanelId = Filament::getDefaultPanel()->getId();
|
||||
} catch (NoDefaultPanelSetException) {
|
||||
$defaultPanelId = null;
|
||||
}
|
||||
|
||||
/** @var Panel $panel */
|
||||
$panel = $panels[select(
|
||||
label: $question,
|
||||
options: array_map(
|
||||
fn (Panel $panel): string => $panel->getId(),
|
||||
$panels,
|
||||
),
|
||||
default: $defaultPanelId,
|
||||
)];
|
||||
} else {
|
||||
/** @var Panel $panel */
|
||||
$panel = Arr::first($panels);
|
||||
}
|
||||
|
||||
$this->panel = $panel;
|
||||
}
|
||||
}
|
||||
81
vendor/filament/support/src/Commands/Concerns/HasResourcesLocation.php
vendored
Normal file
81
vendor/filament/support/src/Commands/Concerns/HasResourcesLocation.php
vendored
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Concerns;
|
||||
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use function Filament\Support\is_path_within_vendor_directory;
|
||||
use function Laravel\Prompts\search;
|
||||
|
||||
trait HasResourcesLocation
|
||||
{
|
||||
protected string $resourcesNamespace;
|
||||
|
||||
protected string $resourcesDirectory;
|
||||
|
||||
protected function configureResourcesLocation(string $question): void
|
||||
{
|
||||
if (filled($this->clusterFqn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
[
|
||||
$this->resourcesNamespace,
|
||||
$this->resourcesDirectory,
|
||||
] = $this->getResourcesLocation($question);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{
|
||||
* 0: string,
|
||||
* 1: string,
|
||||
* }
|
||||
*/
|
||||
public function getResourcesLocation(string $question): array
|
||||
{
|
||||
$directories = $this->panel->getResourceDirectories();
|
||||
$namespaces = $this->panel->getResourceNamespaces();
|
||||
|
||||
foreach ($directories as $index => $directory) {
|
||||
if (is_path_within_vendor_directory($directory, base_path())) {
|
||||
unset($directories[$index]);
|
||||
unset($namespaces[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($namespaces) < 2) {
|
||||
return [
|
||||
(Arr::first($namespaces) ?? app()->getNamespace() . 'Filament\\Resources'),
|
||||
(Arr::first($directories) ?? app_path('Filament/Resources/')),
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->option('resource-namespace')) {
|
||||
return [
|
||||
(string) $this->option('resource-namespace'),
|
||||
$directories[array_search($this->option('resource-namespace'), $namespaces)],
|
||||
];
|
||||
}
|
||||
|
||||
$keyedNamespaces = array_combine(
|
||||
$namespaces,
|
||||
$namespaces,
|
||||
);
|
||||
|
||||
return [
|
||||
$namespace = search(
|
||||
label: $question,
|
||||
options: function (?string $search) use ($keyedNamespaces): array {
|
||||
if (blank($search)) {
|
||||
return $keyedNamespaces;
|
||||
}
|
||||
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
return array_filter($keyedNamespaces, fn (string $namespace): bool => str($namespace)->replace(['\\', '/'], '')->contains($search, ignoreCase: true));
|
||||
},
|
||||
),
|
||||
$directories[array_search($namespace, $namespaces)],
|
||||
];
|
||||
}
|
||||
}
|
||||
7
vendor/filament/support/src/Commands/Exceptions/FailureCommandOutput.php
vendored
Normal file
7
vendor/filament/support/src/Commands/Exceptions/FailureCommandOutput.php
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FailureCommandOutput extends Exception {}
|
||||
7
vendor/filament/support/src/Commands/Exceptions/SuccessCommandOutput.php
vendored
Normal file
7
vendor/filament/support/src/Commands/Exceptions/SuccessCommandOutput.php
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class SuccessCommandOutput extends Exception {}
|
||||
143
vendor/filament/support/src/Commands/FileGenerators/ClassGenerator.php
vendored
Normal file
143
vendor/filament/support/src/Commands/FileGenerators/ClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators;
|
||||
|
||||
use Filament\Support\Commands\FileGenerators\Concerns\CanCheckFileGenerationFlags;
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\FileGenerator;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\PhpFile;
|
||||
use Nette\PhpGenerator\PhpNamespace;
|
||||
use Nette\PhpGenerator\Printer;
|
||||
use Nette\PhpGenerator\PsrPrinter;
|
||||
|
||||
abstract class ClassGenerator implements FileGenerator
|
||||
{
|
||||
use CanCheckFileGenerationFlags;
|
||||
|
||||
protected PhpNamespace $namespace;
|
||||
|
||||
public function getFile(): PhpFile
|
||||
{
|
||||
$file = (new PhpFile);
|
||||
$this->configureFile($file);
|
||||
|
||||
$this->namespace = $file->addNamespace($this->getNamespace());
|
||||
$this->useImportsInNamespace($this->namespace, $this->getImports());
|
||||
$this->configureNamespace($this->namespace);
|
||||
|
||||
$class = $this->namespace->addClass($this->getBasename());
|
||||
|
||||
if (filled($extends = $this->getExtends())) {
|
||||
$class->setExtends($extends);
|
||||
}
|
||||
|
||||
foreach ($this->getImplements() as $implement) {
|
||||
$class->addImplement($implement);
|
||||
}
|
||||
|
||||
$this->addTraitsToClass($class);
|
||||
$this->addPropertiesToClass($class);
|
||||
$this->addMethodsToClass($class);
|
||||
$this->configureClass($class);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
protected function configureFile(PhpFile $file): void {}
|
||||
|
||||
protected function configureNamespace(PhpNamespace $namespace): void {}
|
||||
|
||||
protected function configureClass(ClassType $class): void {}
|
||||
|
||||
protected function addTraitsToClass(ClassType $class): void {}
|
||||
|
||||
protected function addPropertiesToClass(ClassType $class): void {}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void {}
|
||||
|
||||
/**
|
||||
* @return ?class-string
|
||||
*/
|
||||
public function getExtends(): ?string
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string>
|
||||
*/
|
||||
public function getImplements(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $name
|
||||
*/
|
||||
public function simplifyFqn(string $name): string
|
||||
{
|
||||
return $this->namespace->simplifyName($name);
|
||||
}
|
||||
|
||||
abstract public function getBasename(): string;
|
||||
|
||||
abstract public function getNamespace(): string;
|
||||
|
||||
protected function extractNamespace(string $fqn): string
|
||||
{
|
||||
return (string) str($fqn)->beforeLast('\\');
|
||||
}
|
||||
|
||||
public function hasPartialImports(): bool
|
||||
{
|
||||
return $this->hasFileGenerationFlag(FileGenerationFlag::PARTIAL_IMPORTS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $imports
|
||||
*/
|
||||
protected function useImportsInNamespace(PhpNamespace $namespace, array $imports): void
|
||||
{
|
||||
foreach ($imports as $key => $import) {
|
||||
if (is_string($key)) {
|
||||
$namespace->addUse($key, alias: $import);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$namespace->addUse($import);
|
||||
}
|
||||
}
|
||||
|
||||
protected function importUnlessPartial(string $class): void
|
||||
{
|
||||
if ($this->hasPartialImports()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->namespace->addUse($class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getPrinter(): Printer
|
||||
{
|
||||
$printer = new PsrPrinter;
|
||||
$printer->linesBetweenProperties = 1;
|
||||
|
||||
return $printer;
|
||||
}
|
||||
|
||||
protected function configurePrinter(Printer $printer): void {}
|
||||
|
||||
public function generate(): string
|
||||
{
|
||||
return $this->getPrinter()->printFile($this->getFile());
|
||||
}
|
||||
}
|
||||
11
vendor/filament/support/src/Commands/FileGenerators/Concerns/CanCheckFileGenerationFlags.php
vendored
Normal file
11
vendor/filament/support/src/Commands/FileGenerators/Concerns/CanCheckFileGenerationFlags.php
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators\Concerns;
|
||||
|
||||
trait CanCheckFileGenerationFlags
|
||||
{
|
||||
protected function hasFileGenerationFlag(string $flag): bool
|
||||
{
|
||||
return in_array($flag, config('filament.file_generation.flags') ?? []);
|
||||
}
|
||||
}
|
||||
19
vendor/filament/support/src/Commands/FileGenerators/Concerns/CanGenerateViewProperty.php
vendored
Normal file
19
vendor/filament/support/src/Commands/FileGenerators/Concerns/CanGenerateViewProperty.php
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators\Concerns;
|
||||
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Property;
|
||||
|
||||
trait CanGenerateViewProperty
|
||||
{
|
||||
protected function addViewPropertyToClass(ClassType $class): void
|
||||
{
|
||||
$property = $class->addProperty('view', $this->getView())
|
||||
->setProtected()
|
||||
->setType('string');
|
||||
$this->configureViewProperty($property);
|
||||
}
|
||||
|
||||
protected function configureViewProperty(Property $property): void {}
|
||||
}
|
||||
8
vendor/filament/support/src/Commands/FileGenerators/Contracts/FileGenerator.php
vendored
Normal file
8
vendor/filament/support/src/Commands/FileGenerators/Contracts/FileGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators\Contracts;
|
||||
|
||||
interface FileGenerator
|
||||
{
|
||||
public function generate(): string;
|
||||
}
|
||||
11
vendor/filament/support/src/Commands/FileGenerators/Contracts/HasSkippedColumns.php
vendored
Normal file
11
vendor/filament/support/src/Commands/FileGenerators/Contracts/HasSkippedColumns.php
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators\Contracts;
|
||||
|
||||
interface HasSkippedColumns
|
||||
{
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function getSkippedColumns(): array;
|
||||
}
|
||||
16
vendor/filament/support/src/Commands/FileGenerators/FileGenerationFlag.php
vendored
Normal file
16
vendor/filament/support/src/Commands/FileGenerators/FileGenerationFlag.php
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands\FileGenerators;
|
||||
|
||||
class FileGenerationFlag
|
||||
{
|
||||
const EMBEDDED_PANEL_RESOURCE_SCHEMAS = 'embedded_panel_resource_schemas';
|
||||
|
||||
const EMBEDDED_PANEL_RESOURCE_TABLES = 'embedded_panel_resource_tables';
|
||||
|
||||
const PANEL_CLUSTER_CLASSES_OUTSIDE_DIRECTORIES = 'panel_cluster_classes_outside_directories';
|
||||
|
||||
const PANEL_RESOURCE_CLASSES_OUTSIDE_DIRECTORIES = 'panel_resource_classes_outside_directories';
|
||||
|
||||
const PARTIAL_IMPORTS = 'partial_imports';
|
||||
}
|
||||
306
vendor/filament/support/src/Commands/InstallCommand.php
vendored
Normal file
306
vendor/filament/support/src/Commands/InstallCommand.php
vendored
Normal file
|
|
@ -0,0 +1,306 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Filament\PanelProvider;
|
||||
use Filament\Support\Commands\Concerns\CanGeneratePanels;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Concerns\CanOpenUrlInBrowser;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Laravel\Prompts\confirm;
|
||||
|
||||
#[AsCommand(name: 'filament:install', aliases: [
|
||||
'install:filament',
|
||||
])]
|
||||
class InstallCommand extends Command
|
||||
{
|
||||
use CanGeneratePanels;
|
||||
use CanManipulateFiles;
|
||||
use CanOpenUrlInBrowser;
|
||||
|
||||
protected $description = 'Install Filament';
|
||||
|
||||
protected $name = 'filament:install';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'install:filament',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'panels',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Install the panel builder and create the first panel',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'scaffold',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Install the Filament packages for use outside of panels, in your Blade or Livewire application',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'notifications',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Install the Filament flash notifications into the scaffolded layout file',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function __invoke(): int
|
||||
{
|
||||
try {
|
||||
$this->installAdminPanel();
|
||||
$this->installScaffolding();
|
||||
$this->installUpgradeCommand();
|
||||
$this->ignorePublishedAssets();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->call(UpgradeCommand::class);
|
||||
|
||||
$this->askToStar();
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function installAdminPanel(): void
|
||||
{
|
||||
if (! $this->option('panels')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! class_exists(PanelProvider::class)) {
|
||||
$this->components->error('Please require [filament/filament] before attempting to install the Panel Builder.');
|
||||
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->generatePanel(defaultId: 'admin', isForced: $this->option('force'));
|
||||
}
|
||||
|
||||
protected function installScaffolding(): void
|
||||
{
|
||||
if (! $this->option('scaffold')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$filesystem = app(Filesystem::class);
|
||||
$filesystem->copyDirectory(__DIR__ . '/../../stubs/scaffolding', base_path());
|
||||
|
||||
$hasNotifications = false;
|
||||
|
||||
if (
|
||||
InstalledVersions::isInstalled('filament/notifications') &&
|
||||
($this->option('notifications') || confirm(
|
||||
label: 'Do you want to send flash notifications using Filament?',
|
||||
default: true,
|
||||
))
|
||||
) {
|
||||
$layout = $filesystem->get(resource_path('views/layouts/app.blade.php'));
|
||||
$layout = (string) str($layout)
|
||||
->replace('{{ $slot }}', '{{ $slot }}' . PHP_EOL . PHP_EOL . ' @livewire(\'notifications\')');
|
||||
$filesystem->put(resource_path('views/layouts/app.blade.php'), $layout);
|
||||
|
||||
$hasNotifications = true;
|
||||
}
|
||||
|
||||
$cssDirectory = resource_path('css');
|
||||
$packagesCssImports = collect([
|
||||
'support',
|
||||
'actions',
|
||||
'forms',
|
||||
'infolists',
|
||||
...($hasNotifications ? ['notifications'] : []),
|
||||
'schemas',
|
||||
'tables',
|
||||
'widgets',
|
||||
])
|
||||
->filter(fn (string $package): bool => InstalledVersions::isInstalled("filament/{$package}"))
|
||||
->map(function (string $package) use ($cssDirectory): string {
|
||||
$packageCssPath = $this->getRelativePath(
|
||||
(string) InstalledVersions::getInstallPath("filament/{$package}") . '/resources/css/index.css',
|
||||
$cssDirectory,
|
||||
);
|
||||
|
||||
return "@import '{$this->escapeCssString($packageCssPath)}';";
|
||||
})
|
||||
->implode(PHP_EOL);
|
||||
|
||||
$paginationViewsPath = $this->escapeCssString(
|
||||
$this->getRelativePath(
|
||||
(string) InstalledVersions::getInstallPath('laravel/framework') . '/src/Illuminate/Pagination/resources/views',
|
||||
$cssDirectory,
|
||||
),
|
||||
);
|
||||
|
||||
$css = $filesystem->get(resource_path('css/app.css'));
|
||||
$css = (string) str($css)
|
||||
->replace('{{ filamentCssImports }}', $packagesCssImports)
|
||||
->replace('{{ laravelPaginationViewsPath }}', $paginationViewsPath);
|
||||
$filesystem->put(resource_path('css/app.css'), $css);
|
||||
|
||||
$this->components->info('Scaffolding installed successfully.');
|
||||
|
||||
$this->components->info('Please run `npm run build` to compile your new assets.');
|
||||
}
|
||||
|
||||
protected function installUpgradeCommand(): void
|
||||
{
|
||||
$path = base_path('composer.json');
|
||||
|
||||
if (! file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$configuration = json_decode(file_get_contents($path), associative: true);
|
||||
|
||||
if (! is_array($configuration)) {
|
||||
$this->components->warn('Could not update [composer.json] because it could not be parsed as JSON. Please add "@php artisan filament:upgrade" to the "post-autoload-dump" scripts manually.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$command = '@php artisan filament:upgrade';
|
||||
|
||||
if (in_array($command, $configuration['scripts']['post-autoload-dump'] ?? [])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$configuration['scripts']['post-autoload-dump'] ??= [];
|
||||
$configuration['scripts']['post-autoload-dump'][] = $command;
|
||||
|
||||
file_put_contents(
|
||||
$path,
|
||||
(string) str(json_encode($configuration, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES))
|
||||
->append(PHP_EOL)
|
||||
->replace(
|
||||
search: " \"keywords\": [\n \"laravel\",\n \"framework\"\n ],",
|
||||
replace: ' "keywords": ["laravel", "framework"],',
|
||||
)
|
||||
->replace(
|
||||
search: " \"keywords\": [\n \"framework\",\n \"laravel\"\n ],",
|
||||
replace: ' "keywords": ["framework", "laravel"],',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
protected function ignorePublishedAssets(): void
|
||||
{
|
||||
$path = base_path('.gitignore');
|
||||
|
||||
if (! file_exists($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$contents = file_get_contents($path);
|
||||
|
||||
preg_match('/\r\n|\n|\r/', $contents, $lineEndingMatches);
|
||||
|
||||
$lineEnding = $lineEndingMatches[0] ?? PHP_EOL;
|
||||
|
||||
$lines = preg_split('/\r\n|\n|\r/', $contents);
|
||||
|
||||
$existingRules = collect($lines)
|
||||
->map(fn (string $rule): string => trim(rtrim($rule), '/'))
|
||||
->all();
|
||||
|
||||
$assetsPath = trim((string) config('filament.assets_path'), '/');
|
||||
|
||||
$newRules = collect(['css', 'fonts', 'js'])
|
||||
->map(fn (string $directory): string => collect(['public', $assetsPath, $directory, 'filament'])
|
||||
->filter()
|
||||
->implode('/'))
|
||||
->reject(fn (string $rule): bool => in_array($rule, $existingRules))
|
||||
->all();
|
||||
|
||||
if (blank($newRules)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($newRules as $newRule) {
|
||||
$previousRule = null;
|
||||
$previousRuleIndex = null;
|
||||
|
||||
foreach ($lines as $lineIndex => $line) {
|
||||
$rule = trim(rtrim($line), '/');
|
||||
|
||||
if (
|
||||
(! str_starts_with($rule, 'public/')) ||
|
||||
(strcmp($rule, $newRule) >= 0) ||
|
||||
(($previousRule !== null) && (strcmp($rule, $previousRule) <= 0))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$previousRule = $rule;
|
||||
$previousRuleIndex = $lineIndex;
|
||||
}
|
||||
|
||||
if ($previousRuleIndex !== null) {
|
||||
array_splice($lines, $previousRuleIndex + 1, 0, ["/{$newRule}"]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
while (($lines !== []) && (end($lines) === '')) {
|
||||
array_pop($lines);
|
||||
}
|
||||
|
||||
if ($lines !== []) {
|
||||
$lines[] = '';
|
||||
}
|
||||
|
||||
$lines[] = "/{$newRule}";
|
||||
}
|
||||
|
||||
if (end($lines) !== '') {
|
||||
$lines[] = '';
|
||||
}
|
||||
|
||||
file_put_contents(
|
||||
$path,
|
||||
implode($lineEnding, $lines),
|
||||
);
|
||||
|
||||
$this->components->info('Added the published Filament assets to [.gitignore].');
|
||||
}
|
||||
|
||||
protected function askToStar(): void
|
||||
{
|
||||
if ($this->option('no-interaction')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! confirm(
|
||||
label: 'All done! Would you like to show some love by starring the Filament repo on GitHub?',
|
||||
default: true,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->openUrlInBrowser('https://github.com/filamentphp/filament');
|
||||
}
|
||||
}
|
||||
42
vendor/filament/support/src/Commands/MakeIssueCommand.php
vendored
Normal file
42
vendor/filament/support/src/Commands/MakeIssueCommand.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Composer\InstalledVersions;
|
||||
use Filament\Support\Commands\Concerns\CanOpenUrlInBrowser;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'make:filament-issue', aliases: [
|
||||
'filament:issue',
|
||||
'filament:make-issue',
|
||||
])]
|
||||
class MakeIssueCommand extends Command
|
||||
{
|
||||
use CanOpenUrlInBrowser;
|
||||
|
||||
protected $description = 'Generates a link to the Filament issue page and pre-fills the version numbers.';
|
||||
|
||||
protected $name = 'make:filament-issue';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:issue',
|
||||
'filament:make-issue',
|
||||
];
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$url = 'https://github.com/filamentphp/filament/issues/new?' . http_build_query([
|
||||
'template' => 'bug_report.yml',
|
||||
'package-version' => InstalledVersions::getPrettyVersion('filament/support'),
|
||||
'laravel-version' => InstalledVersions::getPrettyVersion('laravel/framework'),
|
||||
'livewire-version' => InstalledVersions::getPrettyVersion('livewire/livewire'),
|
||||
'php-version' => PHP_VERSION,
|
||||
]);
|
||||
|
||||
$this->openUrlInBrowser($url);
|
||||
}
|
||||
}
|
||||
43
vendor/filament/support/src/Commands/OptimizeClearCommand.php
vendored
Normal file
43
vendor/filament/support/src/Commands/OptimizeClearCommand.php
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Commands\Concerns\CanCachePanelComponents;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'filament:optimize-clear')]
|
||||
class OptimizeClearCommand extends Command
|
||||
{
|
||||
use CanCachePanelComponents;
|
||||
|
||||
protected $description = 'Remove the cached components and Blade icons';
|
||||
|
||||
protected $name = 'filament:optimize-clear';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->components->info('Clearing cached components and Blade icons.');
|
||||
|
||||
$tasks = collect();
|
||||
|
||||
if ($this->canCachePanelComponents()) {
|
||||
$tasks->put(
|
||||
'Clearing cached components',
|
||||
fn (): bool => $this->callSilent('filament:clear-cached-components') === static::SUCCESS,
|
||||
);
|
||||
}
|
||||
|
||||
$tasks->put(
|
||||
'Clearing cached Blade icons',
|
||||
fn (): bool => $this->callSilent('icons:clear') === static::SUCCESS,
|
||||
);
|
||||
|
||||
$tasks->each(fn (Closure $task, string $description) => $this->components->task($description, $task));
|
||||
|
||||
$this->newLine();
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
40
vendor/filament/support/src/Commands/OptimizeCommand.php
vendored
Normal file
40
vendor/filament/support/src/Commands/OptimizeCommand.php
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\Commands\Concerns\CanCachePanelComponents;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'filament:optimize')]
|
||||
class OptimizeCommand extends Command
|
||||
{
|
||||
use CanCachePanelComponents;
|
||||
|
||||
protected $description = 'Cache components and Blade icons to increase performance';
|
||||
|
||||
protected $name = 'filament:optimize';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$this->components->info('Caching components and Blade icons.');
|
||||
|
||||
$tasks = collect();
|
||||
|
||||
if ($this->canCachePanelComponents()) {
|
||||
$tasks->put(
|
||||
'Caching components',
|
||||
fn (): bool => $this->callSilent('filament:cache-components') === static::SUCCESS
|
||||
);
|
||||
}
|
||||
|
||||
$tasks->put('Caching Blade icons', fn (): bool => $this->callSilent('icons:cache') === static::SUCCESS);
|
||||
|
||||
$tasks->each(fn (Closure $task, string $description) => $this->components->task($description, $task));
|
||||
|
||||
$this->newLine();
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
33
vendor/filament/support/src/Commands/UpgradeCommand.php
vendored
Normal file
33
vendor/filament/support/src/Commands/UpgradeCommand.php
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Commands;
|
||||
|
||||
use Filament\Support\Events\FilamentUpgraded;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand(name: 'filament:upgrade')]
|
||||
class UpgradeCommand extends Command
|
||||
{
|
||||
protected $description = 'Upgrade Filament to the latest version';
|
||||
|
||||
protected $name = 'filament:upgrade';
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
foreach ([
|
||||
AssetsCommand::class,
|
||||
'config:clear',
|
||||
'route:clear',
|
||||
'view:clear',
|
||||
] as $command) {
|
||||
$this->call($command);
|
||||
}
|
||||
|
||||
FilamentUpgraded::dispatch();
|
||||
|
||||
$this->components->info('Successfully upgraded!');
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue