1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
4
|
|
|
use TEiling\Scd16\Commands\Scd16Command; |
5
|
|
|
|
6
|
|
|
class Shopware_Plugins_Core_Scd16_Bootstrap extends Shopware_Components_Plugin_Bootstrap |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
public function install() |
9
|
|
|
{ |
10
|
|
|
$minSwVersion = $this->getPluginJsonAsArray()['compatibility']['minimumVersion']; |
11
|
|
|
if (!$this->assertMinimumVersion($minSwVersion)) { |
12
|
|
|
throw new \RuntimeException('At least Shopware ' . $minSwVersion . ' is required'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
$this->subscribeEvent( |
16
|
|
|
'Shopware_Console_Add_Command', |
17
|
|
|
'onAddConsoleCommand' |
18
|
|
|
); |
19
|
|
|
|
20
|
|
|
return true; |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Callback function of the console event subscriber. Register your console commands here. |
25
|
|
|
* |
26
|
|
|
* @param Enlight_Event_EventArgs $args |
27
|
|
|
* |
28
|
|
|
* @return ArrayCollection |
29
|
|
|
* @throws \LogicException |
30
|
|
|
*/ |
31
|
|
|
public function onAddConsoleCommand(Enlight_Event_EventArgs $args) |
32
|
|
|
{ |
33
|
|
|
$this->registerMyComponents(); |
34
|
|
|
|
35
|
|
|
return new ArrayCollection( |
36
|
|
|
[ |
37
|
|
|
new Scd16Command() |
38
|
|
|
] |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* registerMyComponents function to add auto loader |
44
|
|
|
*/ |
45
|
|
|
private function registerMyComponents() |
46
|
|
|
{ |
47
|
|
|
require_once(__DIR__ . '/vendor/autoload.php'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @return array |
52
|
|
|
* @throws Enlight_Config_Exception |
53
|
|
|
*/ |
54
|
|
|
private function getPluginJsonAsArray() |
55
|
|
|
{ |
56
|
|
|
$json = json_decode(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'plugin.json'), true); |
57
|
|
|
if ($json) { |
58
|
|
|
return $json; |
59
|
|
|
} else { |
60
|
|
|
throw new \Enlight_Config_Exception('The plugin has an invalid version file.'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return mixed |
66
|
|
|
* @throws Enlight_Config_Exception |
67
|
|
|
*/ |
68
|
|
|
public function getVersion() |
69
|
|
|
{ |
70
|
|
|
return $this->getPluginJsonAsArray()['currentVersion']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return mixed |
75
|
|
|
* @throws Enlight_Config_Exception |
76
|
|
|
*/ |
77
|
|
|
public function getLabel() |
78
|
|
|
{ |
79
|
|
|
return $this->getPluginJsonAsArray()['label']['de']; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return array with information |
84
|
|
|
* @throws \Enlight_Config_Exception |
85
|
|
|
* returns an array with information for Shopware Plugin Manager |
86
|
|
|
*/ |
87
|
|
|
public function getInfo() |
88
|
|
|
{ |
89
|
|
|
return [ |
90
|
|
|
'version' => $this->getVersion(), |
91
|
|
|
'label' => $this->getLabel(), |
92
|
|
|
'author' => $this->getPluginJsonAsArray()['author'], |
93
|
|
|
'link' => $this->getPluginJsonAsArray()['link'], |
94
|
|
|
'description' => $this->getPluginJsonAsArray()['description'] |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.