vendor/pimcore/pimcore/lib/Extension/Bundle/Traits/StateHelperTrait.php line 22

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * Pimcore
  5. *
  6. * This source file is available under two different licenses:
  7. * - GNU General Public License version 3 (GPLv3)
  8. * - Pimcore Commercial License (PCL)
  9. * Full copyright and license information is available in
  10. * LICENSE.md which is distributed with this source code.
  11. *
  12. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  13. * @license http://www.pimcore.org/license GPLv3 and PCL
  14. */
  15. namespace Pimcore\Extension\Bundle\Traits;
  16. use Pimcore\Extension\Bundle\PimcoreBundleManager;
  17. trigger_deprecation('pimcore/pimcore', '10.6', 'The "%s" trait is deprecated and will be removed in Pimcore 11.', StateHelperTrait::class);
  18. /**
  19. * @deprecated since Pimcore 10.6 and will be removed in Pimcore 11
  20. *
  21. * Helper trait exposing static isEnabled() and isInstalled() methods for bundles which can be used
  22. * to check bundle state from non-service definitions (e.g. class definitions).
  23. */
  24. trait StateHelperTrait
  25. {
  26. /**
  27. * @deprecated will be removed in Pimcore 11
  28. *
  29. * Helper method to check enabled state from class definitions/non-service instances
  30. *
  31. * @return bool
  32. */
  33. public static function isEnabled(): bool
  34. {
  35. $bundleManager = \Pimcore::getContainer()->get(PimcoreBundleManager::class);
  36. if (!$bundleManager->exists(__CLASS__)) {
  37. return false;
  38. }
  39. if (!$bundleManager->isEnabled(__CLASS__)) {
  40. return false;
  41. }
  42. return true;
  43. }
  44. /**
  45. * Helper method to check installed state from class definitions/non-service instances
  46. *
  47. * @return bool
  48. */
  49. public static function isInstalled(): bool
  50. {
  51. if (!static::isEnabled()) {
  52. return false;
  53. }
  54. $bundleManager = \Pimcore::getContainer()->get(PimcoreBundleManager::class);
  55. $bundle = $bundleManager->getActiveBundle(__CLASS__, false);
  56. if (!$bundleManager->isInstalled($bundle)) {
  57. return false;
  58. }
  59. return true;
  60. }
  61. }