refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
71
app/Console/Commands/Helpers/Command.php
Normal file
71
app/Console/Commands/Helpers/Command.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Helpers;
|
||||
|
||||
use Tests\Helpers\CommandCallerFake;
|
||||
|
||||
/**
|
||||
* @method static void exec(\Illuminate\Console\Command $command, string $message, string $commandline)
|
||||
* @method static void artisan(\Illuminate\Console\Command $command, string $message, string $commandline, array $arguments)
|
||||
*/
|
||||
class Command
|
||||
{
|
||||
/**
|
||||
* Switch to a fake executor for testing purpose.
|
||||
*
|
||||
* @return CommandCallerContract
|
||||
*/
|
||||
public static function fake(): CommandCallerContract
|
||||
{
|
||||
static::setBackend($fake = app(CommandCallerFake::class));
|
||||
|
||||
return $fake;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Command Executor.
|
||||
*
|
||||
* @var CommandCallerContract|null
|
||||
*/
|
||||
private static $commandCaller;
|
||||
|
||||
/**
|
||||
* Get the current backend command.
|
||||
*
|
||||
* @return CommandCallerContract
|
||||
*/
|
||||
private static function getBackend(): CommandCallerContract
|
||||
{
|
||||
if (! static::$commandCaller) {
|
||||
static::$commandCaller = app(CommandCaller::class); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
return static::$commandCaller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current backend command.
|
||||
*
|
||||
* @param CommandCallerContract $executor
|
||||
*/
|
||||
public static function setBackend(CommandCallerContract $executor): void
|
||||
{
|
||||
static::$commandCaller = $executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle dynamic, static calls to the object.
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public static function __callStatic($method, $args)
|
||||
{
|
||||
$instance = static::getBackend();
|
||||
|
||||
return $instance->$method(...$args);
|
||||
}
|
||||
}
|
||||
54
app/Console/Commands/Helpers/CommandCaller.php
Normal file
54
app/Console/Commands/Helpers/CommandCaller.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Helpers;
|
||||
|
||||
use function Safe\exec;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Console\Application;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class CommandCaller implements CommandCallerContract
|
||||
{
|
||||
/**
|
||||
* Print a message on the console, then execute a command.
|
||||
*
|
||||
* @param Command $command Laravel command context
|
||||
* @param string $message Message to output
|
||||
* @param string $commandline Command to execute
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function exec(Command $command, string $message, string $commandline): void
|
||||
{
|
||||
$command->info($message);
|
||||
$command->line($commandline, null, OutputInterface::VERBOSITY_VERBOSE);
|
||||
exec($commandline.' 2>&1', $output);
|
||||
foreach ($output as $line) {
|
||||
$command->line($line, null, OutputInterface::VERBOSITY_VERY_VERBOSE);
|
||||
}
|
||||
$command->line('', null, OutputInterface::VERBOSITY_VERBOSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a message on the console, then execute an artisan command.
|
||||
*
|
||||
* @param Command $command Laravel command context
|
||||
* @param string $message Message to output
|
||||
* @param string $commandline Artisan command name to execute
|
||||
* @param array $arguments Optional arguments to pass to the artisan command
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function artisan(Command $command, string $message, string $commandline, array $arguments = []): void
|
||||
{
|
||||
$info = '';
|
||||
foreach ($arguments as $key => $value) {
|
||||
if (is_string($key)) {
|
||||
$info .= ' '.$key.'="'.$value.'"';
|
||||
} else {
|
||||
$info .= ' '.$value;
|
||||
}
|
||||
}
|
||||
$this->exec($command, $message, Application::formatCommandString($commandline.$info));
|
||||
}
|
||||
}
|
||||
27
app/Console/Commands/Helpers/CommandCallerContract.php
Normal file
27
app/Console/Commands/Helpers/CommandCallerContract.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Helpers;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
interface CommandCallerContract
|
||||
{
|
||||
/**
|
||||
* Print a message on the console, then execute a command.
|
||||
*
|
||||
* @param Command $command Laravel command context
|
||||
* @param string $message Message to output
|
||||
* @param string $commandline Command to execute
|
||||
*/
|
||||
public function exec(Command $command, string $message, string $commandline): void;
|
||||
|
||||
/**
|
||||
* Print a message on the console, then execute an artisan command.
|
||||
*
|
||||
* @param Command $command Laravel command context
|
||||
* @param string $message Message to output
|
||||
* @param string $commandline Artisan command name to execute
|
||||
* @param array $arguments Optional arguments to pass to the artisan command
|
||||
*/
|
||||
public function artisan(Command $command, string $message, string $commandline, array $arguments = []): void;
|
||||
}
|
||||
Reference in New Issue
Block a user