Snapshot of main at 9f39a6e1e (2026-11-02)
This commit is contained in:
commit
6ccf1792d7
2580 files changed
+1040202
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Services\PlatformOverrides;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
/**
|
||||
* Copy a template from the code into the platform folder to change it there. The copy starts with a Blade
|
||||
* comment holding the original's sha1, so platform:check can tell when the original changes later.
|
||||
*
|
||||
* php artisan platform:override emails.layouts.html an app view
|
||||
* php artisan platform:override mail::html.panel a mail component (header, footer, button, ...)
|
||||
* php artisan platform:override wirechat::components.divider a package view
|
||||
*/
|
||||
class PlatformOverride extends Command
|
||||
{
|
||||
protected $signature = 'platform:override {view : View name, e.g. emails.layouts.html, mail::html.panel or wirechat::components.divider}
|
||||
{--force : Replace an existing copy (e.g. after the original changed)}';
|
||||
|
||||
protected $description = 'Copy a template into the platform folder, with a fingerprint of its original';
|
||||
|
||||
public function handle(PlatformOverrides $overrides): int
|
||||
{
|
||||
$view = (string) $this->argument('view');
|
||||
$namespace = str_contains($view, '::') ? strstr($view, '::', true) : null;
|
||||
$name = str_replace('.', '/', $namespace ? substr($view, strlen($namespace) + 2) : $view) . '.blade.php';
|
||||
$relative = match ($namespace) {
|
||||
null => $name,
|
||||
'mail' => "mail/{$name}",
|
||||
default => "vendor/{$namespace}/{$name}",
|
||||
};
|
||||
|
||||
$original = $overrides->originalOf($relative);
|
||||
if ($original === null) {
|
||||
$this->error("No template {$view} in the code.");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$target = platform_path("views/{$relative}");
|
||||
if (is_file($target) && !$this->option('force')) {
|
||||
$this->error("platform/views/{$relative} exists already. Use --force to replace it (your changes in it are lost).");
|
||||
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
File::ensureDirectoryExists(dirname($target));
|
||||
File::put($target, '{{-- platform:override of ' . $overrides->shown($original) . ' sha1:' . sha1_file($original) . " --}}\n" . File::get($original));
|
||||
$this->info("Copied {$overrides->shown($original)} to platform/views/{$relative}. Change it there; php artisan view:clear afterwards.");
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user