. */ namespace SP\Http; use Klein\Response; /** * Class Xml * * @package SP\Http */ final class Xml { public const SAFE = [ 'from' => ['&', '<', '>', '"', "\'"], 'to' => ['&', '<', '>', '"', '''] ]; private Response $response; /** * Xml constructor. */ public function __construct(Response $response) { $this->response = $response; } /** * Devuelve una respuesta en formato XML con el estado y el mensaje. * * @param string $description mensaje a devolver * @param int $status devuelve el estado */ public function printXml(string $description, int $status = 1): void { $xml[] = ''; $xml[] = ''; $xml[] = '' . $status . ''; $xml[] = '' . $this->safeString($description) . ''; $xml[] = ''; $this->response ->header('Content-Type', 'application/xml') ->body(implode(PHP_EOL, $xml)) ->send(true); } /** * @return array|string|string[] */ public function safeString(string $string) { return str_replace(self::SAFE['from'], self::SAFE['to'], $string); } }