-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathioDoctrineMenuPluginConfiguration.class.php
119 lines (106 loc) · 3.14 KB
/
ioDoctrineMenuPluginConfiguration.class.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
<?php
/**
* Plugin configuration
*
* @package ioDoctrineMenuPlugin
* @subpackage Doctrine_Record
* @author Ryan Weaver <[email protected]>
*/
class ioDoctrineMenuPluginConfiguration extends sfPluginConfiguration
{
protected $_menuManager;
public function initialize()
{
if (in_array('io_doctrine_menu', sfConfig::get('sf_enabled_modules', array())))
{
$this->dispatcher->connect('routing.load_configuration', array($this, 'loadRoutes'));
}
$actions = new ioDoctrineMenuActions($this);
$this->dispatcher->connect('component.method_not_found', array($actions, 'extend'));
}
/**
* Retrieves the ioDoctrineMenuManager for this context
*
* @return ioDoctrineMenuManager
*/
public function getMenuManager()
{
if ($this->_menuManager === null)
{
$manager = new ioDoctrineMenuManager();
// Set the cache driver if caching is enabled
$cacheConfig = sfConfig::get('app_doctrine_menu_cache');
if ($cacheConfig['enabled'])
{
$class = $cacheConfig['class'];
$options = isset($cacheConfig['options']) ? $cacheConfig['options'] : array();
$cacheDriver = new $class($options);
$manager->setCacheDriver($cacheDriver);
}
$this->_menuManager = $manager;
}
return $this->_menuManager;
}
/**
* Listens to routing.load_configuration
*
* @param sfEvent $event The routing.load_configuration event
* @return void
*/
public function loadRoutes(sfEvent $event)
{
$prefix = sfConfig::get('app_doctrine_menu_module_prefix', '/admin/menu');
$event->getSubject()->prependRoute('io_doctrine_menu', new sfDoctrineRouteCollection(array(
'name' => 'io_doctrine_menu',
'model' => 'ioDoctrineMenuItem',
'module' => 'io_doctrine_menu',
'prefix_path' => $prefix,
'with_wildcard_routes' => true,
'collection_actions' => array(),
'requirements' => array(),
)));
$event->getSubject()->prependRoute('io_doctrine_menu_reorder', new sfDoctrineRoute(
$prefix.'/reorder/:id',
array(
'module' => 'io_doctrine_menu',
'action' => 'reorder',
),
array(
'sf_method' => array('get'),
),
array(
'model' => 'ioDoctrineMenuItem',
'type' => 'object',
)
));
$event->getSubject()->prependRoute('io_doctrine_menu_reorder_json', new sfDoctrineRoute(
$prefix.'/reorder/json/:id',
array(
'module' => 'io_doctrine_menu',
'action' => 'json',
'sf_format' => 'json',
),
array(
'sf_method' => array('get'),
),
array(
'model' => 'ioDoctrineMenuItem',
'type' => 'object',
)
));
$event->getSubject()->prependRoute('io_doctrine_menu_reorder_save', new sfDoctrineRoute(
$prefix.'/reorder/save/:id',
array(
'module' => 'io_doctrine_menu',
'action' => 'saveJson',
),
array(
'sf_method' => array('post'),
),
array(
'model' => 'ioDoctrineMenuItem',
'type' => 'object',
)
));
}
}