-
Notifications
You must be signed in to change notification settings - Fork 16
/
Module.php
117 lines (97 loc) · 3.72 KB
/
Module.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace SpeckCatalog;
class Module
{
protected $serviceManager;
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getConfig()
{
$config = array();
$configFiles = array(
__DIR__ . '/config/module.config.php',
__DIR__ . '/config/module.config.routes.php',
__DIR__ . '/config/module.config.servicemanager.php',
);
foreach($configFiles as $configFile) {
$config = \Zend\Stdlib\ArrayUtils::merge($config, include $configFile);
}
return $config;
}
public function getViewHelperConfig()
{
return include(__DIR__ . '/config/services/viewhelpers.php');
}
public function getServiceConfig()
{
return include(__DIR__ . '/config/services/servicemanager.php');
}
public function onBootstrap($e)
{
if($e->getRequest() instanceof \Zend\Console\Request){
return;
}
$app = $e->getParam('application');
$locator = $app->getServiceManager();
$this->setServiceManager($locator);
$em = $app->getEventManager()->getSharedManager();
$em->attach('ImageUploader\Service\Uploader', 'fileupload.pre', array('SpeckCatalog\Event\FileUpload', 'preFileUpload'));
$em->attach('ImageUploader\Service\Uploader', 'fileupload.post', array('SpeckCatalog\Event\FileUpload', 'postFileUpload'));
$em->attach('SpeckCatalog\Service\ProductUom', 'insert.post', function ($e) {
$eventClass = new Event\FrontendEnabled;
$eventClass->insertProductUom($e);
});
$em->attach('SpeckCatalog\Service\ProductUom', 'update.post', function ($e) {
$eventClass = new Event\FrontendEnabled;
$eventClass->updateProductUom($e);
});
$em->attach('SpeckCatalog\Service\Product', 'update.post', array('SpeckCatalog\Event\FrontendEnabled', 'updateProduct'));
$em->attach('SpeckCatalog\Service\Product', 'insert.post', array('SpeckCatalog\Event\FrontendEnabled', 'insertProduct'));
//install event listeners
$em->attach('SpeckInstall\Controller\InstallController', 'install.create_tables.post', array($this, 'constraints'),1);
}
public function constraints($e)
{
try {
$mapper = $e->getParam('mapper');
//check dependencies
$tables = $mapper->query("show tables like 'contact_company'");
if(!count($tables)) {
return array(false, 'SpeckCatalog could not add table constraints - missing table contact_company from SpeckContact');
}
$tables = $mapper->query("show tables like 'catalog_product'");
if(!count($tables)) {
return array(false, 'SpeckCatalog could not add table constraints - missing tables provided by SpeckCatalog');
}
$alter = file_get_contents(__DIR__ .'/data/alter.sql');
$mapper->query($alter);
} catch (\Exception $e) {
return array(false, "SpeckCatalog could not add table constraints - " . $e->getMessage());
}
return array(true, "SpeckCatalog added table constraints");
}
/**
* @return serviceManager
*/
public function getServiceManager()
{
return $this->serviceManager;
}
/**
* @param $serviceManager
* @return self
*/
public function setServiceManager($serviceManager)
{
$this->serviceManager = $serviceManager;
return $this;
}
}