Skip to content

Commit 7a41029

Browse files
committed
View: blade.compiler register
1 parent dcd41ec commit 7a41029

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/AffordableMobiles/GServerlessSupportLaravel/View/Compilers/FakeCompiler.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66

77
use AffordableMobiles\GServerlessSupportLaravel\View\Exceptions\RuntimeCompilationNotSupportedException;
88
use Illuminate\Support\Str;
9+
use Illuminate\View\Compilers\BladeCompiler;
910
use Illuminate\View\Compilers\CompilerInterface;
1011

1112
/**
1213
* A compiler implementation that performs NO compilation at runtime.
1314
* It relies on a pre-generated manifest (views part) and the runtime cache path
1415
* to find already compiled views. Used in production serverless environments.
1516
*/
16-
class FakeCompiler implements CompilerInterface
17+
class FakeCompiler extends BladeCompiler implements CompilerInterface
1718
{
1819
/**
1920
* The default echo format.
@@ -178,21 +179,24 @@ public function compile($path = null): void
178179
}
179180

180181
/**
181-
* Get the Blade extensions.
182+
* Compile the given Blade template contents.
183+
*
184+
* @param string $value
185+
*
186+
* @return string
182187
*/
183-
public function getExtensions(): array
188+
public function compileString($value)
184189
{
185-
return ['blade.php'];
190+
throw new RuntimeCompilationNotSupportedException(
191+
'Runtime Blade compilation is disabled in this environment.'
192+
);
186193
}
187194

188195
/**
189-
* Register a path for anonymous blade components.
190-
* This is a no-op at runtime as components are pre-compiled.
196+
* Get the Blade extensions.
191197
*/
192-
public function anonymousComponentPath(string $path, ?string $prefix = null): void
198+
public function getExtensions(): array
193199
{
194-
// We don't need to do anything here at runtime because the view manifest
195-
// has already mapped all the components during the pre-compilation step.
196-
// This method just needs to exist to satisfy Livewire's service provider.
200+
return ['blade.php'];
197201
}
198202
}

src/AffordableMobiles/GServerlessSupportLaravel/View/ViewServiceProvider.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function register(): void
6666

6767
if ($this->isRunning) {
6868
$this->registerGServerlessViewFinder();
69+
$this->registerGServerlessBladeCompiler();
6970
$this->registerGServerlessEngineResolver();
7071
$this->registerGServerlessViewFactory(); // Register our custom factory
7172
} elseif ($this->isServerless && !$this->isRunning) {
@@ -138,11 +139,9 @@ public function registerGServerlessEngineResolver(): void
138139
}
139140

140141
/**
141-
* Register the GServerless Blade engine implementation (Runtime).
142-
*
143-
* @param mixed $resolver
142+
* Register the Blade compiler implementation.
144143
*/
145-
public function registerGServerlessBladeEngine($resolver): void
144+
public function registerGServerlessBladeCompiler(): void
146145
{
147146
$this->app->singleton('gserverless.blade.compiler.fake', static function ($app) {
148147
$finder = $app['view.finder'];
@@ -159,7 +158,15 @@ public function registerGServerlessBladeEngine($resolver): void
159158
});
160159

161160
$this->app->singleton('blade.compiler', static fn ($app) => $app['gserverless.blade.compiler.fake']);
161+
}
162162

163+
/**
164+
* Register the GServerless Blade engine implementation (Runtime).
165+
*
166+
* @param mixed $resolver
167+
*/
168+
public function registerGServerlessBladeEngine($resolver): void
169+
{
163170
$resolver->register('blade', fn () => new CompilerEngine($this->app['gserverless.blade.compiler.fake']));
164171
}
165172

0 commit comments

Comments
 (0)