vendor/shopware/core/Framework/App/ActiveAppsLoader.php line 59

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework\App;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\DevOps\Environment\EnvironmentHelper;
  5. use Shopware\Core\Framework\App\Lifecycle\AbstractAppLoader;
  6. use Shopware\Core\Framework\App\Manifest\Manifest;
  7. use Shopware\Core\Framework\Log\Package;
  8. use Symfony\Contracts\Service\ResetInterface;
  9. /**
  10.  * @internal only for use by the app-system, will be considered internal from v6.4.0 onward
  11.  *
  12.  * @phpstan-type App array{name: string, path: string, author: string|null}
  13.  */
  14. #[Package('core')]
  15. class ActiveAppsLoader implements ResetInterface
  16. {
  17.     /**
  18.      * @var App[]|null
  19.      */
  20.     private ?array $activeApps null;
  21.     public function __construct(
  22.         private readonly Connection $connection,
  23.         private readonly AbstractAppLoader $appLoader
  24.     ) {
  25.     }
  26.     /**
  27.      * @return App[]
  28.      */
  29.     public function getActiveApps(): array
  30.     {
  31.         if (EnvironmentHelper::getVariable('DISABLE_EXTENSIONS'false)) {
  32.             return [];
  33.         }
  34.         if ($this->activeApps === null) {
  35.             $this->activeApps $this->loadApps();
  36.         }
  37.         return $this->activeApps;
  38.     }
  39.     public function reset(): void
  40.     {
  41.         $this->activeApps null;
  42.     }
  43.     /**
  44.      * @return App[]
  45.      */
  46.     private function loadApps(): array
  47.     {
  48.         try {
  49.             /** @var App[] $apps */
  50.             $apps $this->connection->fetchAllAssociative('
  51.                 SELECT `name`, `path`, `author`
  52.                 FROM `app`
  53.                 WHERE `active` = 1
  54.             ');
  55.             return $apps;
  56.         } catch (\Throwable $e) {
  57.             if (\defined('\STDERR')) {
  58.                 fwrite(\STDERR'Warning: Failed to load apps. Loading apps from local. Message: ' $e->getMessage() . \PHP_EOL);
  59.             }
  60.             return array_map(fn (Manifest $manifest) => [
  61.                 'name' => $manifest->getMetadata()->getName(),
  62.                 'path' => $manifest->getPath(),
  63.                 'author' => $manifest->getMetadata()->getAuthor(),
  64.             ], $this->appLoader->load());
  65.         }
  66.     }
  67. }