for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types = 1);
/**
* /src/Rest/ControllerCollection.php
*
* @author TLe, Tarmo Leppänen <[email protected]>
*/
namespace App\Rest;
use App\Collection\CollectionTrait;
use App\Rest\Interfaces\ControllerInterface;
use Closure;
use Countable;
use IteratorAggregate;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use function sprintf;
* Class ControllerCollection
* @package App\Rest
* @method ControllerInterface get(string $className)
* @method IteratorAggregate<int, ControllerInterface> getAll()
* @template T<ControllerInterface>
class ControllerCollection implements Countable
{
use CollectionTrait;
* Collection constructor.
* @phpstan-param IteratorAggregate<int, ControllerInterface> $items
public function __construct(
#[TaggedIterator('app.rest.controller')]
protected readonly IteratorAggregate $items,
protected readonly LoggerInterface $logger,
) {
}
public function getErrorMessage(string $className): string
return sprintf('REST controller \'%s\' does not exist', $className);
public function filter(string $className): Closure
return static fn (ControllerInterface $restController): bool => $restController instanceof $className;