FlexGravTrait.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Traits;
  10. use Grav\Common\Grav;
  11. use Grav\Common\User\Interfaces\UserInterface;
  12. use Grav\Framework\Flex\Flex;
  13. /**
  14. * Implements Grav specific logic
  15. */
  16. trait FlexGravTrait
  17. {
  18. /**
  19. * @return Grav
  20. */
  21. protected function getContainer(): Grav
  22. {
  23. return Grav::instance();
  24. }
  25. /**
  26. * @return Flex
  27. */
  28. protected function getFlexContainer(): Flex
  29. {
  30. $container = $this->getContainer();
  31. /** @var Flex $flex */
  32. $flex = $container['flex'];
  33. return $flex;
  34. }
  35. /**
  36. * @return UserInterface|null
  37. */
  38. protected function getActiveUser(): ?UserInterface
  39. {
  40. $container = $this->getContainer();
  41. /** @var UserInterface|null $user */
  42. $user = $container['user'] ?? null;
  43. return $user;
  44. }
  45. /**
  46. * @return bool
  47. */
  48. protected function isAdminSite(): bool
  49. {
  50. $container = $this->getContainer();
  51. return isset($container['admin']);
  52. }
  53. /**
  54. * @return string
  55. */
  56. protected function getAuthorizeScope(): string
  57. {
  58. return $this->isAdminSite() ? 'admin' : 'site';
  59. }
  60. }