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