UserObjectLegacyTrait.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @package Grav\Common\Flex
  5. *
  6. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  7. * @license MIT License; see LICENSE file for details.
  8. */
  9. namespace Grav\Common\Flex\Types\Users\Traits;
  10. use Grav\Common\Page\Medium\ImageMedium;
  11. use Grav\Common\Page\Medium\StaticImageMedium;
  12. use function count;
  13. /**
  14. * Trait UserObjectLegacyTrait
  15. * @package Grav\Common\Flex\Types\Users\Traits
  16. */
  17. trait UserObjectLegacyTrait
  18. {
  19. /**
  20. * Merge two configurations together.
  21. *
  22. * @param array $data
  23. * @return $this
  24. * @deprecated 1.6 Use `->update($data)` instead (same but with data validation & filtering, file upload support).
  25. */
  26. public function merge(array $data)
  27. {
  28. user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use ->update($data) method instead', E_USER_DEPRECATED);
  29. $this->setElements($this->getBlueprint()->mergeData($this->toArray(), $data));
  30. return $this;
  31. }
  32. /**
  33. * Return media object for the User's avatar.
  34. *
  35. * @return ImageMedium|StaticImageMedium|null
  36. * @deprecated 1.6 Use ->getAvatarImage() method instead.
  37. */
  38. public function getAvatarMedia()
  39. {
  40. user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use ->getAvatarImage() method instead', E_USER_DEPRECATED);
  41. return $this->getAvatarImage();
  42. }
  43. /**
  44. * Return the User's avatar URL
  45. *
  46. * @return string
  47. * @deprecated 1.6 Use ->getAvatarUrl() method instead.
  48. */
  49. public function avatarUrl()
  50. {
  51. user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6, use ->getAvatarUrl() method instead', E_USER_DEPRECATED);
  52. return $this->getAvatarUrl();
  53. }
  54. /**
  55. * Checks user authorization to the action.
  56. * Ensures backwards compatibility
  57. *
  58. * @param string $action
  59. * @return bool
  60. * @deprecated 1.5 Use ->authorize() method instead.
  61. */
  62. public function authorise($action)
  63. {
  64. user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.5, use ->authorize() method instead', E_USER_DEPRECATED);
  65. return $this->authorize($action) ?? false;
  66. }
  67. /**
  68. * Implements Countable interface.
  69. *
  70. * @return int
  71. * @deprecated 1.6 Method makes no sense for user account.
  72. */
  73. #[\ReturnTypeWillChange]
  74. public function count()
  75. {
  76. user_error(__CLASS__ . '::' . __FUNCTION__ . '() is deprecated since Grav 1.6', E_USER_DEPRECATED);
  77. return count($this->jsonSerialize());
  78. }
  79. }