forked from Bittarman/rest-essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
54 lines (43 loc) · 1.98 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
<?php
namespace RESTEssentials;
use Zend\Mvc\ModuleRouteListener;
class Module {
protected $sm;
protected $config;
protected $em;
public function getDefaultConfig($config) {
$config['DefaultModule'] = isset($config['DefaultModule']) ? $config['DefaultModule'] : 'Home';
$config['DefaultController'] = isset($config['DefaultController']) ? $config['DefaultController'] : 'Default';
$config['LogChanges'] = isset($config['LogChanges']) ? $config['LogChanges'] : true;
$config['EntityPath'] = isset($config['EntityPath']) ? $config['EntityPath'] : getcwd() . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
return $config;
}
public function onBootstrap(\Zend\Mvc\MvcEvent $e) {
$this->sm = $e->getApplication()->getServiceManager();
$this->em = $this->sm->get('Doctrine\ORM\EntityManager');
$config = $this->sm->get('config');
$this->config = $this->getDefaultConfig(
(isset($config['RESTEssentials']) ? $config['RESTEssentials'] : array())
);
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
public function getConfig() {
$this->config = $this->getDefaultConfig(
(isset($this->config['RESTEssentials']) ? $this->config['RESTEssentials'] : array())
);
$config = \Zend\Stdlib\ArrayUtils::merge(array('RESTEssentials' => $this->config), (include __DIR__ . '/config/module.config.php'));
$config['doctrine']['driver']['Entity']['paths'][] = $this->config['EntityPath'];
return $config;
}
public function getAutoloaderConfig() {
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
}