|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Magium\Configuration\View; |
|
4
|
|
|
|
|
5
|
|
|
use Interop\Container\ContainerInterface; |
|
6
|
|
|
use Magium\Configuration\Config\Repository\ConfigurationRepository; |
|
7
|
|
|
use Magium\Configuration\MagiumConfigurationFactoryInterface; |
|
8
|
|
|
use Magium\Configuration\View\Controllers\Layout; |
|
9
|
|
|
use Magium\Configuration\View\Controllers\View; |
|
10
|
|
|
use Zend\View\Renderer\PhpRenderer; |
|
11
|
|
|
use Zend\View\Resolver\TemplatePathStack; |
|
12
|
|
|
|
|
13
|
|
|
class ViewManager |
|
14
|
|
|
{ |
|
15
|
|
|
|
|
16
|
|
|
protected $viewConfiguration; |
|
17
|
|
|
protected $magiumConfigurationFactory; |
|
18
|
|
|
protected $diContainer; |
|
19
|
|
|
protected $view; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct( |
|
22
|
|
|
ViewConfiguration $viewConfiguration, |
|
23
|
|
|
MagiumConfigurationFactoryInterface $magiumConfigurationFactory, |
|
24
|
|
|
ContainerInterface $diContainer |
|
25
|
|
|
) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->viewConfiguration = $viewConfiguration; |
|
28
|
|
|
$this->magiumConfigurationFactory = $magiumConfigurationFactory; |
|
29
|
|
|
$this->diContainer = $diContainer; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function render() |
|
33
|
|
|
{ |
|
34
|
|
|
$request = $this->viewConfiguration->getRequest(); |
|
35
|
|
|
$params = $request->getQueryParams(); |
|
36
|
|
|
|
|
37
|
|
|
// This pseudo router section is because I don't want to create yet-another-dependency in the project. |
|
38
|
|
|
if ($request->getMethod() == 'GET' && !isset($params['section'])) { |
|
39
|
|
|
$layout = new Layout( |
|
40
|
|
|
$this->viewConfiguration, |
|
41
|
|
|
$this->getConfiguration(), |
|
42
|
|
|
$this->getContextFile() |
|
43
|
|
|
); |
|
44
|
|
|
$viewModel = $layout->execute($request); |
|
45
|
|
|
} else if ($request->getMethod() == 'GET' && isset($params['section'])) { |
|
46
|
|
|
$context = ConfigurationRepository::CONTEXT_DEFAULT; |
|
47
|
|
|
if (isset($params['context'])) { |
|
48
|
|
|
$context = $params['context']; |
|
49
|
|
|
} |
|
50
|
|
|
$view = new View( |
|
51
|
|
|
$this->viewConfiguration, |
|
52
|
|
|
$this->getBuilder(), |
|
53
|
|
|
$this->getMergedStructure(), |
|
54
|
|
|
$this->getConfiguration($context), |
|
55
|
|
|
$this->diContainer |
|
56
|
|
|
); |
|
57
|
|
|
$viewModel = $view->execute($request); |
|
58
|
|
|
} else if ($request->getMethod() == 'POST') { |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$renderer = new PhpRenderer(); |
|
63
|
|
|
$mRenderer = new MagiumRenderer(); |
|
64
|
|
|
$mRenderer->setView($renderer); |
|
65
|
|
|
$renderer->getHelperPluginManager()->setService('magiumRenderer', $mRenderer); |
|
66
|
|
|
$renderer->setResolver(new TemplatePathStack(['script_paths' => [$this->viewConfiguration->getViewDirectory()]])); |
|
67
|
|
|
$content = $renderer->render($viewModel); |
|
|
|
|
|
|
68
|
|
|
$this->viewConfiguration->getResponse()->getBody()->write($content); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function getBuilder() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->magiumConfigurationFactory->getBuilder(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getConfiguration($context = ConfigurationRepository::CONTEXT_DEFAULT) |
|
77
|
|
|
{ |
|
78
|
|
|
return $this->magiumConfigurationFactory->getManager()->getConfiguration($context); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getMergedStructure() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->magiumConfigurationFactory->getBuilder()->getMergedStructure(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getContextFile() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->magiumConfigurationFactory->getContextFile(); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks for the bodies of
ifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
ifbodies can be removed. If you have an empty if but statements in theelsebranch, consider inverting the condition.could be turned into
This is much more concise to read.