Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8.4 Support #858

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
database: ["mysql:8"]
services:
database:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
database: ["mariadb:10.6", "mariadb:10.11", "mariadb:11.4"]
services:
database:
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.2, 8.3]
php: [8.2, 8.3, 8.4]
env:
APP_ENV: testing
APP_DEBUG: "false"
Expand Down
16 changes: 16 additions & 0 deletions app/Contracts/Validatable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Contracts;

use Illuminate\Validation\Validator;

interface Validatable
{
public function getValidator(): Validator;

public static function getRules(): array;

public static function getRulesForField(string $field): array;

public function validate(): void;
}
4 changes: 0 additions & 4 deletions app/Http/Requests/Api/Application/ApplicationApiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Webmozart\Assert\Assert;
use App\Models\ApiKey;
use Laravel\Sanctum\TransientToken;
use Illuminate\Validation\Validator;
use Illuminate\Database\Eloquent\Model;
use App\Services\Acl\Api\AdminAcl;
Expand Down Expand Up @@ -38,9 +37,6 @@ public function authorize(): bool
}

$token = $this->user()->currentAccessToken();
if ($token instanceof TransientToken) {
return true;
}

/** @var ApiKey $token */
if ($token->key_type === ApiKey::TYPE_ACCOUNT) {
Expand Down
8 changes: 5 additions & 3 deletions app/Models/ActivityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Traits\HasValidation;
use Carbon\Carbon;
use Illuminate\Support\Facades\Event;
use App\Events\ActivityLogged;
Expand All @@ -10,7 +11,7 @@
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Model as IlluminateModel;
use Illuminate\Database\Eloquent\Model;

/**
* \App\Models\ActivityLog.
Expand All @@ -25,7 +26,7 @@
* @property int|null $api_key_id
* @property \Illuminate\Support\Collection|null $properties
* @property \Carbon\Carbon $timestamp
* @property IlluminateModel|\Eloquent $actor
* @property Model|\Eloquent $actor
* @property \Illuminate\Database\Eloquent\Collection|\App\Models\ActivityLogSubject[] $subjects
* @property int|null $subjects_count
* @property \App\Models\ApiKey|null $apiKey
Expand All @@ -48,6 +49,7 @@
*/
class ActivityLog extends Model
{
use HasValidation;
use MassPrunable;

public const RESOURCE_NAME = 'activity_log';
Expand Down Expand Up @@ -111,7 +113,7 @@ public function scopeForEvent(Builder $builder, string $action): Builder
/**
* Scopes a query to only return results where the actor is a given model.
*/
public function scopeForActor(Builder $builder, IlluminateModel $actor): Builder
public function scopeForActor(Builder $builder, Model $actor): Builder
{
return $builder->whereMorphedTo('actor', $actor);
}
Expand Down
16 changes: 6 additions & 10 deletions app/Models/Allocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Models;

use App\Exceptions\Service\Allocation\ServerUsingAllocationException;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
Expand Down Expand Up @@ -40,17 +43,15 @@
*/
class Allocation extends Model
{
use HasFactory;
use HasValidation;

/**
* The resource name for this model when it is transformed into an
* API representation using fractal. Also used as name for api key permissions.
*/
public const RESOURCE_NAME = 'allocation';

/**
* The table associated with the model.
*/
protected $table = 'allocations';

/**
* Fields that are not mass assignable.
*/
Expand Down Expand Up @@ -81,11 +82,6 @@ protected function casts(): array
];
}

public function getRouteKeyName(): string
{
return $this->getKeyName();
}

/**
* Accessor to automatically provide the IP alias if defined.
*/
Expand Down
31 changes: 13 additions & 18 deletions app/Models/ApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Models;

use App\Services\Acl\Api\AdminAcl;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Str;
use Laravel\Sanctum\PersonalAccessToken;
use Webmozart\Assert\Assert;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Expand Down Expand Up @@ -47,8 +50,11 @@
* @method static \Illuminate\Database\Eloquent\Builder|ApiKey whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|ApiKey whereUserId($value)
*/
class ApiKey extends Model
class ApiKey extends PersonalAccessToken
{
use HasFactory;
use HasValidation;

/**
* The resource name for this model when it is transformed into an
* API representation using fractal.
Expand All @@ -75,11 +81,6 @@ class ApiKey extends Model
*/
public const KEY_LENGTH = 32;

/**
* The table associated with the model.
*/
protected $table = 'api_keys';

/**
* Fields that are mass assignable.
*/
Expand Down Expand Up @@ -148,13 +149,9 @@ public function user(): BelongsTo
return $this->belongsTo(User::class);
}

/**
* Required for support with Laravel Sanctum.
*
* @see \Laravel\Sanctum\Guard::supportsTokens()
*/
public function tokenable(): BelongsTo
public function tokenable()
{
// @phpstan-ignore-next-line
return $this->user();
}

Expand All @@ -180,11 +177,6 @@ public function getPermission(string $resource): int

private static array $customResourceNames = [];

public static function registerCustomResourceName(string $resourceName): void
{
$customResourceNames[] = $resourceName;
}

/**
* Returns a list of all possible permission keys.
*/
Expand All @@ -195,11 +187,14 @@ public static function getPermissionList(): array

/**
* Finds the model matching the provided token.
*
* @param string $token
*/
public static function findToken(string $token): ?self
public static function findToken($token): ?self
{
$identifier = substr($token, 0, self::IDENTIFIER_LENGTH);

/** @var static|null $model */
$model = static::where('identifier', $identifier)->first();
if (!is_null($model) && $model->token === substr($token, strlen($identifier))) {
return $model;
Expand Down
11 changes: 8 additions & 3 deletions app/Models/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Models;

use App\Contracts\Validatable;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Ramsey\Uuid\Uuid;
use Illuminate\Http\Request;
use Illuminate\Container\Container;
Expand All @@ -10,8 +14,11 @@
/**
* @deprecated — this class will be dropped in a future version, use the activity log
*/
class AuditLog extends Model
class AuditLog extends Model implements Validatable
{
use HasFactory;
use HasValidation;

public const UPDATED_AT = null;

public static array $validationRules = [
Expand All @@ -24,8 +31,6 @@ class AuditLog extends Model
'metadata' => 'array',
];

protected $table = 'audit_logs';

protected $guarded = [
'id',
'created_at',
Expand Down
10 changes: 7 additions & 3 deletions app/Models/Backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Models;

use App\Contracts\Validatable;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

Expand All @@ -25,8 +29,10 @@
* @property \App\Models\Server $server
* @property \App\Models\AuditLog[] $audits
*/
class Backup extends Model
class Backup extends Model implements Validatable
{
use HasFactory;
use HasValidation;
use SoftDeletes;

public const RESOURCE_NAME = 'backup';
Expand All @@ -35,8 +41,6 @@ class Backup extends Model

public const ADAPTER_AWS_S3 = 's3';

protected $table = 'backups';

protected $attributes = [
'is_successful' => false,
'is_locked' => false,
Expand Down
19 changes: 8 additions & 11 deletions app/Models/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Models;

use App\Contracts\Validatable;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\DB;

Expand All @@ -21,8 +25,11 @@
* @property \App\Models\Server $server
* @property \App\Models\DatabaseHost $host
*/
class Database extends Model
class Database extends Model implements Validatable
{
use HasFactory;
use HasValidation;

/**
* The resource name for this model when it is transformed into an
* API representation using fractal. Also used as name for api key permissions.
Expand All @@ -31,11 +38,6 @@ class Database extends Model

public const DEFAULT_CONNECTION_NAME = 'dynamic';

/**
* The table associated with the model.
*/
protected $table = 'databases';

/**
* The attributes excluded from the model's JSON form.
*/
Expand Down Expand Up @@ -68,11 +70,6 @@ protected function casts(): array
];
}

public function getRouteKeyName(): string
{
return $this->getKeyName();
}

/**
* Gets the host database server associated with a database.
*/
Expand Down
19 changes: 8 additions & 11 deletions app/Models/DatabaseHost.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

namespace App\Models;

use App\Contracts\Validatable;
use App\Traits\HasValidation;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

Expand All @@ -21,19 +25,17 @@
* @property \Illuminate\Database\Eloquent\Collection|\App\Models\Database[] $databases
* @property int|null $databases_count
*/
class DatabaseHost extends Model
class DatabaseHost extends Model implements Validatable
{
use HasFactory;
use HasValidation;

/**
* The resource name for this model when it is transformed into an
* API representation using fractal. Also used as name for api key permissions.
*/
public const RESOURCE_NAME = 'database_host';

/**
* The table associated with the model.
*/
protected $table = 'database_hosts';

/**
* The attributes excluded from the model's JSON form.
*/
Expand Down Expand Up @@ -70,11 +72,6 @@ protected function casts(): array
];
}

public function getRouteKeyName(): string
{
return 'id';
}

public function nodes(): BelongsToMany
{
return $this->belongsToMany(Node::class);
Expand Down
Loading
Loading