@@ -41,30 +41,32 @@ public static function getTemplatesInfo(): array
4141 return $ info ;
4242 }
4343
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
6454 function (string $ file ): string {
6555 return \pathinfo ($ file , \PATHINFO_FILENAME );
6656 },
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+ }
6870 );
6971
7072 $ info = [];
@@ -95,11 +97,17 @@ public static function getAvailableTemplates(): array
9597 */
9698 public static function getStyleSheet (): string
9799 {
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 ' ;
99107
100- $ cssFile = new \SplFileObject ($ filePath , 'r ' );
108+ $ file = new \SplFileObject ($ filePath , 'r ' );
101109
102- return $ cssFile ->fread ($ cssFile ->getSize ());
110+ return $ fileContent = $ file ->fread ($ file ->getSize ());
103111 }
104112
105113 /**
0 commit comments