EmbedViewHelper::execute()   C
last analyzed

Complexity

Conditions 7
Paths 24

Size

Total Lines 30
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 2
Metric Value
c 3
b 2
f 2
dl 0
loc 30
rs 6.7272
cc 7
eloc 17
nc 24
nop 1
1
<?php
2
namespace Fwk\Core\Components\ViewHelper;
3
4
class EmbedViewHelper extends AbstractViewHelper implements ViewHelper
5
{
6
    public function execute(array $arguments)
7
    {
8
        $actionName = (isset($arguments[0]) ? $arguments[0] : null);
9
        $parameters = (isset($arguments[1]) ? $arguments[1] : array());
10
        
11
        if (empty($actionName)) {
12
            throw new Exception(sprintf('Empty action name'));
13
        }
14
        
15
        if (!is_array($parameters)) {
16
            throw new Exception(sprintf('Parameters should be an array'));
17
        }
18
        
19
        $context = $this->getViewHelperService()->getContext()->newParent();
20
        $context->setActionName($actionName);
21
        
22
        foreach ($parameters as $key => $value) {
23
            $context->getRequest()->query->set($key, $value);
24
        }
25
        
26
        $result = $this->getViewHelperService()
27
                    ->getApplication()
28
                    ->runAction($context);
29
        
30
        if ($context->getResponse() instanceof \Symfony\Component\HttpFoundation\Response) {
31
            return $context->getResponse()->getContent();
32
        }
33
        
34
        return $result;
35
    }
36
}