AbstractAuth.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\HTTP\Auth;
  4. use Sabre\HTTP\RequestInterface;
  5. use Sabre\HTTP\ResponseInterface;
  6. /**
  7. * HTTP Authentication base class.
  8. *
  9. * This class provides some common functionality for the various base classes.
  10. *
  11. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  12. * @author Evert Pot (http://evertpot.com/)
  13. * @license http://sabre.io/license/ Modified BSD License
  14. */
  15. abstract class AbstractAuth
  16. {
  17. /**
  18. * Authentication realm.
  19. *
  20. * @var string
  21. */
  22. protected $realm;
  23. /**
  24. * Request object.
  25. *
  26. * @var RequestInterface
  27. */
  28. protected $request;
  29. /**
  30. * Response object.
  31. *
  32. * @var ResponseInterface
  33. */
  34. protected $response;
  35. /**
  36. * Creates the object.
  37. */
  38. public function __construct(string $realm, RequestInterface $request, ResponseInterface $response)
  39. {
  40. $this->realm = $realm;
  41. $this->request = $request;
  42. $this->response = $response;
  43. }
  44. /**
  45. * This method sends the needed HTTP header and status code (401) to force
  46. * the user to login.
  47. */
  48. abstract public function requireLogin();
  49. /**
  50. * Returns the HTTP realm.
  51. */
  52. public function getRealm(): string
  53. {
  54. return $this->realm;
  55. }
  56. }