• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / bind-render / 4247038317

pending completion
4247038317

push

github

Olivier Laviale
Prefer chain of template providers

1 of 1 new or added line in 1 file covered. (100.0%)

6 of 17 relevant lines covered (35.29%)

0.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/ApplicationTemplateResolver.php
1
<?php
2

3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
namespace ICanBoogie\Binding\Render;
13

14
use ICanBoogie\Render\TemplateResolver;
15
use ICanBoogie\Render\TemplateResolverTrait;
16

17
use function array_reverse;
18
use function file_exists;
19

20
/**
21
 * Decorates a template resolver and adds support for the application paths.
22
 */
23
final class ApplicationTemplateResolver implements TemplateResolver
24
{
25
    use TemplateResolverTrait;
26

27
    /**
28
     * Application paths.
29
     *
30
     * @var string[]
31
     */
32
    private array $paths;
33

34
    /**
35
     * @param string[] $paths Application paths.
36
     */
37
    public function __construct(array $paths)
38
    {
39
        $this->paths = $this->expend_paths($paths);
×
40
    }
41

42
    /**
43
     * @inheritdoc
44
     */
45
    public function resolve(string $name, array $extensions, array &$tried = []): ?string
46
    {
47
        if (str_starts_with($name, '//')) {
×
48
            return $this->resolve_from_app(substr($name, 2), $extensions, $tried);
×
49
        }
50

51
        return $this->resolve_from_app($name, $extensions, $tried);
×
52
    }
53

54
    /**
55
     * Resolves a template name from the application paths.
56
     *
57
     * @param string[] $extensions The supported extensions.
58
     * @param string[] $tried Tried pathname collection.
59
     */
60
    private function resolve_from_app(string $name, array $extensions, array &$tried): ?string
61
    {
62
        return $this->resolve_path($this->resolve_tries($this->paths, $name, $extensions), $tried);
×
63
    }
64

65
    /**
66
     * Expends application paths into template paths.
67
     *
68
     * **Note:** Paths that do not have a "templates" directory are discarded.
69
     *
70
     * @param string[] $paths Application paths.
71
     *
72
     * @return string[]
73
     */
74
    private function expend_paths(array $paths): array
75
    {
76
        $resolved_paths = [];
×
77

78
        foreach (array_reverse($paths) as $path) {
×
79
            $path .= 'templates' . DIRECTORY_SEPARATOR;
×
80

81
            if (file_exists($path)) {
×
82
                $resolved_paths[] = $path;
×
83
            }
84
        }
85

86
        return $resolved_paths;
×
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc