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

  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.  * @phpstan-type App array{name: string, path: string, author: string|null}
  12.  */
  13. #[Package('core')]
  14. class ActiveAppsLoader implements ResetInterface
  15. {
  16.     /**
  17.      * @var App[]|null
  18.      */
  19.     private ?array $activeApps null;
  20.     public function __construct(private readonly Connection $connection, private readonly AbstractAppLoader $appLoader)
  21.     {
  22.     }
  23.     /**
  24.      * @return App[]
  25.      */
  26.     public function getActiveApps(): array
  27.     {
  28.         if (EnvironmentHelper::getVariable('DISABLE_EXTENSIONS'false)) {
  29.             return [];
  30.         }
  31.         if ($this->activeApps === null) {
  32.             $this->activeApps $this->loadApps();
  33.         }
  34.         return $this->activeApps;
  35.     }
  36.     public function reset(): void
  37.     {
  38.         $this->activeApps null;
  39.     }
  40.     /**
  41.      * @return App[]
  42.      */
  43.     private function loadApps(): array
  44.     {
  45.         try {
  46.             /** @var App[] $apps */
  47.             $apps $this->connection->fetchAllAssociative('
  48.                 SELECT `name`, `path`, `author`
  49.                 FROM `app`
  50.                 WHERE `active` = 1
  51.             ');
  52.             return $apps;
  53.         } catch (\Throwable $e) {
  54.             if (\defined('\STDERR')) {
  55.                 fwrite(\STDERR'Warning: Failed to load apps. Loading apps from local. Message: ' $e->getMessage() . \PHP_EOL);
  56.             }
  57.             return array_map(fn (Manifest $manifest) => [
  58.                 'name' => $manifest->getMetadata()->getName(),
  59.                 'path' => $manifest->getPath(),
  60.                 'author' => $manifest->getMetadata()->getAuthor(),
  61.             ], $this->appLoader->load());
  62.         }
  63.     }
  64. }