for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Uxmp\Core\Api\Random;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Uxmp\Core\Api\AbstractApiApplication;
use Uxmp\Core\Api\Lib\Message\JsonEnabledResponseInterface;
use Uxmp\Core\Api\Lib\ResultItemFactoryInterface;
use Uxmp\Core\Component\Song\RandomSongsRetrieverInterface;
final class RandomSongsApplication extends AbstractApiApplication
{
/** @var int */
private const DEFAULT_LIMIT = 100;
public function __construct(
private readonly RandomSongsRetrieverInterface $randomSongsRetriever,
private readonly ResultItemFactoryInterface $resultItemFactory,
) {
}
protected function run(
ServerRequestInterface $request,
JsonEnabledResponseInterface $response,
array $args
): ResponseInterface {
$list = [];
$limit = (int) ($args['limit'] ?? self::DEFAULT_LIMIT);
foreach ($this->randomSongsRetriever->retrieve($limit) as $song) {
$album = $song->getDisc()->getAlbum();
$list[] = $this->resultItemFactory->createSongListItem($song, $album);
return $response->withJson(
['items' => $list]
);