forked from pablodip/PablodipModuleBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleView.php
More file actions
138 lines (123 loc) · 3.3 KB
/
Copy pathModuleView.php
File metadata and controls
138 lines (123 loc) · 3.3 KB
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
<?php
/*
* This file is part of the PablodipModuleBundle package.
*
* (c) Pablo Díez <pablodip@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Pablodip\ModuleBundle\Module;
/**
* ModuleView.
*
* @author Pablo Díez <pablodip@gmail.com>
*/
class ModuleView
{
private $module;
/**
* Constructor.
*
* @param ModuleInterface $module.
*/
public function __construct(ModuleInterface $module)
{
$this->module = $module;
}
/**
* Returns the module.
*
* @return ModuleInterface The module.
*/
protected function getModule()
{
return $this->module;
}
/**
* Checks if the module has a named action
*
* @param string $actionName The action name.
*
* @return bool
*/
public function hasAction($actionName)
{
return $this->module->hasAction($actionName);
}
/**
* Generates a path for a module url.
*
* @param string $actionName The action name.
* @param array $parameters An array of parameters.
*
* @return string The path.
*/
public function path($actionName, array $parameters = array())
{
return $this->module->generateModuleUrl($actionName, $parameters, false);
}
/**
* Generates a url for a module url.
*
* @param string $actionName The action name.
* @param array $parameters An array of parameters.
*
* @return string The path.
*/
public function url($actionName, array $parameters = array())
{
return $this->module->generateModuleUrl($actionName, $parameters, true);
}
/**
* Returns a module option.
*
* @param string $name The name.
*
* @return mixed The value.
*/
public function getOption($name)
{
return $this->module->getOption($name);
}
/**
* Returns an action option.
*
* @param string $actionName The action name.
* @param string $optionName The option name.
*
* @return mixed The option value.
*/
public function getActionOption($actionName, $optionName)
{
return $this->module->getAction($actionName)->getOption($optionName);
}
/**
* Renders an action.
*
* @param string $actionName The action name.
* @param array $attributes An array of attributes (optional).
* @param array $options An array of options (optional).
*
* @see Symfony\Bundle\FrameworkBundle\HttpKernel::render()
*/
public function render($actionName, array $attributes = array(), array $options = array())
{
$controller = 'PablodipModuleBundle:Module:execute';
$attributes['_module.module'] = get_class($this->module);
$attributes['_module.action'] = $actionName;
$options['attributes'] = $attributes;
return $this->module->getContainer()->get('http_kernel')->render($controller, $options);
}
/**
* Returns the parameters to propagate.
*
* Useful when you have to propagate parameters in a form.
*
* @return array The parameters to propagate.
*/
public function getParametersToPropagate()
{
return $this->module->getParametersToPropagate();
}
}