@@ -8,19 +8,14 @@ class CodeigniterVite
88 /**
99 * @var string manifest path.
1010 */
11- private $ manifest ;
12-
13- public function __construct ()
14- {
15- $ this ->manifest = is_file (FCPATH . 'manifest.json ' ) ? FCPATH . 'manifest.json ' : null ;
16- }
11+ private static $ manifest = FCPATH . 'manifest.json ' ;
1712
1813 /**
1914 * Get vite entry file on running or bundled files instead.
2015 *
2116 * @return string single script tag on developing and much more on production
2217 */
23- public function tags ()
18+ public static function tags (): ? string
2419 {
2520 # Check if vite is running.
2621 $ entryFile = env ('VITE_ORIGIN ' ) . '/ ' . env ('VITE_RESOURCES_DIR ' ) . '/ ' . env ('VITE_ENTRY_FILE ' );
@@ -30,14 +25,14 @@ public function tags()
3025 # React HMR fix.
3126 if (!empty ($ result ))
3227 {
33- $ result = $ this -> getReactTag () . "$ result " ;
28+ $ result = self :: getReactTag () . "$ result " ;
3429 }
3530
3631 # If vite isn't running, then return the compiled resources.
37- if (empty ($ result ) && $ this -> manifest )
32+ if (empty ($ result ) && is_file ( self :: $ manifest) )
3833 {
3934 # Get the manifest content.
40- $ manifest = file_get_contents ($ this -> manifest );
35+ $ manifest = file_get_contents (self :: $ manifest );
4136 # You look much pretty as an php object =).
4237 $ manifest = json_decode ($ manifest );
4338
@@ -67,7 +62,7 @@ public function tags()
6762 *
6863 * @return string|null a simple module script
6964 */
70- public function getReactTag ()
65+ public static function getReactTag (): ? string
7166 {
7267 if (env ('VITE_FRAMEWORK ' ) === 'react ' )
7368 {
@@ -84,22 +79,23 @@ public function getReactTag()
8479 *
8580 * @return bool true if vite is runnig or if manifest does exist, otherwise false;
8681 */
87- public function check (): bool
82+ public static function check (): bool
8883 {
8984 # Check if vite is running.
9085 $ entryFile = env ('VITE_ORIGIN ' ) . '/ ' . env ('VITE_RESOURCES_DIR ' ) . '/ ' . env ('VITE_ENTRY_FILE ' );
9186
92- if (@file_get_contents ($ entryFile ))
93- {
94- $ result = true ;
95- }
96- elseif (!empty ($ this ->manifest ))
97- {
98- $ result = true ;
99- }
100- else
87+ switch (true )
10188 {
102- $ result = false ;
89+ case @file_get_contents ($ entryFile ):
90+ $ result = true ;
91+ break ;
92+ case !empty (self ::$ manifest ):
93+ $ result = true ;
94+ break ;
95+
96+ default :
97+ $ result = false ;
98+ break ;
10399 }
104100
105101 return $ result ;
0 commit comments