Advertisement
Foxxything

Untitled

Sep 29th, 2022
1,364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. namespace Foxx\Library\Action;
  3.  
  4. use Psr\Http\Message\ResponseInterface as Response;
  5. use Psr\Http\Message\ServerRequestInterface as Request;
  6.  
  7. use Foxx\Library\Core\Persistence\BookManager;
  8.  
  9.  
  10. final class HomeAction {
  11.   private BookManager $bookManager;
  12.  
  13.   public function __construct(BookManager $bookManager) {
  14.     $this->bookManager = $bookManager;
  15.   }
  16.  
  17.   public function __invoke(Request $request, Response $response): Response {
  18.     $bookManager = $this->bookManager;
  19.     $books = $bookManager->getBooks();
  20.  
  21.     $response->getBody()->write(
  22.       "<h1>Books</h1>
  23.      <ul>"
  24.     );
  25.    
  26.     foreach ($books as $book) {
  27.       $response->getBody()->write(
  28.         "<li>
  29.          <a href='/book?id=" . $book->getId() . "'>" . $book->getTitle() . "</a>
  30.        </li>"
  31.       );
  32.     }
  33.  
  34.     $response->getBody()->write(
  35.       "</ul>"
  36.     );
  37.  
  38.     return $response;
  39.  
  40.   }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement