mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-27 17:24:42 +02:00
* refactor(api): prefer composition to strict inheritance for API queries, requests & actions * style: fix StyleCI findigns
49 lines
1.2 KiB
PHP
49 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Api\Field\Base;
|
|
|
|
use App\Http\Api\Field\IntField;
|
|
use App\Http\Api\Query\Query;
|
|
use App\Http\Api\Schema\Schema;
|
|
use App\Http\Resources\BaseResource;
|
|
|
|
/**
|
|
* Class IdField.
|
|
*/
|
|
class IdField extends IntField
|
|
{
|
|
/**
|
|
* Create a new field instance.
|
|
*
|
|
* @param Schema $schema
|
|
* @param string $column
|
|
*/
|
|
public function __construct(Schema $schema, string $column)
|
|
{
|
|
parent::__construct($schema, BaseResource::ATTRIBUTE_ID, $column);
|
|
}
|
|
|
|
/**
|
|
* Determine if the field should be included in the select clause of our query.
|
|
*
|
|
* @param Query $query
|
|
* @param Schema $schema
|
|
* @return bool
|
|
*/
|
|
public function shouldSelect(Query $query, Schema $schema): bool
|
|
{
|
|
// We can only exclude ID fields for top-level models that are not including related resources.
|
|
$includeCriteria = $query->getIncludeCriteria($this->schema->type());
|
|
if (
|
|
$this->schema->type() === $schema->type()
|
|
&& ($includeCriteria === null || $includeCriteria->getPaths()->isEmpty())
|
|
) {
|
|
return parent::shouldSelect($query, $schema);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|