authorization_store.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace phpnotify;
  3. /**
  4. * This could be used to store authorization method in the class.
  5. *
  6. * That class helps other classes storing authorization method, which is
  7. * implemented in more than one class.
  8. */
  9. class authorization_store {
  10. /**
  11. * This variable store current authorization method.
  12. * @var authorization_method
  13. */
  14. private authorization_method $method;
  15. /**
  16. * This initialize new aithorization part of class. It is protected.
  17. *
  18. * This function initialize authorization store. When any method is not
  19. * provided, then it use default empty authorization. Method could be
  20. * given there, for example when it is used by class, which is created
  21. * by class which also store authorization. It is protected, because it
  22. * would not being used as autonomous class.
  23. *
  24. * @param ?authorization_method Default method of authorization.
  25. */
  26. protected function __construct(?authorization_method $method = null) {
  27. if ($method === null) {
  28. $method = new empty_authorization();
  29. }
  30. $this->method = $method;
  31. }
  32. /**
  33. * That function return current setup access authorization method.
  34. *
  35. * @return authorization_method Current authorization method.
  36. */
  37. public function get_access_method(): authorization_method {
  38. return $this->method;
  39. }
  40. /**
  41. * This set new access method to use in the requests.
  42. *
  43. * @param authorization_method New method of the authorization.
  44. *
  45. * @return object Self to chain loading.
  46. */
  47. public function access_method(authorization_method $method): object {
  48. $this->method = $method;
  49. return $this;
  50. }
  51. }