1 | <?php |
||
11 | class SimpleViewFinder implements ViewFinder |
||
12 | { |
||
13 | /** |
||
14 | * @var string absolute path to the view root-folder for the base namespace |
||
15 | */ |
||
16 | public $root_path; |
||
17 | |||
18 | /** |
||
19 | * @var string|null base namespace for view-models supported by this finder |
||
20 | */ |
||
21 | public $namespace = null; |
||
22 | |||
23 | /** |
||
24 | * @param string $root_path absolute path to view root-folder |
||
25 | * @param string|null $namespace optional; base namespace for view-models supported by this finder |
||
26 | */ |
||
27 | 1 | public function __construct($root_path, $namespace = null) |
|
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | * |
||
36 | * @see ViewFinder::findTemplate() |
||
37 | */ |
||
38 | 1 | public function findTemplate($view_model, $type) |
|
39 | { |
||
40 | 1 | $name = $this->getTemplateName($view_model); |
|
41 | |||
42 | 1 | return $name |
|
43 | 1 | ? $this->root_path . DIRECTORY_SEPARATOR . $name . ".{$type}.php" |
|
44 | 1 | : null; |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | * |
||
50 | * @see ViewFinder::listSearchPaths() |
||
51 | */ |
||
52 | 1 | public function listSearchPaths($view_model, $type) |
|
56 | |||
57 | /** |
||
58 | * @param object $view_model view-model |
||
59 | * |
||
60 | * @return string|null template name (e.g. "Bar/Baz" for class Foo\Bar\Baz if $namespace is 'Foo') |
||
61 | * |
||
62 | * @throws RuntimeException if the given view-model doesn't belong to the base namespace |
||
63 | * |
||
64 | * @see ViewFinder::findTemplate() |
||
65 | */ |
||
66 | 1 | protected function getTemplateName($view_model) |
|
83 | } |
||
84 |