Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Foxx\Library\Action;
- use Psr\Http\Message\ResponseInterface as Response;
- use Psr\Http\Message\ServerRequestInterface as Request;
- use Foxx\Library\Core\Persistence\BookManager;
- final class HomeAction {
- private BookManager $bookManager;
- public function __construct(BookManager $bookManager) {
- $this->bookManager = $bookManager;
- }
- public function __invoke(Request $request, Response $response): Response {
- $bookManager = $this->bookManager;
- $books = $bookManager->getBooks();
- $response->getBody()->write(
- "<h1>Books</h1>
- <ul>"
- );
- foreach ($books as $book) {
- $response->getBody()->write(
- "<li>
- <a href='/book?id=" . $book->getId() . "'>" . $book->getTitle() . "</a>
- </li>"
- );
- }
- $response->getBody()->write(
- "</ul>"
- );
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement