Просмотр файла app/Controllers/CaptchaController.php

Размер файла: 732B
  1. <?php
  2.  
  3. declare(strict_types=1);
  4.  
  5. namespace App\Controllers;
  6.  
  7. use App\Services\Session;
  8. use Psr\Http\Message\ResponseInterface as Response;
  9. use Visavi\Captcha\CaptchaBuilder;
  10.  
  11. /**
  12. * CaptchaController
  13. */
  14. class CaptchaController extends Controller
  15. {
  16. public function __construct(
  17. protected Session $session,
  18. ) {}
  19.  
  20. /**
  21. * Captcha
  22. *
  23. * @param Response $response
  24. *
  25. * @return Response
  26. */
  27. public function captcha(Response $response): Response
  28. {
  29. $captcha = new CaptchaBuilder();
  30. $this->session->set('captcha', $captcha->getPhrase());
  31.  
  32. $response->getBody()->write($captcha->render());
  33.  
  34. return $response->withHeader('Content-Type', 'image/gif');
  35. }
  36. }