src/Eccube/Service/PluginContext.php line 78

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Service;
  13. use Eccube\Common\EccubeConfig;
  14. use Eccube\Exception\PluginException;
  15. class PluginContext
  16. {
  17.     private const MODE_INSTALL 'install';
  18.     private const MODE_UNINSTALL 'uninstall';
  19.     private $mode;
  20.     private $code;
  21.     private $composerJson;
  22.     /**
  23.      * @var EccubeConfig
  24.      */
  25.     private $eccubeConfig;
  26.     public function __construct(EccubeConfig $eccubeConfig)
  27.     {
  28.         $this->eccubeConfig $eccubeConfig;
  29.     }
  30.     public function isInstall()
  31.     {
  32.         return $this->mode === self::MODE_INSTALL;
  33.     }
  34.     public function isUninstall()
  35.     {
  36.         return $this->mode === self::MODE_UNINSTALL;
  37.     }
  38.     public function setInstall()
  39.     {
  40.         return $this->mode self::MODE_INSTALL;
  41.     }
  42.     public function setUninstall()
  43.     {
  44.         return $this->mode self::MODE_UNINSTALL;
  45.     }
  46.     public function setCode(string $code)
  47.     {
  48.         $this->code $code;
  49.     }
  50.     public function getComposerJson(): array
  51.     {
  52.         if ($this->composerJson) {
  53.             return $this->composerJson;
  54.         }
  55.         $projectRoot $this->eccubeConfig->get('kernel.project_dir');
  56.         $composerJsonPath $projectRoot.'/app/Plugin/'.$this->code.'/composer.json';
  57.         if (file_exists($composerJsonPath) === false) {
  58.             throw new PluginException("${composerJsonPath} not found.");
  59.         }
  60.         $this->composerJson json_decode(file_get_contents($composerJsonPath), true);
  61.         if ($this->composerJson === null) {
  62.             throw new PluginException("Invalid json format. [${composerJsonPath}]");
  63.         }
  64.         return $this->composerJson;
  65.     }
  66.     public function getExtraEntityNamespaces(): array
  67.     {
  68.         $json $this->getComposerJson();
  69.         if (isset($json['extra'])) {
  70.             if (array_key_exists('entity-namespaces'$json['extra'])) {
  71.                 return $json['extra']['entity-namespaces'];
  72.             }
  73.         }
  74.         return [];
  75.     }
  76. }