Completed
Branch dbal-improvement (06db1a)
by Anton
03:59
created

Bundler::importable()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Stempler\Importers;
9
10
use Spiral\Stempler\ImporterInterface;
11
use Spiral\Stempler\Supervisor;
12
13
/**
14
 * Share all template importers with given supervisor.
15
 */
16
class Bundler implements ImporterInterface
17
{
18
    /**
19
     * Importers fetched from bundle file.
20
     *
21
     * @var ImporterInterface[]
22
     */
23
    protected $importers = [];
24
25
    /**
26
     * @param Supervisor $supervisor
27
     * @param string     $path
28
     * @param array      $token
29
     */
30
    public function __construct(Supervisor $supervisor, $path, array $token = [])
31
    {
32
        $node = $supervisor->createNode($path, $token);
33
        $supervisor = $node->supervisor();
34
35
        if ($supervisor instanceof Supervisor) {
36
            $this->importers = $supervisor->getImporters();
37
        }
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function importable($element, array $token)
44
    {
45
        foreach ($this->importers as $importer) {
46
            if ($importer->importable($element, $token)) {
47
                return true;
48
            }
49
        }
50
51
        return false;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function resolvePath($element, array $token)
58
    {
59
        foreach ($this->importers as $importer) {
60
            if ($importer->importable($element, $token)) {
61
                return $importer->resolvePath($element, $token);
62
            }
63
        }
64
65
        return null;
66
    }
67
}