- Add comprehensive health check system with multiple endpoints - Add Prometheus metrics endpoint - Add production logging configurations (5 strategies) - Add complete deployment documentation suite: * QUICKSTART.md - 30-minute deployment guide * DEPLOYMENT_CHECKLIST.md - Printable verification checklist * DEPLOYMENT_WORKFLOW.md - Complete deployment lifecycle * PRODUCTION_DEPLOYMENT.md - Comprehensive technical reference * production-logging.md - Logging configuration guide * ANSIBLE_DEPLOYMENT.md - Infrastructure as Code automation * README.md - Navigation hub * DEPLOYMENT_SUMMARY.md - Executive summary - Add deployment scripts and automation - Add DEPLOYMENT_PLAN.md - Concrete plan for immediate deployment - Update README with production-ready features All production infrastructure is now complete and ready for deployment.
102 lines
2.7 KiB
PHP
102 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Process\ValueObjects;
|
|
|
|
/**
|
|
* Repräsentiert ein Kommando zur Prozess-Ausführung.
|
|
*
|
|
* Verwendung:
|
|
* - new Command('docker', 'ps', '-a') // Variadic constructor (bypass shell)
|
|
* - Command::fromString('cat /proc/uptime') // Shell-Kommando String (uses shell)
|
|
*/
|
|
final readonly class Command
|
|
{
|
|
/** @var array<int, string> */
|
|
public array $parts;
|
|
|
|
public function __construct(string ...$values)
|
|
{
|
|
if (empty($values)) {
|
|
throw new \InvalidArgumentException('Command cannot be empty');
|
|
}
|
|
|
|
// Validate all parts are non-empty strings
|
|
foreach ($values as $value) {
|
|
if (trim($value) === '') {
|
|
throw new \InvalidArgumentException('Command parts cannot contain empty strings');
|
|
}
|
|
}
|
|
|
|
$this->parts = array_values($values);
|
|
}
|
|
|
|
/**
|
|
* Konvertiert das Kommando zu einem String mit escaped arguments.
|
|
*/
|
|
public function toString(): string
|
|
{
|
|
return implode(' ', array_map('escapeshellarg', $this->parts));
|
|
}
|
|
|
|
/**
|
|
* Gibt die rohen Kommando-Teile zurück.
|
|
*
|
|
* Für proc_open:
|
|
* - String wenn fromString (bypass_shell=false)
|
|
* - Array wenn variadic/fromArray (bypass_shell=true)
|
|
*
|
|
* @return string|array<int, string>
|
|
*/
|
|
public function getValue(): string|array
|
|
{
|
|
// If only one part (fromString), return as string for shell execution
|
|
if (count($this->parts) === 1) {
|
|
return $this->parts[0];
|
|
}
|
|
|
|
// Multiple parts, return as array for bypass_shell
|
|
return $this->parts;
|
|
}
|
|
|
|
/**
|
|
* Prüft, ob das Kommando als Array erstellt wurde (mehr als 1 Element).
|
|
*
|
|
* Ein Element = fromString (Shell verwenden)
|
|
* Mehrere Elemente = fromArray oder variadic constructor (Shell umgehen)
|
|
*/
|
|
public function isArray(): bool
|
|
{
|
|
return count($this->parts) > 1;
|
|
}
|
|
|
|
/**
|
|
* Erstellt ein Kommando aus einem Shell-String.
|
|
* Nutze dies nur für einfache Shell-Kommandos.
|
|
*/
|
|
public static function fromString(string $command): self
|
|
{
|
|
if (trim($command) === '') {
|
|
throw new \InvalidArgumentException('Command string cannot be empty');
|
|
}
|
|
|
|
// Store as single part - will be executed as shell command
|
|
return new self($command);
|
|
}
|
|
|
|
/**
|
|
* Erstellt ein Kommando aus einem Array.
|
|
*
|
|
* @param array<int, string> $parts
|
|
*/
|
|
public static function fromArray(array $parts): self
|
|
{
|
|
if (empty($parts)) {
|
|
throw new \InvalidArgumentException('Command array cannot be empty');
|
|
}
|
|
|
|
return new self(...$parts);
|
|
}
|
|
}
|