-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
123 lines (110 loc) · 4.49 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
<?php
namespace CivContent;
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 getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function getServiceConfig()
{
return array(
'invokables' => array(
'civcontent_category_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
'civcontent_post_form_hydrator' => 'Zend\Stdlib\Hydrator\ClassMethods',
),
'factories' => array(
'civcontent_service' => function($sm) {
$service = new \CivContent\Service\Content;
$service->setCategoryMapper($sm->get('civcontent_category_mapper'));
$service->setPostMapper($sm->get('civcontent_post_mapper'));
return $service;
},
'civcontent_post_mapper' => function($sm) {
$mapper = new \CivContent\Model\Post\PostMapper;
$postModelClass = Module::getOption('post_model_class');
$mapper->setEntityPrototype(new $postModelClass);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
},
'civcontent_post' => function($sm) {
$post = new \CivContent\Model\Post\Post;
return $post;
},
'civcontent_post_form' => function($sm) {
$form = new \CivContent\Form\ContentForm;
$form->setCategories($sm->get('civcontent_service'));
$form->setInputFilter(new \CivContent\Form\PostFilter());
$form->setHydrator($sm->get('civcontent_post_form_hydrator'));
return $form;
},
'civcontent_category_mapper' => function($sm) {
$mapper = new \CivContent\Model\Category\CategoryMapper;
$categoryModelClass = Module::getOption('category_model_class');
$mapper->setEntityPrototype(new $categoryModelClass);
$mapper->setHydrator(new \Zend\Stdlib\Hydrator\ClassMethods);
return $mapper;
},
'civcontent_category' => function($sm) {
$category = new\CivContent\Model\Category\Category;
return $category;
},
'civcontent_category_form' => function($sm) {
$form = new \CivContent\Form\CategoryForm;
$form->setInputFilter(new \CivContent\Form\CategoryFilter());
$form->setHydrator($sm->get('civcontent_category_form_hydrator'));
return $form;
},
'civcontent_confirmation_form' => function($sm) {
$form = new \CivContent\Form\ConfirmationForm;
return $form;
}
),
'initializers' => array(
function($instance, $sm){
if($instance instanceof Service\DbAdapterAwareInterface){
$dbAdapter = $sm->get('civcontent_zend_db_adapter');
return $instance->setDbAdapter($dbAdapter);
}
},
),
);
}
public function getViewHelperConfig()
{
return array(
'invokables' => array(
'RenderFormHorizontal' => 'CivContent\View\Helper\RenderFormHorizontal',
'RenderFormVertical' => 'CivContent\View\Helper\RenderFormVertical'
)
);
}
public function modulesLoaded($e)
{
$config = $e->getConfigListener()->getMergedConfig();
static::$options = $config['civcontent'];
}
public static function getOption($option)
{
if (!isset(static::$options[$option])) {
return null;
}
return static::$options[$option];
}
}