Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
Map | |
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
matchNamespacePrefix | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
matchBaseDirectory | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | /** |
4 | * @license MIT |
5 | * @author hazuki3417<hazuki3417@gmail.com> |
6 | * @copyright 2023 hazuki3417 all rights reserved. |
7 | */ |
8 | |
9 | namespace Selen\PSR4; |
10 | |
11 | /** |
12 | * 名前空間のnamespace prefixとbase directoryのマッピング情報を保持するクラスです |
13 | */ |
14 | class Map implements Constants |
15 | { |
16 | /** |
17 | * @var string 名前空間のprefix |
18 | */ |
19 | public readonly string $namespacePrefix; |
20 | |
21 | /** |
22 | * @var string 名前空間のprefixに対応するbase directory |
23 | */ |
24 | public readonly string $baseDirectory; |
25 | |
26 | public function __construct(string $namespacePrefix, string $baseDirectory) |
27 | { |
28 | // 先頭または末尾にある区切り文字を除去(記載揺れの対応) |
29 | $this->namespacePrefix = \trim($namespacePrefix, self::DELIMITER_NAMESPACE); |
30 | $this->baseDirectory = \trim($baseDirectory, self::DELIMITER_PATH); |
31 | } |
32 | |
33 | public function matchNamespacePrefix(string $namespace): bool |
34 | { |
35 | return strpos($namespace, $this->namespacePrefix) === 0; |
36 | } |
37 | |
38 | public function matchBaseDirectory(string $path): bool |
39 | { |
40 | return strpos($path, $this->baseDirectory) === 0; |
41 | } |
42 | } |