Skip to content

Instantly share code, notes, and snippets.

@cednore
Created June 22, 2022 09:03
Show Gist options
  • Save cednore/08b0ef3abead6f3df712d807ec7757b8 to your computer and use it in GitHub Desktop.
Save cednore/08b0ef3abead6f3df712d807ec7757b8 to your computer and use it in GitHub Desktop.
Patch UserPresenter class not found error (#2274) (see https://github.com/orchidsoftware/platform/issues/2274)
<?php
namespace Cednore\Cedi\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class PatchOrchidPlatform extends Command
{
/**
* Class name to be patched.
*
* @var string
*/
const CLASSNAME_TO_PATCH = 'Orchid\Presenters\UserPresenter';
/**
* Relative path to the file to be patched.
*
* @var string
*/
const FILEPATH_TO_PATH = 'vendor/orchid/platform/src/Platform/Models/User.php';
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'orchid:patch {--ignore-error : Ignore error if can not be patched}';
/**
* The console command description.
*
* @var string
*/
protected $description = "Patch UserPresenter class not found error (#2274) (see https://github.com/orchidsoftware/platform/issues/2274)";
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$contents = Str::of(File::get(base_path(self::FILEPATH_TO_PATH)));
$search = 'use App\\' . self::CLASSNAME_TO_PATCH;
$replace = 'use ' . app()->getNamespace() . self::CLASSNAME_TO_PATCH;
if ($contents->contains($search)) {
File::put(base_path(self::FILEPATH_TO_PATH), $contents->replaceFirst($search, $replace));
$this->info('Successfully patched [Orchid Platform Issue #2274].');
return 0;
} else if ($contents->contains($replace)) {
$this->info('Already patched [Orchid Platform Issue #2274].');
return 0;
} else if ($this->option('ignore-error')) {
$this->warn('Can not find the class ' . self::CLASSNAME_TO_PATCH . '.');
return 0;
}
$this->error('Can not find the class ' . self::CLASSNAME_TO_PATCH . '.');
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment