MultiViewFinder::listSearchPaths()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
namespace mindplay\kisstpl;
4
5
/**
6
 * This view-finder aggregates a stack of view-finders and attempts to
7
 * locate views by trying every added view-finder in order - use this
8
 * for advanced (modular) "theme" scenarios, etc.
9
 */
10
class MultiViewFinder implements ViewFinder
11
{
12
    /**
13
     * @var ViewFinder[] stack of view-finders
14
     */
15
    protected $finders = array();
16
17
    /**
18
     * Add a view-finder to the top of the stack - the added view-finder will
19
     * have the highest priority of view-finders currently on the stack.
20
     *
21
     * @param ViewFinder $finder
22
     */
23 1
    public function pushViewFinder(ViewFinder $finder)
24
    {
25 1
        array_unshift($this->finders, $finder);
26 1
    }
27
28
    /**
29
     * Add a view-finder to the bottom of the stack - the added view-finder will
30
     * have the lowest priority of view-finders currently on the stack.
31
     *
32
     * @param ViewFinder $finder
33
     */
34 1
    public function addViewFinder(ViewFinder $finder)
35
    {
36 1
        $this->finders[] = $finder;
37 1
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @see ViewFinder::findTemplate()
43
     */
44 1
    public function findTemplate($view_model, $type)
45
    {
46 1
        foreach ($this->finders as $finder) {
47 1
            $path = $finder->findTemplate($view_model, $type);
48
49 1
            if ($path !== null && file_exists($path)) {
50 1
                return $path;
51
            }
52
        }
53
54 1
        return null;
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @see ViewFinder::listSearchPaths()
61
     */
62 1
    public function listSearchPaths($view_model, $type)
63
    {
64 1
        $paths = array();
65
66 1
        foreach ($this->finders as $finder) {
67 1
            $paths = array_merge($paths, $finder->listSearchPaths($view_model, $type));
68
        }
69
70 1
        return $paths;
71
    }
72
}
73