33 lines
988 B
PHP
33 lines
988 B
PHP
<?php
|
|
|
|
namespace App\Doctrine;
|
|
|
|
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
|
|
use App\Entity\Bucket;
|
|
use Doctrine\ORM\QueryBuilder;
|
|
|
|
/**
|
|
* Scopes every Bucket read to the authenticated owner. A Bucket has no direct
|
|
* owner column — ownership is transitive via its Scenario — so this JOINs the
|
|
* `scenario` relation and filters on that join's `owner`.
|
|
*
|
|
* @see AbstractOwnerScopeExtension for the 404-not-403 mechanism.
|
|
*/
|
|
final class BucketOwnerExtension extends AbstractOwnerScopeExtension
|
|
{
|
|
protected function getResourceClass(): string
|
|
{
|
|
return Bucket::class;
|
|
}
|
|
|
|
protected function ownerAlias(
|
|
QueryBuilder $queryBuilder,
|
|
QueryNameGeneratorInterface $queryNameGenerator,
|
|
string $rootAlias,
|
|
): string {
|
|
$scenarioAlias = $queryNameGenerator->generateJoinAlias('scenario');
|
|
$queryBuilder->innerJoin(\sprintf('%s.scenario', $rootAlias), $scenarioAlias);
|
|
|
|
return $scenarioAlias;
|
|
}
|
|
}
|