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
106
vendor/filament/support/src/Services/RelationshipJoiner.php
vendored
Normal file
106
vendor/filament/support/src/Services/RelationshipJoiner.php
vendored
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RelationshipJoiner
|
||||
{
|
||||
/**
|
||||
* @return array<JoinClause>
|
||||
*/
|
||||
public function getLeftJoinsForRelationship(Builder $query, string $relationship): array
|
||||
{
|
||||
/** @phpstan-ignore-next-line */
|
||||
$query->leftJoinRelationship($relationship);
|
||||
|
||||
return $query->toBase()->joins;
|
||||
}
|
||||
|
||||
public function prepareQueryForNoConstraints(Relation $relationship): Builder
|
||||
{
|
||||
$relationshipQuery = $relationship->getQuery();
|
||||
|
||||
// By default, `BelongsToMany` relationships use an inner join to scope the results to only
|
||||
// those that are attached in the pivot table. We need to change this to a left join so
|
||||
// that we can still get results when the relationship is not attached to the record.
|
||||
if ($relationship instanceof BelongsToMany) {
|
||||
/** @var ?JoinClause $firstRelationshipJoinClause */
|
||||
$firstRelationshipJoinClause = $relationshipQuery->getQuery()->joins[0] ?? null;
|
||||
|
||||
if ($firstRelationshipJoinClause) {
|
||||
$firstRelationshipJoinClause->type = 'left';
|
||||
|
||||
// Any "where" clauses that are scoped to the pivot table need to be moved to the join.
|
||||
// It's expected that any scopes that don't apply to the pivot table do not have
|
||||
// a `column` attribute set.
|
||||
$relationshipQueryPivotWheres = Arr::where(
|
||||
$relationshipQuery->getQuery()->wheres,
|
||||
function (array $where) use ($relationship): bool {
|
||||
if (! array_key_exists('column', $where)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Str::startsWith($where['column'], "{$relationship->getTable()}.");
|
||||
},
|
||||
);
|
||||
|
||||
$firstRelationshipJoinClause->wheres = array_merge(
|
||||
$firstRelationshipJoinClause->wheres,
|
||||
$relationshipQueryPivotWheres,
|
||||
);
|
||||
|
||||
$relationshipQuery->getQuery()->wheres = Arr::except(
|
||||
$relationshipQuery->getQuery()->wheres,
|
||||
array_keys($relationshipQueryPivotWheres),
|
||||
);
|
||||
}
|
||||
|
||||
$relationshipQuery
|
||||
->distinct()
|
||||
->select($relationshipQuery->getModel()->getTable() . '.*');
|
||||
|
||||
/** @phpstan-ignore-next-line */
|
||||
foreach (($relationshipQuery->getQuery()->orders ?? []) as $order) {
|
||||
// Regular orders: { column: string, direction: 'asc' | 'desc' }
|
||||
// Sub-query orders: { column: Illuminate\Database\Query\Expression, direction: 'asc' | 'desc' }
|
||||
// Raw orders: { type: 'Raw', sql: string }
|
||||
if (! array_key_exists('column', $order) && ! array_key_exists('sql', $order)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (array_key_exists('type', $order) && $order['type'] === 'Raw' && preg_match('/\b(asc|desc)\b/i', $order['sql'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$columnValue = $order['column'] ?? new Expression($order['sql']);
|
||||
|
||||
if (
|
||||
$columnValue instanceof Expression
|
||||
&& str($columnValue->getValue($relationship->getGrammar()))->contains('?')
|
||||
) {
|
||||
// Heuristic to determine if the expression contains (a) binding(s), if so, as of
|
||||
// yet we cannot reliably determine (which) bindings are used in the expression.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
str($columnValue instanceof Expression ? $columnValue->getValue($relationship->getGrammar()) : $columnValue)
|
||||
->startsWith("{$relationshipQuery->getModel()->getTable()}.")
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$relationshipQuery->addSelect($columnValue);
|
||||
}
|
||||
}
|
||||
|
||||
return $relationshipQuery;
|
||||
}
|
||||
}
|
||||
304
vendor/filament/support/src/Services/RelationshipOrderer.php
vendored
Normal file
304
vendor/filament/support/src/Services/RelationshipOrderer.php
vendored
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Support\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphOne;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use InvalidArgumentException;
|
||||
use Znck\Eloquent\Relations\BelongsToThrough;
|
||||
|
||||
class RelationshipOrderer
|
||||
{
|
||||
public function buildSubquery(EloquentBuilder $query, string $relationshipName, string $column): Builder
|
||||
{
|
||||
$relationshipChain = $this->buildRelationshipChain($query->getModel(), $relationshipName);
|
||||
$lastRelationship = end($relationshipChain);
|
||||
$targetModel = $lastRelationship->getRelated();
|
||||
|
||||
$subquery = $lastRelationship->getQuery()->select($targetModel->qualifyColumn($column));
|
||||
$this->applyRelationshipConstraints($subquery, $relationshipChain, $query->getModel());
|
||||
|
||||
return $subquery->limit(1)->toBase();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Relation>
|
||||
*/
|
||||
protected function buildRelationshipChain(Model $baseModel, string $relationshipPath): array
|
||||
{
|
||||
$relationshipSegments = explode('.', $relationshipPath);
|
||||
$currentModel = $baseModel;
|
||||
$chain = [];
|
||||
|
||||
foreach ($relationshipSegments as $relationshipSegment) {
|
||||
$relationship = Relation::noConstraints(fn () => $currentModel->{$relationshipSegment}());
|
||||
|
||||
$this->validateRelationshipType($relationship);
|
||||
|
||||
$chain[] = $relationship;
|
||||
|
||||
$currentModel = $relationship->getRelated();
|
||||
}
|
||||
|
||||
return $chain;
|
||||
}
|
||||
|
||||
protected function validateRelationshipType(Relation $relationship): void
|
||||
{
|
||||
if ($relationship instanceof BelongsTo || $relationship instanceof HasOne || $relationship instanceof MorphOne || $relationship instanceof BelongsToThrough || $relationship instanceof HasOneThrough) {
|
||||
return;
|
||||
}
|
||||
|
||||
throw new InvalidArgumentException(
|
||||
'Nested sorting only supports [BelongsTo], [HasOne], [MorphOne], [BelongsToThrough], and [HasOneThrough] relationships, [' . $relationship::class . '] found.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Relation> $relationshipChain
|
||||
*/
|
||||
protected function applyRelationshipConstraints(
|
||||
EloquentBuilder $subquery,
|
||||
array $relationshipChain,
|
||||
Model $baseModel
|
||||
): void {
|
||||
$chainLength = count($relationshipChain);
|
||||
|
||||
for ($i = $chainLength - 1; $i >= 0; $i--) {
|
||||
$isFirstRelationship = $i === 0;
|
||||
$isSubqueryBase = $i === ($chainLength - 1);
|
||||
|
||||
if ($isFirstRelationship) {
|
||||
$this->applyFirstRelationshipConstraint($subquery, $relationshipChain[$i], $baseModel, $isSubqueryBase); /** @phpstan-ignore argument.type */
|
||||
} else {
|
||||
$this->applyIntermediateRelationshipJoin($subquery, $relationshipChain[$i], $relationshipChain[$i - 1], $isSubqueryBase); /** @phpstan-ignore argument.type, argument.type */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyFirstRelationshipConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsTo | HasOne | MorphOne | BelongsToThrough | HasOneThrough $relationship,
|
||||
Model $baseModel,
|
||||
bool $isSubqueryBase,
|
||||
): void {
|
||||
$baseTable = $baseModel->getTable();
|
||||
|
||||
if ($relationship instanceof BelongsTo) {
|
||||
$this->applyBelongsToConstraint($subquery, $relationship, $baseTable);
|
||||
} elseif ($relationship instanceof MorphOne) {
|
||||
$this->applyMorphOneConstraint($subquery, $relationship, $baseModel);
|
||||
} elseif ($relationship instanceof HasOne) {
|
||||
$this->applyHasOneConstraint($subquery, $relationship, $baseModel);
|
||||
} elseif ($relationship instanceof BelongsToThrough) {
|
||||
$this->applyBelongsToThroughConstraint($subquery, $relationship, $baseModel, $isSubqueryBase);
|
||||
} elseif ($relationship instanceof HasOneThrough) {
|
||||
$this->applyHasOneThroughConstraint($subquery, $relationship, $isSubqueryBase);
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyBelongsToConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsTo $relationship,
|
||||
string $baseTable
|
||||
): void {
|
||||
$subquery->whereColumn(
|
||||
$relationship->getQualifiedOwnerKeyName(),
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyHasOneConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
HasOne $relationship,
|
||||
Model $baseModel
|
||||
): void {
|
||||
$subquery->whereColumn(
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
$baseModel->qualifyColumn($relationship->getLocalKeyName()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyMorphOneConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
MorphOne $relationship,
|
||||
Model $baseModel
|
||||
): void {
|
||||
$subquery->whereColumn(
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
$baseModel->qualifyColumn($relationship->getLocalKeyName()),
|
||||
)->where(
|
||||
$relationship->getQualifiedMorphType(),
|
||||
$relationship->getMorphClass()
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyBelongsToThroughConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsToThrough $relationship,
|
||||
Model $baseModel,
|
||||
bool $isSubqueryBase,
|
||||
): void {
|
||||
if (! $isSubqueryBase) {
|
||||
$this->joinBelongsToThroughParents($subquery, $relationship);
|
||||
}
|
||||
|
||||
$subquery->whereColumn(
|
||||
$relationship->getQualifiedFirstLocalKeyName(),
|
||||
$baseModel->qualifyColumn($relationship->getFirstForeignKeyName()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyHasOneThroughConstraint(
|
||||
EloquentBuilder $subquery,
|
||||
HasOneThrough $relationship,
|
||||
bool $isSubqueryBase,
|
||||
): void {
|
||||
if (! $isSubqueryBase) {
|
||||
$this->joinHasOneThroughParent($subquery, $relationship);
|
||||
}
|
||||
|
||||
$subquery->whereColumn(
|
||||
$relationship->getQualifiedFirstKeyName(),
|
||||
$relationship->getQualifiedLocalKeyName(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinBelongsToThroughParents(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsToThrough $relationship,
|
||||
): void {
|
||||
$throughParents = $relationship->getThroughParents();
|
||||
|
||||
foreach ($throughParents as $i => $throughParent) {
|
||||
$predecessor = ($i === 0)
|
||||
? $relationship->getRelated()
|
||||
: $throughParents[$i - 1];
|
||||
|
||||
$subquery->join(
|
||||
$throughParent->getTable(),
|
||||
$throughParent->qualifyColumn($relationship->getForeignKeyName($predecessor)),
|
||||
'=',
|
||||
$predecessor->qualifyColumn($relationship->getLocalKeyName($predecessor)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function joinHasOneThroughParent(
|
||||
EloquentBuilder $subquery,
|
||||
HasOneThrough $relationship,
|
||||
): void {
|
||||
$subquery->join(
|
||||
invade($relationship)->throughParent->getTable(), /** @phpstan-ignore property.protected */
|
||||
$relationship->getQualifiedParentKeyName(),
|
||||
'=',
|
||||
$relationship->getQualifiedFarKeyName(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function applyIntermediateRelationshipJoin(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsTo | HasOne | MorphOne | BelongsToThrough | HasOneThrough $currentRelationship,
|
||||
BelongsTo | HasOne | MorphOne | BelongsToThrough | HasOneThrough $previousRelationship,
|
||||
bool $isSubqueryBase,
|
||||
): void {
|
||||
$previousTable = $previousRelationship->getRelated()->getTable();
|
||||
|
||||
if ($currentRelationship instanceof BelongsTo) {
|
||||
$this->joinBelongsTo($subquery, $currentRelationship, $previousTable);
|
||||
} elseif ($currentRelationship instanceof MorphOne) {
|
||||
$this->joinMorphOne($subquery, $currentRelationship, $previousTable);
|
||||
} elseif ($currentRelationship instanceof HasOne) {
|
||||
$this->joinHasOne($subquery, $currentRelationship, $previousTable);
|
||||
} elseif ($currentRelationship instanceof BelongsToThrough) {
|
||||
if (! $isSubqueryBase) {
|
||||
$this->joinBelongsToThroughParents($subquery, $currentRelationship);
|
||||
}
|
||||
|
||||
$this->joinBelongsToThrough($subquery, $currentRelationship, $previousTable);
|
||||
} elseif ($currentRelationship instanceof HasOneThrough) {
|
||||
if (! $isSubqueryBase) {
|
||||
$this->joinHasOneThroughParent($subquery, $currentRelationship);
|
||||
}
|
||||
|
||||
$this->joinHasOneThrough($subquery, $currentRelationship, $previousTable);
|
||||
}
|
||||
}
|
||||
|
||||
protected function joinBelongsTo(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsTo $relationship,
|
||||
string $previousTable
|
||||
): void {
|
||||
$subquery->join(
|
||||
$previousTable,
|
||||
$relationship->getQualifiedOwnerKeyName(),
|
||||
'=',
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinHasOne(
|
||||
EloquentBuilder $subquery,
|
||||
HasOne $relationship,
|
||||
string $previousTable
|
||||
): void {
|
||||
$subquery->join(
|
||||
$previousTable,
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
'=',
|
||||
$relationship->getQualifiedParentKeyName(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinMorphOne(
|
||||
EloquentBuilder $subquery,
|
||||
MorphOne $relationship,
|
||||
string $previousTable
|
||||
): void {
|
||||
$subquery->join(
|
||||
$previousTable,
|
||||
$relationship->getQualifiedForeignKeyName(),
|
||||
'=',
|
||||
$relationship->getQualifiedParentKeyName(),
|
||||
)->where(
|
||||
$relationship->getQualifiedMorphType(),
|
||||
$relationship->getMorphClass(),
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinBelongsToThrough(
|
||||
EloquentBuilder $subquery,
|
||||
BelongsToThrough $relationship,
|
||||
string $previousTable
|
||||
): void {
|
||||
$throughParents = $relationship->getThroughParents();
|
||||
$lastThroughParent = end($throughParents);
|
||||
|
||||
$subquery->join(
|
||||
$previousTable,
|
||||
$lastThroughParent->qualifyColumn($relationship->getLocalKeyName($lastThroughParent)),
|
||||
'=',
|
||||
"{$previousTable}.{$relationship->getForeignKeyName($lastThroughParent)}",
|
||||
);
|
||||
}
|
||||
|
||||
protected function joinHasOneThrough(
|
||||
EloquentBuilder $subquery,
|
||||
HasOneThrough $relationship,
|
||||
string $previousTable
|
||||
): void {
|
||||
$subquery->join(
|
||||
$previousTable,
|
||||
$relationship->getQualifiedLocalKeyName(),
|
||||
'=',
|
||||
$relationship->getQualifiedFirstKeyName(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue