Skip to content

Commit 92bf6a8

Browse files
committed
Fix a bug
1 parent 78bf7ec commit 92bf6a8

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/CodeigniterVite.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class CodeigniterVite
88
/**
99
* @var string manifest path.
1010
*/
11-
private static $manifest;
11+
private $manifest;
1212

1313
public function __construct()
1414
{
15-
self::$manifest = is_file(FCPATH . 'manifest.json') ? FCPATH . 'manifest.json' : null;
15+
$this->manifest = is_file(FCPATH . 'manifest.json') ? FCPATH . 'manifest.json' : null;
1616
}
1717

1818
/**
1919
* Get vite entry file on running or bundled files instead.
2020
*
2121
* @return string single script tag on developing and much more on production
2222
*/
23-
public static function tags()
23+
public function tags()
2424
{
2525
# Check if vite is running.
2626
$entryFile = env('VITE_ORIGIN') . '/' . env('VITE_RESOURCES_DIR') . '/' . env('VITE_ENTRY_FILE');
@@ -30,14 +30,14 @@ public static function tags()
3030
# React HMR fix.
3131
if (!empty($result))
3232
{
33-
$result = self::getReactTag() . "$result";
33+
$result = $this->getReactTag() . "$result";
3434
}
3535

3636
# If vite isn't running, then return the compiled resources.
37-
if (empty($result) && self::$manifest)
37+
if (empty($result) && $this->manifest)
3838
{
3939
# Get the manifest content.
40-
$manifest = file_get_contents(self::$manifest);
40+
$manifest = file_get_contents($this->manifest);
4141
# You look much pretty as an php object =).
4242
$manifest = json_decode($manifest);
4343

@@ -67,7 +67,7 @@ public static function tags()
6767
*
6868
* @return string|null a simple module script
6969
*/
70-
public static function getReactTag()
70+
public function getReactTag()
7171
{
7272
if (env('VITE_FRAMEWORK') === 'react')
7373
{
@@ -84,7 +84,7 @@ public static function getReactTag()
8484
*
8585
* @return bool true if vite is runnig or if manifest does exist, otherwise false;
8686
*/
87-
public static function check(): bool
87+
public function check(): bool
8888
{
8989
# Check if vite is running.
9090
$entryFile = env('VITE_ORIGIN') . '/' . env('VITE_RESOURCES_DIR') . '/' . env('VITE_ENTRY_FILE');
@@ -93,7 +93,7 @@ public static function check(): bool
9393
{
9494
$result = true;
9595
}
96-
elseif (!empty(self::$manifest))
96+
elseif (!empty($this->manifest))
9797
{
9898
$result = true;
9999
}

src/Decorator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ class Decorator implements ViewDecoratorInterface
88
{
99
public static function decorate(string $html): string
1010
{
11+
$vite = new CodeigniterVite();
12+
1113
# Check if vite is running or manifest is ready.
12-
if (CodeigniterVite::check())
14+
if ($vite->check())
1315
{
1416
# Get generated js and css tags.
15-
$tags = CodeigniterVite::tags();
17+
$tags = $vite->tags();
1618

1719
# Insert tags just before "</head>" tag.
1820
$html = empty($tags) ? $html : str_replace('</head>', "\n\t$tags\n</head>", $html);

0 commit comments

Comments
 (0)