vendor/shopware/core/Framework/Plugin.php line 74

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Framework;
  3. use Shopware\Core\Framework\Parameter\AdditionalBundleParameters;
  4. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  5. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  6. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  7. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  8. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  9. use Shopware\Core\Kernel;
  10. use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
  11. abstract class Plugin extends Bundle
  12. {
  13.     /**
  14.      * @var bool
  15.      */
  16.     private $active;
  17.     /**
  18.      * @var string
  19.      */
  20.     private $basePath;
  21.     /**
  22.      * @internal
  23.      */
  24.     final public function __construct(bool $activestring $basePath, ?string $projectDir null)
  25.     {
  26.         $this->active $active;
  27.         $this->basePath $basePath;
  28.         if ($projectDir && mb_strpos($this->basePath'/') !== 0) {
  29.             $this->basePath rtrim($projectDir'/') . '/' $this->basePath;
  30.         }
  31.         $this->path $this->computePluginClassPath();
  32.     }
  33.     final public function isActive(): bool
  34.     {
  35.         return $this->active;
  36.     }
  37.     public function install(InstallContext $installContext): void
  38.     {
  39.     }
  40.     public function postInstall(InstallContext $installContext): void
  41.     {
  42.     }
  43.     public function update(UpdateContext $updateContext): void
  44.     {
  45.     }
  46.     public function postUpdate(UpdateContext $updateContext): void
  47.     {
  48.     }
  49.     public function activate(ActivateContext $activateContext): void
  50.     {
  51.     }
  52.     public function deactivate(DeactivateContext $deactivateContext): void
  53.     {
  54.     }
  55.     public function uninstall(UninstallContext $uninstallContext): void
  56.     {
  57.     }
  58.     public function configureRoutes(RoutingConfigurator $routesstring $environment): void
  59.     {
  60.         if (!$this->isActive()) {
  61.             return;
  62.         }
  63.         parent::configureRoutes($routes$environment);
  64.     }
  65.     /**
  66.      * @return Bundle[]
  67.      */
  68.     public function getAdditionalBundles(AdditionalBundleParameters $parameters): array
  69.     {
  70.         return [];
  71.     }
  72.     /**
  73.      * By default the container is rebuild during plugin activation and deactivation to allow the plugin to access
  74.      * its own services. If you are absolutely sure you do not require this feature for you plugin you might want
  75.      * to overwrite this method and return false to improve the activation/deactivation of your plugin. This change will
  76.      * only have an affect in the system context (CLI)
  77.      */
  78.     public function rebuildContainer(): bool
  79.     {
  80.         return true;
  81.     }
  82.     /**
  83.      * Some plugins need to provide 3rd party dependencies.
  84.      * If needed, return true and Shopware will execute `composer require` during the plugin installation.
  85.      * When the plugins gets uninstalled, Shopware executes `composer remove`
  86.      */
  87.     public function executeComposerCommands(): bool
  88.     {
  89.         return false;
  90.     }
  91.     final public function removeMigrations(): void
  92.     {
  93.         // namespace should not start with `shopware`
  94.         if (str_starts_with(mb_strtolower($this->getMigrationNamespace()), 'shopware') && !str_starts_with(mb_strtolower($this->getMigrationNamespace()), 'shopware\commercial')) {
  95.             throw new \RuntimeException('Deleting Shopware migrations is not allowed');
  96.         }
  97.         $class addcslashes($this->getMigrationNamespace(), '\\_%') . '%';
  98.         Kernel::getConnection()->executeUpdate('DELETE FROM migration WHERE class LIKE :class', ['class' => $class]);
  99.     }
  100.     public function getBasePath(): string
  101.     {
  102.         return $this->basePath;
  103.     }
  104.     public function enrichPrivileges(): array
  105.     {
  106.         return [];
  107.     }
  108.     /**
  109.      * Used to configure the BaseUrl for the Admin Extension API
  110.      */
  111.     public function getAdminBaseUrl(): ?string
  112.     {
  113.         return null;
  114.     }
  115.     private function computePluginClassPath(): string
  116.     {
  117.         $canonicalizedPluginClassPath parent::getPath();
  118.         $canonicalizedPluginPath realpath($this->basePath);
  119.         if ($canonicalizedPluginPath !== false && mb_strpos($canonicalizedPluginClassPath$canonicalizedPluginPath) === 0) {
  120.             $relativePluginClassPath mb_substr($canonicalizedPluginClassPathmb_strlen($canonicalizedPluginPath));
  121.             return $this->basePath $relativePluginClassPath;
  122.         }
  123.         return parent::getPath();
  124.     }
  125. }