@@ -29,30 +29,32 @@ public static function getTemplatesInfo(): array
2929 return $ info ;
3030 }
3131
32- $ glob = \implode (
33- \DIRECTORY_SEPARATOR ,
34- [
35- __DIR__ ,
36- 'Renderer ' ,
37- '{ ' . \implode (', ' , RendererConstant::TEMPLATE_TYPES ) . '} ' ,
38- '*.php ' ,
39- ]
40- );
41-
42- $ files = \array_filter (
43- \glob ($ glob , \GLOB_BRACE ),
44- // not an abstact class
45- function (string $ file ): bool {
46- return \substr ($ file , 0 , 8 ) !== 'Abstract ' ;
47- }
48- );
49-
50- // class name = file name without the extension
51- $ templates = \array_map (
32+ $ glob = \implode (\DIRECTORY_SEPARATOR , [
33+ static ::getProjectDirectory (),
34+ 'src ' ,
35+ 'Renderer ' ,
36+ '{ ' . \implode (', ' , RendererConstant::TEMPLATE_TYPES ) . '} ' ,
37+ '*.php ' ,
38+ ]);
39+
40+ $ fileNames = \array_map (
41+ // get basename without file extension
5242 function (string $ file ): string {
5343 return \pathinfo ($ file , \PATHINFO_FILENAME );
5444 },
55- $ files
45+ // paths of all Renderer files
46+ \glob ($ glob , \GLOB_BRACE )
47+ );
48+
49+ $ templates = \array_filter (
50+ $ fileNames ,
51+ // only normal class files are wanted
52+ function (string $ fileName ): bool {
53+ return
54+ \substr ($ fileName , 0 , 8 ) !== 'Abstract ' &&
55+ \substr ($ fileName , 0 , -9 ) !== 'Interface ' &&
56+ \substr ($ fileName , 0 , -5 ) !== 'Trait ' ;
57+ }
5658 );
5759
5860 $ info = [];
@@ -83,11 +85,17 @@ public static function getAvailableTemplates(): array
8385 */
8486 public static function getStyleSheet (): string
8587 {
86- static $ filePath = __DIR__ . '/../example/diff-table.css ' ;
88+ static $ fileContent ;
89+
90+ if (isset ($ fileContent )) {
91+ return $ fileContent ;
92+ }
93+
94+ $ filePath = static ::getProjectDirectory () . '/example/diff-table.css ' ;
8795
88- $ cssFile = new \SplFileObject ($ filePath , 'r ' );
96+ $ file = new \SplFileObject ($ filePath , 'r ' );
8997
90- return $ cssFile ->fread ($ cssFile ->getSize ());
98+ return $ fileContent = $ file ->fread ($ file ->getSize ());
9199 }
92100
93101 /**
0 commit comments