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