diff --git a/config/remote-view.php b/config/remote-view.php index a487c97..7923881 100644 --- a/config/remote-view.php +++ b/config/remote-view.php @@ -1,7 +1,6 @@ [ @@ -10,7 +9,7 @@ 'connect_timeout' => 5, ], - 'url_modifier' => DefaultUrlModifier::class, + 'url_modifier' => [], 'blade_modifier' => DefaultBladeFilename::class, @@ -25,12 +24,15 @@ 'hosts' => [ 'default' => [ 'cache' => false, - 'host' => 'https://www.your-first-content-domain.tld', + 'host' => 'https://www.sportschau.de', 'request_options' => [ 'auth_user' => '', 'auth_password' => '', ], - 'mapping' => [], + 'mapping' => [ + '403' => '/fussball/fifa-wm-2022/wm-katar-auslosung-deutschland-gegner-100.html', + '404' => '/fussball/fifa-wm-2022/audio-dfb-team-so-lief-die-qualifikation-zur-wm-in-katar-100.html', + ], ], 'specific' => [ diff --git a/src/Commands/WarmupTemplates.php b/src/Commands/WarmupTemplates.php new file mode 100644 index 0000000..a90fee6 --- /dev/null +++ b/src/Commands/WarmupTemplates.php @@ -0,0 +1,46 @@ + $config) { + foreach ($config['mapping'] as $name => $url) { + try { + $result = $fileViewFinder->find('remote:'.$host.'::'.$name); + $this->comment($result); + } catch (Exception) { + $this->error('Das war nix.'); + } + } + } + + return 0; + } +} diff --git a/src/Exceptions/InvalidUrlModifierException.php b/src/Exceptions/InvalidUrlModifierException.php new file mode 100644 index 0000000..d252564 --- /dev/null +++ b/src/Exceptions/InvalidUrlModifierException.php @@ -0,0 +1,9 @@ +registerFactory(); $this->registerBladeCompiler(); $this->registerEngineResolver(); + $this->commands(WarmupTemplates::class); } /** diff --git a/src/Support/AbstractUrlModifier.php b/src/Support/AbstractUrlModifier.php new file mode 100644 index 0000000..164d2ae --- /dev/null +++ b/src/Support/AbstractUrlModifier.php @@ -0,0 +1,17 @@ +breakTheCycle; + } + + abstract public function getQueryString(): bool; +} diff --git a/src/Support/DefaultResponseHandler.php b/src/Support/DefaultResponseHandler.php deleted file mode 100644 index a84fcbd..0000000 --- a/src/Support/DefaultResponseHandler.php +++ /dev/null @@ -1,11 +0,0 @@ -getTemplateUrlForIdentifier($name, $remoteHost); - $url = app(config('remote-view.url_modifier', DefaultUrlModifier::class))->determine($url); + + foreach (config('remote-view.url_modifier', []) as $urlModifierClass) { + $modifierInstance = app($urlModifierClass); + + if (! $modifierInstance instanceof AbstractUrlModifier) { + throw new InvalidUrlModifierException; + } + + if ($modifierInstance->applicable()) { + $url .= $modifierInstance->getQueryString(); + } + + if ($modifierInstance->breakTheCycle()) { + break; + } + } $path = $this->getViewFolder($namespace); $path .= app(config('remote-view.blade_modifier', DefaultBladeFilename::class))->determine($url);