Ajde_Component_Include::process()   C
last analyzed

Complexity

Conditions 8
Paths 15

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 15
nc 15
nop 0
dl 0
loc 25
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
class Ajde_Component_Include extends Ajde_Component
4
{
5
    public static function processStatic(Ajde_Template_Parser $parser, $attributes)
6
    {
7
        $instance = new self($parser, $attributes);
8
9
        return $instance->process();
10
    }
11
12
    public function process()
13
    {
14
        if (!array_key_exists('route', $this->attributes)) {
15
            // TODO:
16
            throw new Ajde_Component_Exception();
17
        }
18
        $route = $this->attributes['route'];
19
        if (!$route instanceof Ajde_Core_Route) {
20
            $route = new Ajde_Core_Route($route);
21
        }
22
        $controller = Ajde_Controller::fromRoute($route);
23
        if (array_key_exists('vars',
24
                $this->attributes) && is_array($this->attributes['vars']) && !empty($this->attributes['vars'])
25
        ) {
26
            try {
27
                $view = $controller->getView();
28
                foreach ($this->attributes['vars'] as $key => $var) {
29
                    $view->assign($key, $var);
30
                }
31
            } catch (Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
32
            }
33
        }
34
35
        return $controller->invoke();
36
    }
37
}
38