@@ -41,30 +41,32 @@ public static function getTemplatesInfo(): array
41
41
return $ info ;
42
42
}
43
43
44
- $ glob = \implode (
45
- \DIRECTORY_SEPARATOR ,
46
- [
47
- __DIR__ ,
48
- 'Renderer ' ,
49
- '{ ' . \implode (', ' , RendererConstant::TEMPLATE_TYPES ) . '} ' ,
50
- '*.php ' ,
51
- ]
52
- );
53
-
54
- $ files = \array_filter (
55
- \glob ($ glob , \GLOB_BRACE ),
56
- // not an abstact class
57
- function (string $ file ): bool {
58
- return \substr ($ file , 0 , 8 ) !== 'Abstract ' ;
59
- }
60
- );
61
-
62
- // class name = file name without the extension
63
- $ templates = \array_map (
44
+ $ glob = \implode (\DIRECTORY_SEPARATOR , [
45
+ static ::getProjectDirectory (),
46
+ 'src ' ,
47
+ 'Renderer ' ,
48
+ '{ ' . \implode (', ' , RendererConstant::TEMPLATE_TYPES ) . '} ' ,
49
+ '*.php ' ,
50
+ ]);
51
+
52
+ $ fileNames = \array_map (
53
+ // get basename without file extension
64
54
function (string $ file ): string {
65
55
return \pathinfo ($ file , \PATHINFO_FILENAME );
66
56
},
67
- $ files
57
+ // paths of all Renderer files
58
+ \glob ($ glob , \GLOB_BRACE )
59
+ );
60
+
61
+ $ templates = \array_filter (
62
+ $ fileNames ,
63
+ // only normal class files are wanted
64
+ function (string $ fileName ): bool {
65
+ return
66
+ \substr ($ fileName , 0 , 8 ) !== 'Abstract ' &&
67
+ \substr ($ fileName , 0 , -9 ) !== 'Interface ' &&
68
+ \substr ($ fileName , 0 , -5 ) !== 'Trait ' ;
69
+ }
68
70
);
69
71
70
72
$ info = [];
@@ -95,11 +97,17 @@ public static function getAvailableTemplates(): array
95
97
*/
96
98
public static function getStyleSheet (): string
97
99
{
98
- static $ filePath = __DIR__ . '/../example/diff-table.css ' ;
100
+ static $ fileContent ;
101
+
102
+ if (isset ($ fileContent )) {
103
+ return $ fileContent ;
104
+ }
105
+
106
+ $ filePath = static ::getProjectDirectory () . '/example/diff-table.css ' ;
99
107
100
- $ cssFile = new \SplFileObject ($ filePath , 'r ' );
108
+ $ file = new \SplFileObject ($ filePath , 'r ' );
101
109
102
- return $ cssFile ->fread ($ cssFile ->getSize ());
110
+ return $ fileContent = $ file ->fread ($ file ->getSize ());
103
111
}
104
112
105
113
/**
0 commit comments