-
Notifications
You must be signed in to change notification settings - Fork 15
/
Module.php
121 lines (108 loc) · 4.51 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
118
119
120
121
<?php
/**
* CgmConfigAdmin
*
* @link http://github.com/cgmartin/CgmConfigAdmin for the canonical source repository
* @copyright Copyright (c) 2012-2013 Christopher Martin (http://cgmartin.com)
* @license New BSD License https://raw.github.com/cgmartin/CgmConfigAdmin/master/LICENSE
*/
namespace CgmConfigAdmin;
use CgmConfigAdmin\View\Helper\CgmFlashMessages;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Session\Container as SessionContainer;
class Module implements
AutoloaderProviderInterface,
ConfigProviderInterface,
ServiceProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// if we're in a namespace deeper than one level we need to fix the \ in the path
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getViewHelperConfig()
{
return array(
'factories' => array(
'cgmFlashMessages' => function($sm) {
$plugin = $sm->getServiceLocator()
->get('ControllerPluginManager')
->get('flashMessenger');
$helper = new CgmFlashMessages($plugin);
return $helper;
},
),
);
}
public function getServiceConfig()
{
return array(
'invokables' => array(
'cgmconfigadmin' => 'CgmConfigAdmin\Service\ConfigAdmin',
'cgmconfigadmin_form' => 'CgmConfigAdmin\Form\ConfigOptionsForm',
'cgmconfigadmin_configgroup' => 'CgmConfigAdmin\Model\ConfigGroup',
'cgmconfigadmin_configoption' => 'CgmConfigAdmin\Model\ConfigOption',
'cgmconfigadmin_configgroupfactory' => 'CgmConfigAdmin\Model\ConfigGroupFactory',
),
'shared' => array(
'cgmconfigadmin_configgroup' => false,
'cgmconfigadmin_configoption' => false,
),
'factories' => array(
// Configuration options for entire module
'cgmconfigadmin_module_options' => function($sm) {
$config = $sm->get('Config');
return new Options\ModuleOptions(
isset($config['cgmconfigadmin']) ? $config['cgmconfigadmin'] : array()
);
},
// Session container
'cgmconfigadmin_session' => function($sm) {
$session = new SessionContainer('cgmconfigadmin');
return $session;
},
// Data Mapper for config values
'cgmconfigadmin_configvalues_mapper' => function ($sm) {
/** @var $options Options\ModuleOptions */
$options = $sm->get('cgmconfigadmin_module_options');
$mapper = new Entity\ConfigValuesMapper();
$mapper->setTableName($options->getConfigValuesTable());
$mapper->setDbAdapter($sm->get('cgmconfigadmin_zend_db_adapter'));
$mapper->setEntityPrototype(new Entity\ConfigValues);
$mapper->setHydrator(new Entity\ConfigValuesHydrator());
return $mapper;
},
// Example Per-user settings
// * Requires ZfcUser *
/*
'cgmconfigadmin_userconfig' => function($sm) {
$authService = $sm->get('zfcuser_auth_service');
$userId = null;
if ($authService->hasIdentity()) {
$userId = $authService->getIdentity()->getId();
}
$service = new Service\ConfigAdmin('user', $userId);
$service->setIsPreviewEnabled(false); // To disable settings preview
return $service;
}
*/
),
);
}
}