52 lines
2.6 KiB
PHP
52 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\RepositoryConnection;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class RepositoryConnectionResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
$provider = $this->resource instanceof RepositoryConnection
|
|
? $this->provider
|
|
: null;
|
|
|
|
return [
|
|
'id' => $this->resource instanceof RepositoryConnection ? $this->id : Arr::get($this->resource, 'id'),
|
|
'project_id' => $this->resource instanceof RepositoryConnection ? $this->project_id : Arr::get($this->resource, 'project_id'),
|
|
'provider' => $provider?->value ?? Arr::get($this->resource, 'provider'),
|
|
'provider_label' => $provider?->label() ?? Arr::get($this->resource, 'provider_label'),
|
|
'base_url' => $this->resource instanceof RepositoryConnection ? $this->base_url : Arr::get($this->resource, 'base_url'),
|
|
'provider_repository_id' => $this->resource instanceof RepositoryConnection
|
|
? $this->provider_repository_id
|
|
: Arr::get($this->resource, 'provider_repository_id'),
|
|
'owner_name' => $this->resource instanceof RepositoryConnection ? $this->owner_name : Arr::get($this->resource, 'owner_name'),
|
|
'repository_name' => $this->resource instanceof RepositoryConnection
|
|
? $this->repository_name
|
|
: Arr::get($this->resource, 'repository_name'),
|
|
'repository_full_name' => $this->resource instanceof RepositoryConnection
|
|
? $this->repository_full_name
|
|
: Arr::get($this->resource, 'repository_full_name'),
|
|
'repository_url' => $this->resource instanceof RepositoryConnection ? $this->repository_url : Arr::get($this->resource, 'repository_url'),
|
|
'has_personal_access' => $this->resource instanceof RepositoryConnection
|
|
? (bool) ($this->resource->getAttribute('has_personal_access') ?? false)
|
|
: (bool) Arr::get($this->resource, 'has_personal_access', false),
|
|
'created_at' => $this->resource instanceof RepositoryConnection
|
|
? $this->created_at?->toISOString()
|
|
: Arr::get($this->resource, 'created_at'),
|
|
'updated_at' => $this->resource instanceof RepositoryConnection
|
|
? $this->updated_at?->toISOString()
|
|
: Arr::get($this->resource, 'updated_at'),
|
|
];
|
|
}
|
|
}
|