This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
140 lines (125 loc) · 5.29 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
namespace Zf2Forum;
use Zend\ModuleManager\ModuleManager;
class Module
{
protected static $options;
public function init(ModuleManager $moduleManager)
{
$moduleManager->getEventManager()->attach('loadModules.post', array($this, 'modulesLoaded'));
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
),
),
);
}
public function getServiceConfig()
{
return array(
'invokables' => array(
'Zf2Forum_post_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
'Zf2Forum_thread' => 'Zf2Forum\Model\Topic\Topic',
'Zf2Forum_message' => 'Zf2Forum\Model\Message\Message',
'Zf2Forum_form' => 'Zf2Forum\Form\PostForm',
'Zf2Forum_replyform' => 'Zf2Forum\Form\ReplyForm',
),
'factories' => array(
'Zf2Forum\ModuleOptions' => 'Zf2Forum\Factory\ModuleOptionsFactory',
'Zf2Forum_user_mapper' => 'Zf2Forum\Factory\UserMapperFactory',
'Zf2Forum_discuss_service' => function ($sm) {
$service = new \Zf2Forum\Service\Discuss;
$service->setTopicMapper($sm->get('Zf2Forum_topic_mapper'))
->setMessageMapper($sm->get('Zf2Forum_message_mapper'))
->setCategoryMapper($sm->get('Zf2Forum_category_mapper'))
->setVisitMapper($sm->get('Zf2Forum_visit_mapper'));
return $service;
},
'Zf2Forum_topic_mapper' => function ($sm) {
$mapper = new \Zf2Forum\Model\Topic\TopicMapper;
$threadModelClass = Module::getOption('topic_model_class');
$mapper->setEntityPrototype(new $threadModelClass);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
$mapper->setServiceLocator($sm);
return $mapper;
},
'Zf2Forum_category_mapper' => function ($sm) {
$mapper = new \Zf2Forum\Model\Category\CategoryMapper;
$categoryModelClass = Module::getOption('category_model_class');
$mapper->setEntityPrototype(new $categoryModelClass);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
},
'Zf2Forum_message_mapper' => function ($sm) {
$mapper = new \Zf2Forum\Model\Message\MessageMapper;
//$messageModelClass = static::getOption('message_model_class');
$messageModelClass = Module::getOption('message_model_class');
$mapper->setEntityPrototype(new $messageModelClass);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
},
'Zf2Forum_visit_mapper' => function ($sm) {
$mapper = new \Zf2Forum\Model\Visit\VisitMapper;
$visitModelClass = Module::getOption('visit_model_class');
$mapper->setEntityPrototype(new $visitModelClass);
$mapper->setHydrator(new \Zend\StdLib\Hydrator\ClassMethods);
return $mapper;
},
'Zf2Forum_visit' => function ($sm) {
$visit = new \Zf2Forum\Model\Visit\Visit;
$visit->setIpAddress($_SERVER['REMOTE_ADDR'])
->setVisitTime(new \DateTime);
return $visit;
}
),
'initializers' => array(
function ($instance, $sm) {
if ($instance instanceof Service\DbAdapterAwareInterface) {
$dbAdapter = $sm->get('Zf2Forum_zend_db_adapter');
return $instance->setDbAdapter($dbAdapter);
}
},
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getControllerConfig()
{
return array(
'factories' => array(
'Zf2Forum\Controller\DiscussController' => 'Zf2Forum\Controller\Factory\DiscussController',
),
);
}
public function modulesLoaded($e)
{
$config = $e->getConfigListener()->getMergedConfig();
static::$options = $config['Zf2Forum'];
}
/**
* @TODO: Come up with a better way of handling module settings/options
*/
public static function getOption($option)
{
if (!isset(static::$options[$option])) {
return null;
}
return static::$options[$option];
}
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'RenderForm' => 'Zf2Forum\View\Helper\RenderForm',
'privateSmartTime' => 'Zf2Forum\View\Helper\SmartTime',
)
);
}
}