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
271
vendor/filament/forms/src/Commands/FileGenerators/Concerns/CanGenerateModelForms.php
vendored
Normal file
271
vendor/filament/forms/src/Commands/FileGenerators/Concerns/CanGenerateModelForms.php
vendored
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands\FileGenerators\Concerns;
|
||||
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\TimePicker;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Nette\PhpGenerator\Literal;
|
||||
|
||||
trait CanGenerateModelForms
|
||||
{
|
||||
/**
|
||||
* @param ?class-string<Model> $model
|
||||
* @param array<string> $exceptColumns
|
||||
*/
|
||||
public function generateFormMethodBody(?string $model = null, ?string $statePath = null, ?string $modelMethodOutput = null, array $exceptColumns = []): string
|
||||
{
|
||||
$statePathOutput = filled($statePath)
|
||||
? PHP_EOL . new Literal(' ->statePath(?)', [$statePath])
|
||||
: '';
|
||||
|
||||
$modelMethodOutput = filled($modelMethodOutput)
|
||||
? PHP_EOL . ' ' . $modelMethodOutput
|
||||
: '';
|
||||
|
||||
return <<<PHP
|
||||
return \$schema
|
||||
->components([
|
||||
{$this->outputFormComponents($model, $exceptColumns)}
|
||||
]){$statePathOutput}{$modelMethodOutput};
|
||||
PHP;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?class-string<Model> $model
|
||||
* @param array<string> $exceptColumns
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getFormComponents(?string $model = null, array $exceptColumns = []): array
|
||||
{
|
||||
if (! $this->isGenerated()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (blank($model)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (! class_exists($model)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$schema = $this->getModelSchema($model);
|
||||
$table = $this->getModelTable($model);
|
||||
|
||||
$components = [];
|
||||
|
||||
foreach ($schema->getColumns($table) as $column) {
|
||||
if ($column['auto_increment']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$componentName = $column['name'];
|
||||
|
||||
if (in_array($componentName, $exceptColumns)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (str($componentName)->is([
|
||||
app($model)->getKeyName(),
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
'updated_at',
|
||||
'*_token',
|
||||
])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = $this->parseColumnType($column);
|
||||
|
||||
if (! $this->canGenerateSchemaComponentForColumnType($type)) {
|
||||
$this->recordSkippedColumn($model, $column);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$componentData = [];
|
||||
|
||||
$componentData['type'] = match (true) {
|
||||
$type['name'] === 'boolean' => Toggle::class,
|
||||
$type['name'] === 'date' => DatePicker::class,
|
||||
$type['name'] === 'time' => TimePicker::class,
|
||||
in_array($type['name'], ['datetime', 'timestamp']) => DateTimePicker::class,
|
||||
$type['name'] === 'text' => Textarea::class,
|
||||
$componentName === 'image', str($componentName)->startsWith('image_'), str($componentName)->contains('_image_'), str($componentName)->endsWith('_image') => FileUpload::class,
|
||||
default => TextInput::class,
|
||||
};
|
||||
|
||||
$enumCasts = $this->getEnumCasts($model);
|
||||
|
||||
if (isset($type['name']) && (($type['name'] === 'enum') || array_key_exists($componentName, $enumCasts))) {
|
||||
$componentData['type'] = Select::class;
|
||||
|
||||
if (array_key_exists($componentName, $enumCasts)) {
|
||||
$enumClass = $enumCasts[$componentName];
|
||||
|
||||
$this->namespace->addUse($enumClass);
|
||||
|
||||
$componentData['options'] = [new Literal(class_basename($enumClass) . '::class')];
|
||||
} else {
|
||||
$componentData['options'] = [array_combine(
|
||||
$type['values'],
|
||||
array_map(
|
||||
fn (string $value): string => (string) str($value)
|
||||
->kebab()
|
||||
->replace(['-', '_'], ' ')
|
||||
->ucfirst(),
|
||||
$type['values'],
|
||||
),
|
||||
)];
|
||||
}
|
||||
|
||||
if ($column['default']) {
|
||||
$componentData['default'] = [$this->parseDefaultExpression($column, $model)];
|
||||
}
|
||||
}
|
||||
|
||||
if (str($componentName)->endsWith('_id')) {
|
||||
$guessedRelationshipName = $this->guessBelongsToRelationshipName($componentName, $model);
|
||||
|
||||
if (filled($guessedRelationshipName)) {
|
||||
$guessedRelationshipTitleColumnName = $this->guessBelongsToRelationshipTitleColumnName($componentName, app($model)->{$guessedRelationshipName}()->getModel()::class);
|
||||
|
||||
$componentData['type'] = Select::class;
|
||||
$componentData['relationship'] = [$guessedRelationshipName, $guessedRelationshipTitleColumnName];
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($componentName, [
|
||||
'id',
|
||||
'sku',
|
||||
'uuid',
|
||||
])) {
|
||||
$componentData['label'] = [Str::upper($componentName)];
|
||||
}
|
||||
|
||||
if ($componentName === 'email') {
|
||||
$componentData['label'] = ['Email address'];
|
||||
}
|
||||
|
||||
if ($componentData['type'] === TextInput::class) {
|
||||
if (str($componentName)->contains(['email'])) {
|
||||
$componentData['email'] = [];
|
||||
}
|
||||
|
||||
if (str($componentName)->contains(['password'])) {
|
||||
$componentData['password'] = [];
|
||||
}
|
||||
|
||||
if (str($componentName)->contains(['phone', 'tel'])) {
|
||||
$componentData['tel'] = [];
|
||||
}
|
||||
|
||||
if (in_array($componentName, ['url', 'website']) || str($componentName)->endsWith(['_url', '_website'])) {
|
||||
$componentData['url'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
if ($componentData['type'] === FileUpload::class) {
|
||||
$componentData['image'] = [];
|
||||
}
|
||||
|
||||
if (! $column['nullable']) {
|
||||
$componentData['required'] = [];
|
||||
}
|
||||
|
||||
if (in_array($type['name'], [
|
||||
'integer',
|
||||
'decimal',
|
||||
'float',
|
||||
'double',
|
||||
'money',
|
||||
])) {
|
||||
if ($componentData['type'] === TextInput::class) {
|
||||
$componentData['numeric'] = [];
|
||||
}
|
||||
|
||||
if (filled($column['default'])) {
|
||||
$componentData['default'] = [$this->parseDefaultExpression($column, $model)];
|
||||
|
||||
if (is_numeric($componentData['default'][0])) {
|
||||
$componentData['default'] = [$componentData['default'][0] + 0];
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($componentName, [
|
||||
'cost',
|
||||
'money',
|
||||
'price',
|
||||
]) || str($componentName)->endsWith([
|
||||
'_cost',
|
||||
'_price',
|
||||
]) || $type['name'] === 'money') {
|
||||
$componentData['prefix'] = ['$'];
|
||||
}
|
||||
} elseif (in_array($componentData['type'], [
|
||||
TextInput::class,
|
||||
Textarea::class,
|
||||
])) {
|
||||
if (isset($column['length'])) { /** @phpstan-ignore isset.offset */
|
||||
$componentData['maxLength'] = [$column['length']];
|
||||
}
|
||||
|
||||
if (filled($column['default'])) {
|
||||
$componentData['default'] = [$this->parseDefaultExpression($column, $model)];
|
||||
}
|
||||
}
|
||||
|
||||
if ($componentData['type'] === Textarea::class) {
|
||||
$componentData['columnSpanFull'] = [];
|
||||
}
|
||||
|
||||
$this->importUnlessPartial($componentData['type']);
|
||||
|
||||
$components[$componentName] = $componentData;
|
||||
}
|
||||
|
||||
return array_map(
|
||||
function (array $componentData, string $componentName): string {
|
||||
$component = (string) new Literal("{$this->simplifyFqn($componentData['type'])}::make(?)", [$componentName]);
|
||||
|
||||
unset($componentData['type']);
|
||||
|
||||
foreach ($componentData as $methodName => $parameters) {
|
||||
$component .= new Literal(PHP_EOL . " ->{$methodName}(...?:)", [$parameters]);
|
||||
}
|
||||
|
||||
return "{$component},";
|
||||
},
|
||||
$components,
|
||||
array_keys($components),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ?class-string<Model> $model
|
||||
* @param array<string> $exceptColumns
|
||||
*/
|
||||
public function outputFormComponents(?string $model = null, array $exceptColumns = []): string
|
||||
{
|
||||
$components = $this->getFormComponents($model, $exceptColumns);
|
||||
|
||||
if (empty($components)) {
|
||||
return '//';
|
||||
}
|
||||
|
||||
return implode(PHP_EOL . ' ', $components);
|
||||
}
|
||||
|
||||
public function isGenerated(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
66
vendor/filament/forms/src/Commands/FileGenerators/FieldClassGenerator.php
vendored
Normal file
66
vendor/filament/forms/src/Commands/FileGenerators/FieldClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands\FileGenerators;
|
||||
|
||||
use Filament\Forms\Components\Field;
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Property;
|
||||
|
||||
class FieldClassGenerator extends ClassGenerator
|
||||
{
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $view,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
return [
|
||||
$this->getExtends(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return Field::class;
|
||||
}
|
||||
|
||||
protected function addPropertiesToClass(ClassType $class): void
|
||||
{
|
||||
$this->addViewPropertyToClass($class);
|
||||
}
|
||||
|
||||
protected function addViewPropertyToClass(ClassType $class): void
|
||||
{
|
||||
$property = $class->addProperty('view', $this->getView())
|
||||
->setProtected()
|
||||
->setType('string');
|
||||
$this->configureViewProperty($property);
|
||||
}
|
||||
|
||||
protected function configureViewProperty(Property $property): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
public function getView(): ?string
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
}
|
||||
95
vendor/filament/forms/src/Commands/FileGenerators/FormSchemaClassGenerator.php
vendored
Normal file
95
vendor/filament/forms/src/Commands/FileGenerators/FormSchemaClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands\FileGenerators;
|
||||
|
||||
use Filament\Forms\Commands\FileGenerators\Concerns\CanGenerateModelForms;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Method;
|
||||
|
||||
class FormSchemaClassGenerator extends ClassGenerator implements HasSkippedColumns
|
||||
{
|
||||
use CanGenerateModelForms;
|
||||
use CanReadModelSchemas;
|
||||
|
||||
/**
|
||||
* @param ?class-string<Model> $modelFqn
|
||||
*/
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected ?string $modelFqn,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
return [
|
||||
Schema::class,
|
||||
...($this->hasPartialImports() ? [
|
||||
'Filament\Forms',
|
||||
'Filament\Schemas',
|
||||
] : []),
|
||||
...(($modelFqn = $this->getModelFqn()) ? [$modelFqn] : []),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addConfigureMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addConfigureMethodToClass(ClassType $class): void
|
||||
{
|
||||
$modelFqn = $this->getModelFqn();
|
||||
|
||||
$method = $class->addMethod('configure')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType(Schema::class)
|
||||
->setBody(
|
||||
filled($modelFqn)
|
||||
? $this->generateFormMethodBody($this->getModelFqn())
|
||||
: <<<'PHP'
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
]);
|
||||
PHP,
|
||||
);
|
||||
$method->addParameter('schema')
|
||||
->setType(Schema::class);
|
||||
|
||||
$this->configureConfigureMethod($method);
|
||||
}
|
||||
|
||||
protected function configureConfigureMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?class-string<Model>
|
||||
*/
|
||||
public function getModelFqn(): ?string
|
||||
{
|
||||
return $this->modelFqn;
|
||||
}
|
||||
}
|
||||
271
vendor/filament/forms/src/Commands/FileGenerators/LivewireFormComponentClassGenerator.php
vendored
Normal file
271
vendor/filament/forms/src/Commands/FileGenerators/LivewireFormComponentClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands\FileGenerators;
|
||||
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Forms\Commands\FileGenerators\Concerns\CanGenerateModelForms;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Commands\Concerns\CanReadModelSchemas;
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Filament\Support\Commands\FileGenerators\Contracts\HasSkippedColumns;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Livewire\Component;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Literal;
|
||||
use Nette\PhpGenerator\Method;
|
||||
use Nette\PhpGenerator\Property;
|
||||
use Nette\PhpGenerator\TraitUse;
|
||||
|
||||
class LivewireFormComponentClassGenerator extends ClassGenerator implements HasSkippedColumns
|
||||
{
|
||||
use CanGenerateModelForms;
|
||||
use CanReadModelSchemas;
|
||||
|
||||
/**
|
||||
* @param ?class-string<Model> $modelFqn
|
||||
*/
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $submitAction,
|
||||
protected ?string $modelFqn,
|
||||
protected ?bool $isGenerated,
|
||||
protected string $view,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
return [
|
||||
$this->getExtends(),
|
||||
...$this->getImplements(),
|
||||
InteractsWithActions::class,
|
||||
InteractsWithSchemas::class,
|
||||
Schema::class,
|
||||
...($this->hasPartialImports() ? [
|
||||
'Filament\Forms',
|
||||
'Filament\Schemas',
|
||||
] : []),
|
||||
...(($modelFqn = $this->getModelFqn()) ? [$modelFqn] : []),
|
||||
View::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return Component::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string>
|
||||
*/
|
||||
public function getImplements(): array
|
||||
{
|
||||
return [
|
||||
HasActions::class,
|
||||
HasSchemas::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function addTraitsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addInteractsWithActionsTraitToClass($class);
|
||||
$this->addInteractsWithSchemasTraitToClass($class);
|
||||
}
|
||||
|
||||
protected function addPropertiesToClass(ClassType $class): void
|
||||
{
|
||||
$this->addRecordPropertyToClass($class);
|
||||
$this->addDataPropertyToClass($class);
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addMountMethodToClass($class);
|
||||
$this->addFormMethodToClass($class);
|
||||
$this->addSubmitMethodToClass($class);
|
||||
$this->addRenderMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addInteractsWithActionsTraitToClass(ClassType $class): void
|
||||
{
|
||||
$trait = $class->addTrait(InteractsWithActions::class);
|
||||
$this->configureInteractsWithActionsTrait($trait);
|
||||
}
|
||||
|
||||
protected function configureInteractsWithActionsTrait(TraitUse $trait): void {}
|
||||
|
||||
protected function addInteractsWithSchemasTraitToClass(ClassType $class): void
|
||||
{
|
||||
$trait = $class->addTrait(InteractsWithSchemas::class);
|
||||
$this->configureInteractsWithSchemasTrait($trait);
|
||||
}
|
||||
|
||||
protected function configureInteractsWithSchemasTrait(TraitUse $trait): void {}
|
||||
|
||||
protected function addRecordPropertyToClass(ClassType $class): void
|
||||
{
|
||||
if ($this->getSubmitAction() !== 'save') {
|
||||
return;
|
||||
}
|
||||
|
||||
$property = $class->addProperty('record')
|
||||
->setPublic()
|
||||
->setType($this->getModelFqn());
|
||||
$this->configureRecordProperty($property);
|
||||
}
|
||||
|
||||
protected function configureRecordProperty(Property $property): void {}
|
||||
|
||||
protected function addDataPropertyToClass(ClassType $class): void
|
||||
{
|
||||
$property = $class->addProperty('data', [])
|
||||
->setPublic()
|
||||
->setType('?array');
|
||||
$this->configureDataProperty($property);
|
||||
}
|
||||
|
||||
protected function configureDataProperty(Property $property): void {}
|
||||
|
||||
protected function addMountMethodToClass(ClassType $class): void
|
||||
{
|
||||
$submitAction = $this->getSubmitAction();
|
||||
|
||||
$method = $class->addMethod('mount')
|
||||
->setPublic()
|
||||
->setReturnType('void')
|
||||
->setBody(match ($submitAction) {
|
||||
'save' => <<<'PHP'
|
||||
$this->form->fill($this->record->attributesToArray());
|
||||
PHP,
|
||||
default => <<<'PHP'
|
||||
$this->form->fill();
|
||||
PHP,
|
||||
});
|
||||
|
||||
$this->configureMountMethod($method);
|
||||
}
|
||||
|
||||
protected function configureMountMethod(Method $method): void {}
|
||||
|
||||
protected function addFormMethodToClass(ClassType $class): void
|
||||
{
|
||||
$submitAction = $this->getSubmitAction();
|
||||
$modelFqn = $this->getModelFqn();
|
||||
|
||||
$method = $class->addMethod('form')
|
||||
->setPublic()
|
||||
->setReturnType(Schema::class)
|
||||
->setBody(
|
||||
filled($modelFqn)
|
||||
? $this->generateFormMethodBody($this->getModelFqn(), statePath: 'data', modelMethodOutput: match ($submitAction) {
|
||||
'create' => "->model({$this->simplifyFqn($modelFqn)}::class)",
|
||||
'save' => '->model($this->record)',
|
||||
default => null,
|
||||
})
|
||||
: <<<'PHP'
|
||||
return $schema
|
||||
->components([
|
||||
//
|
||||
])
|
||||
->statePath('data');
|
||||
PHP,
|
||||
);
|
||||
$method->addParameter('schema')
|
||||
->setType(Schema::class);
|
||||
|
||||
$this->configureFormMethod($method);
|
||||
}
|
||||
|
||||
protected function configureFormMethod(Method $method): void {}
|
||||
|
||||
protected function addSubmitMethodToClass(ClassType $class): void
|
||||
{
|
||||
$submitAction = $this->getSubmitAction();
|
||||
$modelFqn = $this->getModelFqn();
|
||||
|
||||
$method = $class->addMethod($submitAction)
|
||||
->setPublic()
|
||||
->setReturnType('void')
|
||||
->setBody(match ($submitAction) {
|
||||
'create' => <<<PHP
|
||||
\$data = \$this->form->getState();
|
||||
|
||||
\$record = {$this->simplifyFqn($modelFqn)}::create(\$data);
|
||||
|
||||
\$this->form->model(\$record)->saveRelationships();
|
||||
PHP,
|
||||
'save' => <<<'PHP'
|
||||
$data = $this->form->getState();
|
||||
|
||||
$this->record->update($data);
|
||||
PHP,
|
||||
default => <<<'PHP'
|
||||
$data = $this->form->getState();
|
||||
|
||||
//
|
||||
PHP,
|
||||
});
|
||||
|
||||
$this->configureSubmitMethod($method);
|
||||
}
|
||||
|
||||
protected function configureSubmitMethod(Method $method): void {}
|
||||
|
||||
protected function addRenderMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('render')
|
||||
->setPublic()
|
||||
->setReturnType(View::class)
|
||||
->setBody(new Literal(<<<'PHP'
|
||||
return view(?);
|
||||
PHP, [$this->getView()]));
|
||||
|
||||
$this->configureRenderMethod($method);
|
||||
}
|
||||
|
||||
protected function configureRenderMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
public function getSubmitAction(): string
|
||||
{
|
||||
return $this->submitAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ?class-string<Model>
|
||||
*/
|
||||
public function getModelFqn(): ?string
|
||||
{
|
||||
return $this->modelFqn;
|
||||
}
|
||||
|
||||
public function isGenerated(): ?bool
|
||||
{
|
||||
return $this->isGenerated;
|
||||
}
|
||||
|
||||
public function getView(): string
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
}
|
||||
180
vendor/filament/forms/src/Commands/FileGenerators/RichContentCustomBlockClassGenerator.php
vendored
Normal file
180
vendor/filament/forms/src/Commands/FileGenerators/RichContentCustomBlockClassGenerator.php
vendored
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands\FileGenerators;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\RichEditor\RichContentCustomBlock;
|
||||
use Filament\Support\Commands\FileGenerators\ClassGenerator;
|
||||
use Illuminate\Support\Stringable;
|
||||
use Nette\PhpGenerator\ClassType;
|
||||
use Nette\PhpGenerator\Method;
|
||||
|
||||
class RichContentCustomBlockClassGenerator extends ClassGenerator
|
||||
{
|
||||
final public function __construct(
|
||||
protected string $fqn,
|
||||
protected string $view,
|
||||
protected string $previewView,
|
||||
) {}
|
||||
|
||||
public function getNamespace(): string
|
||||
{
|
||||
return $this->extractNamespace($this->getFqn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getImports(): array
|
||||
{
|
||||
return [
|
||||
Action::class,
|
||||
$this->getExtends(),
|
||||
];
|
||||
}
|
||||
|
||||
public function getBasename(): string
|
||||
{
|
||||
return class_basename($this->getFqn());
|
||||
}
|
||||
|
||||
public function getExtends(): string
|
||||
{
|
||||
return RichContentCustomBlock::class;
|
||||
}
|
||||
|
||||
protected function addMethodsToClass(ClassType $class): void
|
||||
{
|
||||
$this->addGetIdMethodToClass($class);
|
||||
$this->addGetLabelMethodToClass($class);
|
||||
$this->addConfigureEditorActionMethodToClass($class);
|
||||
$this->addToPreviewHtmlMethodToClass($class);
|
||||
$this->addToHtmlMethodToClass($class);
|
||||
}
|
||||
|
||||
protected function addGetIdMethodToClass(ClassType $class): void
|
||||
{
|
||||
$id = (string) str($this->getBasename())
|
||||
->whenEndsWith('Block', fn (Stringable $stringable) => $stringable->beforeLast('Block'))
|
||||
->snake()
|
||||
->lower();
|
||||
|
||||
$method = $class->addMethod('getId')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType('string')
|
||||
->setBody(
|
||||
<<<PHP
|
||||
return '{$id}';
|
||||
PHP,
|
||||
);
|
||||
|
||||
$this->configureGetIdMethod($method);
|
||||
}
|
||||
|
||||
protected function configureGetIdMethod(Method $method): void {}
|
||||
|
||||
protected function addGetLabelMethodToClass(ClassType $class): void
|
||||
{
|
||||
$label = (string) str($this->getBasename())
|
||||
->whenEndsWith('Block', fn (Stringable $stringable) => $stringable->beforeLast('Block'))
|
||||
->kebab()
|
||||
->replace('-', ' ')
|
||||
->ucfirst();
|
||||
|
||||
$method = $class->addMethod('getLabel')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType('string')
|
||||
->setBody(
|
||||
<<<PHP
|
||||
return '{$label}';
|
||||
PHP,
|
||||
);
|
||||
|
||||
$this->configureGetLabelMethod($method);
|
||||
}
|
||||
|
||||
protected function configureGetLabelMethod(Method $method): void {}
|
||||
|
||||
protected function addConfigureEditorActionMethodToClass(ClassType $class): void
|
||||
{
|
||||
$label = (string) str($this->getBasename())
|
||||
->kebab()
|
||||
->replace('-', ' ');
|
||||
|
||||
$method = $class->addMethod('configureEditorAction')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType(Action::class)
|
||||
->setBody(
|
||||
<<<PHP
|
||||
return \$action
|
||||
->modalDescription('Configure the {$label}')
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
PHP,
|
||||
);
|
||||
$method->addParameter('action')
|
||||
->setType(Action::class);
|
||||
|
||||
$this->configureConfigureEditorActionMethod($method);
|
||||
}
|
||||
|
||||
protected function configureConfigureEditorActionMethod(Method $method): void {}
|
||||
|
||||
protected function addToPreviewHtmlMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('toPreviewHtml')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType('string')
|
||||
->setBody(
|
||||
<<<PHP
|
||||
return view('{$this->previewView}', [
|
||||
//
|
||||
])->render();
|
||||
PHP,
|
||||
);
|
||||
$method->addParameter('config')
|
||||
->setType('array');
|
||||
|
||||
$this->configureToPreviewMethod($method);
|
||||
}
|
||||
|
||||
protected function configureToPreviewMethod(Method $method): void {}
|
||||
|
||||
protected function addToHtmlMethodToClass(ClassType $class): void
|
||||
{
|
||||
$method = $class->addMethod('toHtml')
|
||||
->setPublic()
|
||||
->setStatic()
|
||||
->setReturnType('string')
|
||||
->setBody(
|
||||
<<<PHP
|
||||
return view('{$this->view}', [
|
||||
//
|
||||
])->render();
|
||||
PHP,
|
||||
);
|
||||
$method->addParameter('config')
|
||||
->setType('array');
|
||||
$method->addParameter('data')
|
||||
->setType('array');
|
||||
|
||||
$this->configureToHtmlMethod($method);
|
||||
}
|
||||
|
||||
protected function configureToHtmlMethod(Method $method): void {}
|
||||
|
||||
public function getFqn(): string
|
||||
{
|
||||
return $this->fqn;
|
||||
}
|
||||
|
||||
public function getView(): ?string
|
||||
{
|
||||
return $this->view;
|
||||
}
|
||||
}
|
||||
174
vendor/filament/forms/src/Commands/MakeFieldCommand.php
vendored
Normal file
174
vendor/filament/forms/src/Commands/MakeFieldCommand.php
vendored
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands;
|
||||
|
||||
use Filament\Forms\Commands\FileGenerators\FieldClassGenerator;
|
||||
use Filament\Support\Commands\Concerns\CanAskForComponentLocation;
|
||||
use Filament\Support\Commands\Concerns\CanAskForViewLocation;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'make:filament-form-field', aliases: [
|
||||
'filament:field',
|
||||
'filament:form-field',
|
||||
'forms:field',
|
||||
'forms:make-field',
|
||||
'make:filament-field',
|
||||
'make:form-field',
|
||||
])]
|
||||
class MakeFieldCommand extends Command
|
||||
{
|
||||
use CanAskForComponentLocation;
|
||||
use CanAskForViewLocation;
|
||||
use CanManipulateFiles;
|
||||
|
||||
protected $description = 'Create a new form field class and view';
|
||||
|
||||
protected $name = 'make:filament-form-field';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:field',
|
||||
'filament:form-field',
|
||||
'forms:field',
|
||||
'forms:make-field',
|
||||
'make:filament-field',
|
||||
'make:form-field',
|
||||
];
|
||||
|
||||
protected string $fqnEnd;
|
||||
|
||||
protected string $fqn;
|
||||
|
||||
protected string $path;
|
||||
|
||||
protected string $view;
|
||||
|
||||
protected string $viewPath;
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'name',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the field to generate, optionally prefixed with directories',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->configureFqnEnd();
|
||||
|
||||
$this->configureLocation();
|
||||
|
||||
$this->createField();
|
||||
$this->createView();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->components->info("Filament form field [{$this->fqn}] created successfully.");
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function configureFqnEnd(): void
|
||||
{
|
||||
$this->fqnEnd = (string) str($this->argument('name') ?? text(
|
||||
label: 'What is the field name?',
|
||||
placeholder: 'RangeSlider',
|
||||
required: true,
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
protected function configureLocation(): void
|
||||
{
|
||||
[
|
||||
$namespace,
|
||||
$path,
|
||||
$viewNamespace,
|
||||
] = $this->askForComponentLocation(
|
||||
path: 'Forms/Components',
|
||||
question: 'Where would you like to create the field?',
|
||||
);
|
||||
|
||||
$this->fqn = "{$namespace}\\{$this->fqnEnd}";
|
||||
$this->path = (string) str("{$path}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
[
|
||||
$this->view,
|
||||
$this->viewPath,
|
||||
] = $this->askForViewLocation(
|
||||
str($this->fqn)
|
||||
->afterLast('\\Forms\\Components\\')
|
||||
->prepend('Filament\\Forms\\Components\\')
|
||||
->replace('\\', '/')
|
||||
->explode('/')
|
||||
->map(Str::kebab(...))
|
||||
->implode('.'),
|
||||
defaultNamespace: $viewNamespace,
|
||||
);
|
||||
}
|
||||
|
||||
protected function createField(): void
|
||||
{
|
||||
if (! $this->option('force') && $this->checkForCollision($this->path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($this->path, app(FieldClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'view' => $this->view,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createView(): void
|
||||
{
|
||||
if (blank($this->view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($this->viewPath)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->copyStubToApp('FieldView', $this->viewPath);
|
||||
}
|
||||
}
|
||||
201
vendor/filament/forms/src/Commands/MakeFormCommand.php
vendored
Normal file
201
vendor/filament/forms/src/Commands/MakeFormCommand.php
vendored
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands;
|
||||
|
||||
use Filament\Forms\Commands\FileGenerators\FormSchemaClassGenerator;
|
||||
use Filament\Support\Commands\Concerns\CanAskForComponentLocation;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Filament\Support\discover_app_classes;
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\suggest;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'make:filament-form', aliases: [
|
||||
'filament:form',
|
||||
])]
|
||||
class MakeFormCommand extends Command
|
||||
{
|
||||
use CanAskForComponentLocation;
|
||||
use CanManipulateFiles;
|
||||
|
||||
protected $description = 'Create a new Filament form schema class';
|
||||
|
||||
protected $name = 'make:filament-form';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:form',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var class-string
|
||||
*/
|
||||
protected string $fqn;
|
||||
|
||||
protected string $fqnEnd;
|
||||
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* @var ?class-string<Model>
|
||||
*/
|
||||
protected ?string $modelFqn = null;
|
||||
|
||||
protected ?string $modelFqnEnd = null;
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'name',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the form schema class to generate, optionally prefixed with directories',
|
||||
),
|
||||
new InputArgument(
|
||||
name: 'model',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the model to generate the form for, optionally prefixed with directories',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'model-namespace',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_REQUIRED,
|
||||
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->configureFqnEnd();
|
||||
$this->configureModel();
|
||||
|
||||
$this->configureLocation();
|
||||
|
||||
$this->createSchema();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->components->info("Form schema [{$this->fqn}] created successfully.");
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function configureFqnEnd(): void
|
||||
{
|
||||
$this->fqnEnd = (string) str($this->argument('name') ?? text(
|
||||
label: 'What is the form schema name?',
|
||||
placeholder: 'BlogPostForm',
|
||||
required: true,
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
protected function configureModel(): void
|
||||
{
|
||||
if ($this->argument('model')) {
|
||||
$this->modelFqnEnd = (string) str($this->argument('model'))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
|
||||
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
|
||||
|
||||
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! confirm(
|
||||
label: 'Would you like to create a form for a model?',
|
||||
default: false,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$modelFqns = discover_app_classes(parentClass: Model::class);
|
||||
|
||||
$this->modelFqn = suggest(
|
||||
label: 'What is the model?',
|
||||
options: function (string $search) use ($modelFqns): array {
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
if (blank($search)) {
|
||||
return $modelFqns;
|
||||
}
|
||||
|
||||
return array_filter(
|
||||
$modelFqns,
|
||||
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
|
||||
);
|
||||
},
|
||||
placeholder: app()->getNamespace() . 'Models\\BlogPost',
|
||||
required: true,
|
||||
);
|
||||
|
||||
$this->modelFqnEnd = class_basename($this->modelFqn);
|
||||
}
|
||||
|
||||
protected function configureLocation(): void
|
||||
{
|
||||
[
|
||||
$namespace,
|
||||
$path,
|
||||
] = $this->askForComponentLocation(
|
||||
path: 'Schemas',
|
||||
question: 'Where would you like to create the form schema?',
|
||||
);
|
||||
|
||||
$this->fqn = "{$namespace}\\{$this->fqnEnd}";
|
||||
$this->path = (string) str("{$path}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
}
|
||||
|
||||
protected function createSchema(): void
|
||||
{
|
||||
if (! $this->option('force') && $this->checkForCollision($this->path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($this->path, app(FormSchemaClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'modelFqn' => $this->modelFqn,
|
||||
]));
|
||||
}
|
||||
}
|
||||
300
vendor/filament/forms/src/Commands/MakeLivewireFormCommand.php
vendored
Normal file
300
vendor/filament/forms/src/Commands/MakeLivewireFormCommand.php
vendored
Normal file
|
|
@ -0,0 +1,300 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands;
|
||||
|
||||
use Filament\Forms\Commands\FileGenerators\LivewireFormComponentClassGenerator;
|
||||
use Filament\Support\Commands\Concerns\CanAskForLivewireComponentLocation;
|
||||
use Filament\Support\Commands\Concerns\CanAskForViewLocation;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Str;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Filament\Support\discover_app_classes;
|
||||
use function Laravel\Prompts\confirm;
|
||||
use function Laravel\Prompts\select;
|
||||
use function Laravel\Prompts\suggest;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'make:filament-livewire-form', aliases: [
|
||||
'filament:livewire-form',
|
||||
'make:livewire-form',
|
||||
])]
|
||||
class MakeLivewireFormCommand extends Command
|
||||
{
|
||||
use CanAskForLivewireComponentLocation;
|
||||
use CanAskForViewLocation;
|
||||
use CanManipulateFiles;
|
||||
|
||||
protected $description = 'Create a new Livewire component containing a Filament form';
|
||||
|
||||
protected $name = 'make:filament-livewire-form';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:livewire-form',
|
||||
'make:livewire-form',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var class-string
|
||||
*/
|
||||
protected string $fqn;
|
||||
|
||||
protected string $fqnEnd;
|
||||
|
||||
protected string $path;
|
||||
|
||||
/**
|
||||
* @var ?class-string<Model>
|
||||
*/
|
||||
protected ?string $modelFqn = null;
|
||||
|
||||
protected ?string $modelFqnEnd = null;
|
||||
|
||||
protected ?bool $isEdit = null;
|
||||
|
||||
protected ?bool $isGenerated = null;
|
||||
|
||||
protected string $submitAction;
|
||||
|
||||
protected ?string $view = null;
|
||||
|
||||
protected ?string $viewPath = null;
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'name',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the Livewire component to generate, optionally prefixed with directories',
|
||||
),
|
||||
new InputArgument(
|
||||
name: 'model',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the model to generate the form for, optionally prefixed with directories',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'edit',
|
||||
shortcut: 'E',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Generate the form to edit the model instead of creating it',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'generate',
|
||||
shortcut: 'G',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Generate the form fields based on the attributes of a model',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'model-namespace',
|
||||
shortcut: null,
|
||||
mode: InputOption::VALUE_REQUIRED,
|
||||
description: 'The namespace of the model class, [' . app()->getNamespace() . 'Models] by default',
|
||||
),
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->configureFqnEnd();
|
||||
$this->configureModel();
|
||||
$this->configureIsEdit();
|
||||
$this->configureIsGenerated();
|
||||
|
||||
$this->configureLocation();
|
||||
$this->configureSubmitAction();
|
||||
|
||||
$this->createLivewireComponent();
|
||||
$this->createView();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->components->info("Livewire component [{$this->fqn}] created successfully.");
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function configureFqnEnd(): void
|
||||
{
|
||||
$this->fqnEnd = (string) str($this->argument('name') ?? text(
|
||||
label: 'What is the Livewire component name?',
|
||||
placeholder: 'CreateBlogPost',
|
||||
required: true,
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
protected function configureModel(): void
|
||||
{
|
||||
if ($this->argument('model')) {
|
||||
$this->modelFqnEnd = (string) str($this->argument('model'))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
|
||||
$modelNamespace = $this->option('model-namespace') ?? app()->getNamespace() . 'Models';
|
||||
|
||||
$this->modelFqn = "{$modelNamespace}\\{$this->modelFqnEnd}";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (! confirm(
|
||||
label: 'Would you like to create a form for a model?',
|
||||
default: false,
|
||||
)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$modelFqns = discover_app_classes(parentClass: Model::class);
|
||||
|
||||
$this->modelFqn = suggest(
|
||||
label: 'What is the model?',
|
||||
options: function (string $search) use ($modelFqns): array {
|
||||
$search = str($search)->trim()->replace(['\\', '/'], '');
|
||||
|
||||
if (blank($search)) {
|
||||
return $modelFqns;
|
||||
}
|
||||
|
||||
return array_filter(
|
||||
$modelFqns,
|
||||
fn (string $class): bool => str($class)->replace(['\\', '/'], '')->contains($search, ignoreCase: true),
|
||||
);
|
||||
},
|
||||
placeholder: app()->getNamespace() . 'Models\\BlogPost',
|
||||
required: true,
|
||||
);
|
||||
|
||||
$this->modelFqnEnd = class_basename($this->modelFqn);
|
||||
}
|
||||
|
||||
protected function configureIsEdit(): void
|
||||
{
|
||||
if (blank($this->modelFqn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->isEdit = $this->option('edit') || (select(
|
||||
label: 'What would you like the form to do?',
|
||||
options: [
|
||||
'create' => 'Create a new model record',
|
||||
'edit' => 'Edit an existing model record',
|
||||
],
|
||||
default: 'create',
|
||||
) === 'edit');
|
||||
}
|
||||
|
||||
protected function configureIsGenerated(): void
|
||||
{
|
||||
if (blank($this->modelFqn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->isGenerated = $this->option('generate') || confirm(
|
||||
label: 'Should the form fields be generated from the current database columns?',
|
||||
default: false,
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureLocation(): void
|
||||
{
|
||||
[
|
||||
$namespace,
|
||||
$path,
|
||||
$viewNamespace,
|
||||
] = $this->askForLivewireComponentLocation(
|
||||
question: 'Where would you like to create the form?',
|
||||
);
|
||||
|
||||
$this->fqn = "{$namespace}\\{$this->fqnEnd}";
|
||||
$this->path = (string) str("{$path}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
[
|
||||
$this->view,
|
||||
$this->viewPath,
|
||||
] = $this->askForViewLocation(
|
||||
str($this->fqn)
|
||||
->afterLast('\\Livewire\\')
|
||||
->prepend('Livewire\\')
|
||||
->replace('\\', '/')
|
||||
->explode('/')
|
||||
->map(Str::kebab(...))
|
||||
->implode('.'),
|
||||
defaultNamespace: $viewNamespace,
|
||||
);
|
||||
}
|
||||
|
||||
protected function configureSubmitAction(): void
|
||||
{
|
||||
$this->submitAction = filled($this->modelFqn)
|
||||
? ($this->isEdit ? 'save' : 'create')
|
||||
: 'submit';
|
||||
}
|
||||
|
||||
protected function createLivewireComponent(): void
|
||||
{
|
||||
if (! $this->option('force') && $this->checkForCollision($this->path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($this->path, app(LivewireFormComponentClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'submitAction' => $this->submitAction,
|
||||
'modelFqn' => $this->modelFqn,
|
||||
'isGenerated' => $this->isGenerated,
|
||||
'view' => $this->view,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createView(): void
|
||||
{
|
||||
if (blank($this->view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($this->viewPath)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->copyStubToApp('LivewireFormView', $this->viewPath, [
|
||||
'submitAction' => $this->submitAction,
|
||||
]);
|
||||
}
|
||||
}
|
||||
209
vendor/filament/forms/src/Commands/MakeRichContentCustomBlockCommand.php
vendored
Normal file
209
vendor/filament/forms/src/Commands/MakeRichContentCustomBlockCommand.php
vendored
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Forms\Commands;
|
||||
|
||||
use Filament\Forms\Commands\FileGenerators\RichContentCustomBlockClassGenerator;
|
||||
use Filament\Support\Commands\Concerns\CanAskForComponentLocation;
|
||||
use Filament\Support\Commands\Concerns\CanAskForViewLocation;
|
||||
use Filament\Support\Commands\Concerns\CanManipulateFiles;
|
||||
use Filament\Support\Commands\Exceptions\FailureCommandOutput;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Stringable;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'make:filament-rich-content-custom-block', aliases: [
|
||||
'filament:rich-content-custom-block',
|
||||
'filament:rich-editor-custom-block',
|
||||
'filament:custom-block',
|
||||
'forms:rich-content-custom-block',
|
||||
'forms:rich-editor-custom-block',
|
||||
'forms:make-custom-block',
|
||||
'make:filament-rich-editor-custom-block',
|
||||
'make:filament-custom-block',
|
||||
'make:rich-content-custom-block',
|
||||
'make:rich-editor-custom-block',
|
||||
'make:custom-block',
|
||||
])]
|
||||
class MakeRichContentCustomBlockCommand extends Command
|
||||
{
|
||||
use CanAskForComponentLocation;
|
||||
use CanAskForViewLocation;
|
||||
use CanManipulateFiles;
|
||||
|
||||
protected $description = 'Create a new rich editor custom block class and view';
|
||||
|
||||
protected $name = 'make:filament-rich-content-custom-block';
|
||||
|
||||
/**
|
||||
* @var array<string>
|
||||
*/
|
||||
protected $aliases = [
|
||||
'filament:rich-content-custom-block',
|
||||
'filament:rich-editor-custom-block',
|
||||
'filament:custom-block',
|
||||
'forms:rich-content-custom-block',
|
||||
'forms:rich-editor-custom-block',
|
||||
'forms:make-custom-block',
|
||||
'make:filament-rich-editor-custom-block',
|
||||
'make:filament-custom-block',
|
||||
'make:rich-content-custom-block',
|
||||
'make:rich-editor-custom-block',
|
||||
'make:custom-block',
|
||||
];
|
||||
|
||||
protected string $fqnEnd;
|
||||
|
||||
protected string $fqn;
|
||||
|
||||
protected string $path;
|
||||
|
||||
protected string $view;
|
||||
|
||||
protected string $previewView;
|
||||
|
||||
protected string $viewPath;
|
||||
|
||||
protected string $previewViewPath;
|
||||
|
||||
/**
|
||||
* @return array<InputArgument>
|
||||
*/
|
||||
protected function getArguments(): array
|
||||
{
|
||||
return [
|
||||
new InputArgument(
|
||||
name: 'name',
|
||||
mode: InputArgument::OPTIONAL,
|
||||
description: 'The name of the custom block to generate, optionally prefixed with directories',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<InputOption>
|
||||
*/
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
new InputOption(
|
||||
name: 'force',
|
||||
shortcut: 'F',
|
||||
mode: InputOption::VALUE_NONE,
|
||||
description: 'Overwrite the contents of the files if they already exist',
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$this->configureFqnEnd();
|
||||
|
||||
$this->configureLocation();
|
||||
|
||||
$this->createCustomBlock();
|
||||
$this->createView();
|
||||
$this->createPreviewView();
|
||||
} catch (FailureCommandOutput) {
|
||||
return static::FAILURE;
|
||||
}
|
||||
|
||||
$this->components->info("Filament rich editor custom block [{$this->fqn}] created successfully.");
|
||||
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
protected function configureFqnEnd(): void
|
||||
{
|
||||
$this->fqnEnd = (string) str($this->argument('name') ?? text(
|
||||
label: 'What is the custom block name?',
|
||||
placeholder: 'HeroBlock',
|
||||
required: true,
|
||||
))
|
||||
->trim('/')
|
||||
->trim('\\')
|
||||
->trim(' ')
|
||||
->studly()
|
||||
->replace('/', '\\');
|
||||
}
|
||||
|
||||
protected function configureLocation(): void
|
||||
{
|
||||
[
|
||||
$namespace,
|
||||
$path,
|
||||
$viewNamespace,
|
||||
] = $this->askForComponentLocation(
|
||||
path: 'Forms/Components/RichEditor/RichContentCustomBlocks',
|
||||
question: 'Where would you like to create the custom block?',
|
||||
);
|
||||
|
||||
$this->fqn = "{$namespace}\\{$this->fqnEnd}";
|
||||
$this->path = (string) str("{$path}\\{$this->fqnEnd}.php")
|
||||
->replace('\\', '/')
|
||||
->replace('//', '/');
|
||||
|
||||
[
|
||||
$view,
|
||||
$viewPath,
|
||||
] = $this->askForViewLocation(
|
||||
str($this->fqn)
|
||||
->afterLast('\\Forms\\Components\\RichEditor\\RichContentCustomBlocks\\')
|
||||
->prepend('Filament\\Forms\\Components\\RichEditor\\RichContentCustomBlocks\\')
|
||||
->whenEndsWith('Block', fn (Stringable $stringable) => $stringable->beforeLast('Block'))
|
||||
->replace('\\', '/')
|
||||
->explode('/')
|
||||
->map(Str::kebab(...))
|
||||
->implode('.'),
|
||||
defaultNamespace: $viewNamespace,
|
||||
);
|
||||
$this->view = str($view)->append('.index');
|
||||
$this->viewPath = str($viewPath)->replaceLast('.blade.php', '/index.blade.php');
|
||||
$this->previewView = str($view)->append('.preview');
|
||||
$this->previewViewPath = str($viewPath)->replaceLast('.blade.php', '/preview.blade.php');
|
||||
}
|
||||
|
||||
protected function createCustomBlock(): void
|
||||
{
|
||||
if (! $this->option('force') && $this->checkForCollision($this->path)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->writeFile($this->path, app(RichContentCustomBlockClassGenerator::class, [
|
||||
'fqn' => $this->fqn,
|
||||
'view' => $this->view,
|
||||
'previewView' => $this->previewView,
|
||||
]));
|
||||
}
|
||||
|
||||
protected function createView(): void
|
||||
{
|
||||
if (blank($this->view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($this->viewPath)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->copyStubToApp('RichContentCustomBlockView', $this->viewPath);
|
||||
}
|
||||
|
||||
protected function createPreviewView(): void
|
||||
{
|
||||
if (blank($this->previewViewPath)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $this->option('force') && $this->checkForCollision($this->previewViewPath)) {
|
||||
throw new FailureCommandOutput;
|
||||
}
|
||||
|
||||
$this->copyStubToApp('RichContentCustomBlockPreviewView', $this->previewViewPath);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue