Split spec to join ApiKey spec with short URLs, into inlined and regular versions

This commit is contained in:
Alejandro Celaya
2022-01-18 20:14:24 +01:00
parent 9e9621e7b2
commit d0546a2ea2
3 changed files with 31 additions and 9 deletions

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Shlinkio\Shlink\Rest\ApiKey\Spec;
use Happyr\DoctrineSpecification\Spec;
use Happyr\DoctrineSpecification\Specification\BaseSpecification;
use Happyr\DoctrineSpecification\Specification\Specification;
use Shlinkio\Shlink\Rest\Entity\ApiKey;
class WithInlinedApiKeySpecsEnsuringJoin extends BaseSpecification
{
public function __construct(private ?ApiKey $apiKey, private string $fieldToJoin = 'shortUrls')
{
parent::__construct();
}
protected function getSpec(): Specification
{
return $this->apiKey === null || $this->apiKey->isAdmin() ? Spec::andX() : Spec::andX(
Spec::join($this->fieldToJoin, 's'),
$this->apiKey->inlinedSpec(),
);
}
}