Ajde_Component_Include::processStatic()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
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